Class: Modular::Components::Base
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- Modular::Components::Base
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- AbstractController::Helpers, AbstractController::Rendering, ActiveModel::Conversion, ActiveModel::Validations, Rendering
- Defined in:
- lib/modular/components/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Rendering
#action_name, #execute, #render
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/modular/components/base.rb', line 70
def initialize(attributes = {})
append_view_path(Rails.root.join('app', 'views'))
append_view_path(Gem.loaded_specs['modular'].full_gem_path + '/templates')
@attributes ||= ActiveSupport::HashWithIndifferentAccess.new
@attributes[:uniqid] = ''
@attributes[:width] = 0
attributes.each do |name, value|
@attributes[name.to_s] = value
end
end
|
Instance Attribute Details
#title ⇒ Object
params for element itself
64
65
66
|
# File 'lib/modular/components/base.rb', line 64
def title
@title
end
|
#uniqid ⇒ Object
Returns the value of attribute uniqid.
65
66
67
|
# File 'lib/modular/components/base.rb', line 65
def uniqid
@uniqid
end
|
#width ⇒ Object
Returns the value of attribute width.
66
67
68
|
# File 'lib/modular/components/base.rb', line 66
def width
@width
end
|
Class Method Details
.attr_accessor(*fields) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/modular/components/base.rb', line 56
def self.attr_accessor(*fields)
fields.each do |field|
attr_writer field
attr_reader field
end
end
|
.attr_reader(*fields) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/modular/components/base.rb', line 36
def self.attr_reader(*fields)
fields.each do |field|
class_eval " def \#{field}\n @attributes['\#{field}']\n end\n"
end
end
|
.attr_writer(*fields) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/modular/components/base.rb', line 46
def self.attr_writer(*fields)
fields.each do |field|
class_eval " def \#{field}=(value)\n @attributes['\#{field}']=value\n end\n"
end
end
|
.type ⇒ Object
17
18
19
|
# File 'lib/modular/components/base.rb', line 17
def self.type
self.name.demodulize.underscore
end
|
.use_mustached_template! ⇒ Object
25
26
27
28
29
30
|
# File 'lib/modular/components/base.rb', line 25
def self.use_mustached_template!
require 'mustache'
self.class_eval do
include Modular::MstRendering
end
end
|
Instance Method Details
#all_errors ⇒ Object
96
97
98
99
|
# File 'lib/modular/components/base.rb', line 96
def all_errors
valid?
{ uniqid => errors.to_a }
end
|
#persisted? ⇒ Boolean
84
85
86
|
# File 'lib/modular/components/base.rb', line 84
def persisted?
false
end
|
#to_hash ⇒ Object
88
89
90
|
# File 'lib/modular/components/base.rb', line 88
def to_hash
@attributes.merge({:type => type})
end
|
#to_json ⇒ Object
92
93
94
|
# File 'lib/modular/components/base.rb', line 92
def to_json
ActiveSupport::JSON.encode to_hash
end
|
#type ⇒ Object
21
22
23
|
# File 'lib/modular/components/base.rb', line 21
def type
self.class.type
end
|