Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
The gem aims for Myanmar language users who suffered in a never Ending war between Zawgyi and Unicode fonts for Myanmar language.
This is by no means a complete solution. It's just a convenient helper gem.
"mmunicode_rails" lets you convert you rails app input data to Myanmar Unicode regardless of which fonts the users used.
Supported for rails 4.x and 3.x
Add this line to your application's Gemfile:
gem 'mmunicode_rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mmunicode_rails
Currently mmunicode_rails supports two approach:
After bundling the gem, a rails generator for mmunicode_rails will be added to your rails app.
Run the generator:
rails generate mmunicode_rails:initializer
This will produce config/initializers/mmunicode_rails.rb
file. The file include code for inserting RackMmunicode
middleware when your rails app is initialized.
And that's it. Now every request parameters(including query string parameters) will get converted to unicode in the rack layer.
If there is an ActiveRecord model with schema like this:
ActiveRecord::Schema.define(:version => 0) do
create_table :posts do |t|
t.text :body
t.string :title
t.integer :view_count
end
end
You can specify the field you would like to convert to unicode before saving to database like this:
class Post < ActiveRecord::Base
mmunicode_convert :title,:body
end
This will register a before_save hook that converts the incoming input to unicode if it's written in zawgyi. That way you can let your users enter data in Zawgyi font while still using Unicode in your site.
The conversion is supported only for :string and :text type. Specifying any other types will raise an NotSupportedForNonStringTypesError
.
eg:
class Post < ActiveRecord::Base
mmunicode_convert :title,:body,:view_count
end
The above code will raise Error.
If you don't like both approach, you can include MmunicodeRails::Core
module for converter methods.(for zg to unicode => zg12uni51,for unicode to zg =>
uni512zg1 , detecting_font => detect_font
) All accepts an input string. converter methods produce converted output string. detect_font
returns :unicode, :zawgyi depending on fonts. If it's not Myanmar Font it will return nil
. If it's unsure of which font, it will prefer :zawgyi.
For example, if you want to register as a controller before_filter:
class PersonController < ApplicationController
include MmunicodeRails::Core
before_filter :change_name_to_unicode
private
def change_name_to_unicode
zg12uni51(person_params[:name]) if person_params[:name]
end
end
Any form of feedback or contribution is welcome. Please do post an issue if there is something you would like to add as a feature or if you find a bug. An issue/pull request can make the contributors of the project very happy. Don't be shy or afraid!
If you would like to contribute then
Fork it ( https://github.com/dreamingblackcat/mmunicode_rails/fork )
Create your feature branch (git checkout -b my-new-feature
)
Commit your changes (git commit -am 'Add some feature'
)
Push to the branch (git push origin my-new-feature
)
Create a new Pull Request
Ye Lin Aung for his awesome mmfont gem.
Thura Hlaing for his excellent paytan converter generator.
Green Like Orange for his great font detection code in knayi script.
##LICENSE
The project is under GNU LESSER GENERAL PUBLIC LICENSE. You can view the license terms here.
FAQs
Unknown package
We found that mmunicode_rails demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.