Class: Ember::Handlebars::Template
- Inherits:
-
Object
- Object
- Ember::Handlebars::Template
- Defined in:
- lib/ember/handlebars/template.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
- .call(input) ⇒ Object
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
- .handlebars_available? ⇒ Boolean
- .instance ⇒ Object
- .setup(env) ⇒ Object
- .setup_ember_template_compiler(path) ⇒ Object
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(config = self.class.config.dup) ⇒ Template
constructor
A new instance of Template.
Constructor Details
#initialize(config = self.class.config.dup) ⇒ Template
Returns a new instance of Template.
55 56 57 |
# File 'lib/ember/handlebars/template.rb', line 55 def initialize(config = self.class.config.dup) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
53 54 55 |
# File 'lib/ember/handlebars/template.rb', line 53 def config @config end |
Class Method Details
.call(input) ⇒ Object
38 39 40 |
# File 'lib/ember/handlebars/template.rb', line 38 def call(input) instance.call(input) end |
.config ⇒ Object
15 16 17 |
# File 'lib/ember/handlebars/template.rb', line 15 def config @config ||= Config.new end |
.configure {|config| ... } ⇒ Object
11 12 13 |
# File 'lib/ember/handlebars/template.rb', line 11 def configure yield config end |
.handlebars_available? ⇒ Boolean
42 43 44 |
# File 'lib/ember/handlebars/template.rb', line 42 def Barber::Precompiler. end |
.instance ⇒ Object
34 35 36 |
# File 'lib/ember/handlebars/template.rb', line 34 def instance @instance ||= new(config) end |
.setup(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ember/handlebars/template.rb', line 19 def setup(env) env.register_mime_type 'text/x-handlebars', extensions: with_js_extension(%w(.raw.hbs .raw.hjs .raw.handlebars)) env.register_transformer 'text/x-handlebars', 'application/javascript', self env.register_mime_type 'text/x-ember-mustache', extensions: with_js_extension(%w(.mustache.hbs .mustache.hjs .mustache.handlebars)) env.register_transformer 'text/x-ember-mustache', 'application/javascript', self env.register_mime_type 'text/x-ember-handlebars', extensions: with_js_extension(%w(.hbs .hjs .handlebars)) env.register_transformer 'text/x-ember-handlebars', 'application/javascript', self end |
.setup_ember_template_compiler(path) ⇒ Object
30 31 32 |
# File 'lib/ember/handlebars/template.rb', line 30 def setup_ember_template_compiler(path) Barber::Ember::Precompiler.ember_template_compiler_path = path end |
Instance Method Details
#call(input) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ember/handlebars/template.rb', line 59 def call(input) data = input[:data] filename = input[:filename] raw = (filename) if raw template = data else template = (filename, data) end template_name = input[:name] module_name = case config.output_type when :amd amd_template_target(config.amd_namespace, template_name) when :global template_path(template_name, config) else raise "Unsupported `output_type`: #{config.output_type}" end = ? {moduleName: module_name} : false if config.precompile if raw template = (template, input) else template = (template, config.ember_template, input, ) end else if raw template = (data) else template = (template, config.ember_template, ) end end case config.output_type when :amd "define('#{module_name}', ['exports'], function(__exports__){ __exports__['default'] = #{template} });" when :global namespace = raw ? config.raw_template_namespace : 'Ember.TEMPLATES' target = global_template_target(namespace, template_name, config) "#{target} = #{template}\n" else raise "Unsupported `output_type`: #{config.output_type}" end end |