Module: Styler::Style::InstanceMethods
- Defined in:
- lib/styler/style.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #__class__ ⇒ Object
-
#as(type) ⇒ Object
Use like style.as(:widget).
-
#class ⇒ Object
I don’t like this, but it’s needed for routers that check the class if you use resource-based routers (like CRUDtree).
-
#compile_template_path ⇒ Object
This method compiles the default template path.
- #initialize(model, context = {}) ⇒ Object
-
#to_s ⇒ Object
This is the final hook, define :prepare if you need to add some stuff Set @template_path if you want a custom path.
-
#with(context) ⇒ Object
Use this method to add something to the context.
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
48 49 50 |
# File 'lib/styler/style.rb', line 48 def model @model end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
48 49 50 |
# File 'lib/styler/style.rb', line 48 def request @request end |
Instance Method Details
#__class__ ⇒ Object
74 |
# File 'lib/styler/style.rb', line 74 alias_method :__class__, :class |
#as(type) ⇒ Object
Use like style.as(:widget)
51 52 53 54 |
# File 'lib/styler/style.rb', line 51 def as(type) @type = type self end |
#class ⇒ Object
I don’t like this, but it’s needed for routers that check the class if you use resource-based routers (like CRUDtree).
77 78 79 |
# File 'lib/styler/style.rb', line 77 def class @model.class end |
#compile_template_path ⇒ Object
This method compiles the default template path.
70 71 72 |
# File 'lib/styler/style.rb', line 70 def compile_template_path "#{__class__.to_s.downcase.gsub('::','/')}/#{@type}" end |
#initialize(model, context = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/styler/style.rb', line 42 def initialize(model, context={}) serialize_from_hash(context) @model = model @type ||= :default end |
#to_s ⇒ Object
This is the final hook, define :prepare if you need to add some stuff Set @template_path if you want a custom path.
64 65 66 67 |
# File 'lib/styler/style.rb', line 64 def to_s prepare if respond_to?(:prepare) render(@template_path || compile_template_path) end |
#with(context) ⇒ Object
Use this method to add something to the context
57 58 59 60 |
# File 'lib/styler/style.rb', line 57 def with(context) serialize_from_hash(context) self end |