Class: Makura::Layout
- Inherits:
-
Object
- Object
- Makura::Layout
- Defined in:
- lib/makura/layout.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#design ⇒ Object
Returns the value of attribute design.
-
#map ⇒ Object
Returns the value of attribute map.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reduce ⇒ Object
Returns the value of attribute reduce.
Instance Method Summary collapse
- #common_load(root, file_or_function) ⇒ Object
-
#initialize(name, design = nil) ⇒ Layout
constructor
A new instance of Layout.
- #load_map(file_or_function) ⇒ Object
- #load_proto_map(file_or_function, replace = {}) ⇒ Object
- #load_proto_reduce(file_or_function, replace = {}) ⇒ Object
- #load_reduce(file_or_function) ⇒ Object
- #save ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, design = nil) ⇒ Layout
Returns a new instance of Layout.
10 11 12 13 14 15 |
# File 'lib/makura/layout.rb', line 10 def initialize(name, design = nil) @name, @design = name, design @design[name] = self @map = @reduce = nil @options = {} end |
Instance Attribute Details
#design ⇒ Object
Returns the value of attribute design.
3 4 5 |
# File 'lib/makura/layout.rb', line 3 def design @design end |
#map ⇒ Object
Returns the value of attribute map.
3 4 5 |
# File 'lib/makura/layout.rb', line 3 def map @map end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/makura/layout.rb', line 3 def name @name end |
#reduce ⇒ Object
Returns the value of attribute reduce.
3 4 5 |
# File 'lib/makura/layout.rb', line 3 def reduce @reduce end |
Instance Method Details
#common_load(root, file_or_function) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/makura/layout.rb', line 37 def common_load(root, file_or_function) return unless file_or_function if file_or_function =~ /function\(.*\)/ function = file_or_function else filename = "#{root}/#{file_or_function}.js" if pathname = PATH.find{|pa| File.file?(File.join(pa, filename)) } function = File.read(File.join(pathname, filename)) end end instance_variable_set("@#{root}", function) if function end |
#load_map(file_or_function) ⇒ Object
29 30 31 |
# File 'lib/makura/layout.rb', line 29 def load_map(file_or_function) common_load(:map, file_or_function) end |
#load_proto_map(file_or_function, replace = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/makura/layout.rb', line 17 def load_proto_map(file_or_function, replace = {}) return unless common_load(:proto_map, file_or_function) replace.each{|from, to| @proto_map.gsub!(/"\{\{#{from}\}\}"/, to) } @map = @proto_map end |
#load_proto_reduce(file_or_function, replace = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/makura/layout.rb', line 23 def load_proto_reduce(file_or_function, replace = {}) return unless common_load(:proto_reduce, file_or_function) replace.each{|from, to| @proto_reduce.gsub!(/"\{\{#{from}\}\}"/, to) } @reduce = @proto_reduce end |
#load_reduce(file_or_function) ⇒ Object
33 34 35 |
# File 'lib/makura/layout.rb', line 33 def load_reduce(file_or_function) common_load(:reduce, file_or_function) end |
#save ⇒ Object
53 54 55 56 |
# File 'lib/makura/layout.rb', line 53 def save @design[@name] = self.to_hash @design.save end |
#to_hash ⇒ Object
58 59 60 |
# File 'lib/makura/layout.rb', line 58 def to_hash {:map => @map, :reduce => @reduce, :makura_options => @options} end |