Class: Handlebarsjs::BaseHelper
- Inherits:
-
Object
- Object
- Handlebarsjs::BaseHelper
- Defined in:
- lib/handlebarsjs/base_helper.rb
Overview
Extend base helper for each of your custom handlebars-helpers
Direct Known Subclasses
Helpers::Array::Join, Helpers::Array::JoinPost, Helpers::Array::JoinPre, Helpers::Case::BackSlash, Helpers::Case::Camel, Helpers::Case::Constant, Helpers::Case::Dash, Helpers::Case::Dot, Helpers::Case::DoubleColon, Helpers::Case::Human, Helpers::Case::Lamel, Helpers::Case::Lower, Helpers::Case::Slash, Helpers::Case::Snake, Helpers::Case::Title, Helpers::Case::Upper, Helpers::Comparison::And, Helpers::Comparison::Default, Helpers::Comparison::Eq, Helpers::Comparison::Gt, Helpers::Comparison::Gte, Helpers::Comparison::Lt, Helpers::Comparison::Lte, Helpers::Comparison::Ne, Helpers::Comparison::Or, Helpers::Inflection::Ordinal, Helpers::Inflection::Ordinalize, Helpers::Inflection::Pluralize, Helpers::Inflection::PluralizeNumber, Helpers::Inflection::PluralizeNumberWord, Helpers::Inflection::Singularize, Helpers::Misc::FormatJson, Helpers::Misc::Safe, Helpers::Str::Padl, Helpers::Str::Padr
Class Attribute Summary collapse
-
.block ⇒ Object
readonly
Returns the value of attribute block.
-
.cmdlet ⇒ Object
readonly
Returns the value of attribute cmdlet.
-
.parameter_names ⇒ Object
readonly
Returns the value of attribute parameter_names.
-
.safe ⇒ Object
readonly
Returns the value of attribute safe.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#cmdlet ⇒ Object
readonly
Returns the value of attribute cmdlet.
-
#parameter_names ⇒ Object
readonly
Returns the value of attribute parameter_names.
-
#safe ⇒ Object
readonly
Returns the value of attribute safe.
Class Method Summary collapse
-
.register_cmdlet(cmdlet, block: false, safe: false, parameter_names: []) ⇒ Object
Register the cmdlet to be used by the helper.
Instance Method Summary collapse
-
#initialize(cmdlet = nil, safe: nil, parameter_names: nil) ⇒ BaseHelper
constructor
Preferred way to register the internal command is via register_cmdlet but you can also register the command directly in the initializer and that can be handy if you use a custom configured cmdlet.
-
#to_proc ⇒ Object
Wrap the cmdlet call method in a handlebars context aware block and return as a lambda/proc so that it is available to the Handlebars template engine.
-
#wrapper(value) ⇒ Object
If you need to wrap the return value then you can override this method.
Constructor Details
#initialize(cmdlet = nil, safe: nil, parameter_names: nil) ⇒ BaseHelper
Preferred way to register the internal command is via register_cmdlet but you can also register the command directly in the initializer and that can be handy if you use a custom configured cmdlet
14 15 16 17 18 19 |
# File 'lib/handlebarsjs/base_helper.rb', line 14 def initialize(cmdlet = nil, safe: nil, parameter_names: nil) initialize_cmdlet(cmdlet) initialize_safe(safe) initialize_block(block) initialize_parameter_names(parameter_names) end |
Class Attribute Details
.block ⇒ Object (readonly)
Returns the value of attribute block.
23 24 25 |
# File 'lib/handlebarsjs/base_helper.rb', line 23 def block @block end |
.cmdlet ⇒ Object (readonly)
Returns the value of attribute cmdlet.
22 23 24 |
# File 'lib/handlebarsjs/base_helper.rb', line 22 def cmdlet @cmdlet end |
.parameter_names ⇒ Object (readonly)
Returns the value of attribute parameter_names.
25 26 27 |
# File 'lib/handlebarsjs/base_helper.rb', line 25 def parameter_names @parameter_names end |
.safe ⇒ Object (readonly)
Returns the value of attribute safe.
24 25 26 |
# File 'lib/handlebarsjs/base_helper.rb', line 24 def safe @safe end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
7 8 9 |
# File 'lib/handlebarsjs/base_helper.rb', line 7 def block @block end |
#cmdlet ⇒ Object (readonly)
Returns the value of attribute cmdlet.
6 7 8 |
# File 'lib/handlebarsjs/base_helper.rb', line 6 def cmdlet @cmdlet end |
#parameter_names ⇒ Object (readonly)
Returns the value of attribute parameter_names.
9 10 11 |
# File 'lib/handlebarsjs/base_helper.rb', line 9 def parameter_names @parameter_names end |
#safe ⇒ Object (readonly)
Returns the value of attribute safe.
8 9 10 |
# File 'lib/handlebarsjs/base_helper.rb', line 8 def safe @safe end |
Class Method Details
.register_cmdlet(cmdlet, block: false, safe: false, parameter_names: []) ⇒ Object
Register the cmdlet to be used by the helper
By default, it will register an function expression helper You can use HTML by setting safe to true
36 37 38 39 40 41 |
# File 'lib/handlebarsjs/base_helper.rb', line 36 def register_cmdlet(cmdlet, block: false, safe: false, parameter_names: []) @cmdlet = cmdlet @block = block @safe = safe @parameter_names = parameter_names end |
Instance Method Details
#to_proc ⇒ Object
Wrap the cmdlet call method in a handlebars context aware block and return as a lambda/proc so that it is available to the Handlebars template engine
52 53 54 |
# File 'lib/handlebarsjs/base_helper.rb', line 52 def to_proc ->(value, _opts) { wrapper(cmdlet.call(value)) } end |
#wrapper(value) ⇒ Object
If you need to wrap the return value then you can override this method
45 46 47 |
# File 'lib/handlebarsjs/base_helper.rb', line 45 def wrapper(value) value end |