Class: Ember::Handlebars::Template
- Inherits:
-
Object
- Object
- Ember::Handlebars::Template
- Includes:
- Helper
- 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
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(config = self.class.config.dup) ⇒ Template
constructor
A new instance of Template.
Methods included from Helper
Constructor Details
#initialize(config = self.class.config.dup) ⇒ Template
Returns a new instance of Template.
48 49 50 |
# File 'lib/ember/handlebars/template.rb', line 48 def initialize(config = self.class.config.dup) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
46 47 48 |
# File 'lib/ember/handlebars/template.rb', line 46 def config @config end |
Class Method Details
.call(input) ⇒ Object
37 38 39 |
# File 'lib/ember/handlebars/template.rb', line 37 def call(input) instance.call(input) end |
.config ⇒ Object
18 19 20 |
# File 'lib/ember/handlebars/template.rb', line 18 def config @config ||= Config.new end |
.configure {|config| ... } ⇒ Object
14 15 16 |
# File 'lib/ember/handlebars/template.rb', line 14 def configure yield config end |
.handlebars_available? ⇒ Boolean
41 42 43 |
# File 'lib/ember/handlebars/template.rb', line 41 def Barber::Precompiler. end |
.instance ⇒ Object
33 34 35 |
# File 'lib/ember/handlebars/template.rb', line 33 def instance @instance ||= new(config) end |
.setup(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ember/handlebars/template.rb', line 22 def setup(env) env.register_mime_type 'text/x-handlebars', extensions: %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: %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: %w(.hbs .hjs .handlebars) env.register_transformer 'text/x-ember-handlebars', 'application/javascript', self end |
Instance Method Details
#call(input) ⇒ Object
52 53 54 55 56 57 58 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 |
# File 'lib/ember/handlebars/template.rb', line 52 def call(input) data = input[:data] filename = input[:filename] raw = (filename) if raw template = data else template = (filename, data) end template_name = actual_name(input) 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} 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 |