Class: TwitterCldr::Js::Compiler
- Inherits:
-
Object
- Object
- TwitterCldr::Js::Compiler
- Defined in:
- lib/twitter_cldr/js/compiler.rb
Instance Attribute Summary collapse
-
#locales ⇒ Object
readonly
Returns the value of attribute locales.
Instance Method Summary collapse
- #compile_bundle(bundle, bundle_elements, bundle_hash, options = {}) ⇒ Object
- #compile_each(options = {}) ⇒ Object
- #compile_implementation(options = {}) ⇒ Object
- #compile_test(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Compiler
constructor
A new instance of Compiler.
- #post_process_file(file_source, options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Compiler
Returns a new instance of Compiler.
17 18 19 20 21 22 23 24 |
# File 'lib/twitter_cldr/js/compiler.rb', line 17 def initialize( = {}) @locales = [:locales] || TwitterCldr.supported_locales @features = [:features] || implementation_renderers.keys @data = [:features] || data_renderers.keys @test_helpers = [:test_helpers] || test_helper_renderers.keys @prerender = [:prerender].nil? ? true : [:prerender] @source_map = [:source_map] end |
Instance Attribute Details
#locales ⇒ Object (readonly)
Returns the value of attribute locales.
15 16 17 |
# File 'lib/twitter_cldr/js/compiler.rb', line 15 def locales @locales end |
Instance Method Details
#compile_bundle(bundle, bundle_elements, bundle_hash, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/twitter_cldr/js/compiler.rb', line 26 def compile_bundle(bundle, bundle_elements, bundle_hash, = {}) contents = "" bundle_elements.each do |bundle_element| if renderer_const = bundle_hash[bundle_element] if bundle[:locale] contents << renderer_const.new(:locale => bundle[:locale], :prerender => @prerender).render else contents << renderer_const.new(:prerender => @prerender).render end end end bundle[:contents] = contents bundle[:source_map] = @source_map result = CoffeeScript.compile(bundle.render, { :bare => false, :sourceMap => @source_map }) file = if @source_map CompiledFile.new(result["js"], result["sourceMap"]) else CompiledFile.new(result) end file.source = post_process_file(file.source, ) file end |
#compile_each(options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/twitter_cldr/js/compiler.rb', line 68 def compile_each( = {}) @locales.each do |locale| bundle = TwitterCldr::Js::Renderers::DataBundle.new bundle[:locale] = locale bundle[:contents] = data_renderers.inject({}) do |ret, (data_renderer_name, data_renderer_class)| data_renderer = data_renderer_class.new(:locale => locale) data = data_renderer.get_data data.each_pair do |name, value| ret[name] = value end ret end.to_json file = post_process_file(CoffeeScript.compile(bundle.render), ) yield file, TwitterCldr.twitter_locale(locale) end end |
#compile_implementation(options = {}) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/twitter_cldr/js/compiler.rb', line 89 def compile_implementation( = {}) bundle = TwitterCldr::Js::Renderers::Bundle.new bundle[:locale] = TwitterCldr::DEFAULT_LOCALE file = compile_bundle(bundle, @features, implementation_renderers, ) file.source end |
#compile_test(options = {}) ⇒ Object
97 98 99 100 101 |
# File 'lib/twitter_cldr/js/compiler.rb', line 97 def compile_test( = {}) bundle = TwitterCldr::Js::Renderers::TestBundle.new file = compile_bundle(bundle, @test_helpers, test_helper_renderers, ) file.source end |
#post_process_file(file_source, options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/twitter_cldr/js/compiler.rb', line 56 def post_process_file(file_source, ) [:minify] = true unless .include?(:minify) # required alias definition that adds twitter_cldr to Twitter's static build process file_source.gsub!(/\/\*<<module_def>>\s+\*\//, %Q(/*-module-*/\n/*_lib/twitter_cldr_*/)) if [:minify] file_source = Uglifier.compile(file_source) end file_source end |