Module: Styler::Style::InstanceMethods

Defined in:
lib/styler/style.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



48
49
50
# File 'lib/styler/style.rb', line 48

def model
  @model
end

#requestObject (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

#classObject

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_pathObject

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_sObject

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