Class: Middleman::Presentation::PresentationHelper
- Inherits:
-
Object
- Object
- Middleman::Presentation::PresentationHelper
- Includes:
- Comparable
- Defined in:
- lib/middleman-presentation-core/presentation_helper.rb
Overview
Container for helper methods which can be used in presentation slides
Class Method Summary collapse
-
.parse(*modules) ⇒ Object
Parse an array.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#available_methods ⇒ Object
Return all available methods.
-
#initialize(helper_container) ⇒ PresentationHelper
constructor
A new instance of PresentationHelper.
-
#name ⇒ Object
Return name for container.
-
#to_module ⇒ Object
Return self as module.
-
#type ⇒ Object
Type of helper.
Constructor Details
#initialize(helper_container) ⇒ PresentationHelper
Returns a new instance of PresentationHelper.
14 15 16 17 18 |
# File 'lib/middleman-presentation-core/presentation_helper.rb', line 14 def initialize(helper_container) fail TypeError, Middleman::Presentation.t('errors.invalid_helper_module') if !helper_container.is_a?(Module) && !helper_container.is_a?(Proc) @helper_container = helper_container end |
Class Method Details
.parse(*modules) ⇒ Object
Parse an array
59 60 61 |
# File 'lib/middleman-presentation-core/presentation_helper.rb', line 59 def self.parse(*modules) modules.flatten.map { |m| new(m) } end |
Instance Method Details
#<=>(other) ⇒ Object
64 65 66 |
# File 'lib/middleman-presentation-core/presentation_helper.rb', line 64 def <=>(other) name <=> other.name end |
#available_methods ⇒ Object
Return all available methods
51 52 53 54 55 56 |
# File 'lib/middleman-presentation-core/presentation_helper.rb', line 51 def available_methods instance_methods = to_module.instance_methods - Module.methods klass_methods = (to_module.methods - Module.methods).map { |m| "self.#{m}" } instance_methods + klass_methods end |
#name ⇒ Object
Return name for container
33 34 35 36 37 38 39 |
# File 'lib/middleman-presentation-core/presentation_helper.rb', line 33 def name if helper_container.respond_to?(:name) && !helper_container.name.blank? helper_container.name else '<Anonymous>' end end |
#to_module ⇒ Object
Return self as module
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/middleman-presentation-core/presentation_helper.rb', line 21 def to_module if helper_container.is_a? Proc mod = Module.new mod.module_eval(&helper_container) mod else helper_container end end |
#type ⇒ Object
Type of helper
42 43 44 45 46 47 48 |
# File 'lib/middleman-presentation-core/presentation_helper.rb', line 42 def type if helper_container.is_a? Module :MODULE else :PROC end end |