Class: Rake::Pipeline::I18n::Filters::I18nJsFilter
- Inherits:
-
Filter
- Object
- Filter
- Rake::Pipeline::I18n::Filters::I18nJsFilter
- Includes:
- FilterWithDependencies
- Defined in:
- lib/rake-pipeline-i18n-filters/i18n_js_filter.rb
Overview
A filter that compiles locale yml files into javascript appropriate for use by Ember#String#loc
Instance Method Summary collapse
-
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API.
-
#initialize(&block) ⇒ I18nJsFilter
constructor
A new instance of I18nJsFilter.
Constructor Details
#initialize(&block) ⇒ I18nJsFilter
Returns a new instance of I18nJsFilter.
25 26 27 28 |
# File 'lib/rake-pipeline-i18n-filters/i18n_js_filter.rb', line 25 def initialize(&block) block ||= proc { |input| input.sub(/\.(yml)$/, '.js') } super(&block) end |
Instance Method Details
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API. Generates javascript from i18n yaml files appropriate for i18n-js
38 39 40 41 42 43 44 |
# File 'lib/rake-pipeline-i18n-filters/i18n_js_filter.rb', line 38 def generate_output(inputs, output) output_hash = {} inputs.each do |input| output_hash.deep_merge! YAML.load(input.read) end output.write "I18n.translations = #{output_hash.to_json};" end |