Class: Stack::Generator
- Inherits:
-
Object
- Object
- Stack::Generator
- Defined in:
- lib/stack/generator.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#layouts ⇒ Object
Returns the value of attribute layouts.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#processed_at ⇒ Object
Returns the value of attribute processed_at.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
-
#transformed_at ⇒ Object
Returns the value of attribute transformed_at.
Instance Method Summary collapse
-
#initialize(source, target, parent = nil) ⇒ Generator
constructor
A new instance of Generator.
- #process! ⇒ Object
- #read_children ⇒ Object
- #read_layouts ⇒ Object
- #read_pages ⇒ Object
- #to_hash ⇒ Object
- #transform! ⇒ Object
- #transform_assets ⇒ Object
Constructor Details
#initialize(source, target, parent = nil) ⇒ Generator
Returns a new instance of Generator.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stack/generator.rb', line 12 def initialize(source, target, parent = nil) self.source = source self.target = target self.parent = parent self.layouts = (parent) ? parent.layouts.dup : { } self.children = [ ] # read layouts # read pages # write pages process! end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
6 7 8 |
# File 'lib/stack/generator.rb', line 6 def children @children end |
#layouts ⇒ Object
Returns the value of attribute layouts.
7 8 9 |
# File 'lib/stack/generator.rb', line 7 def layouts @layouts end |
#pages ⇒ Object
Returns the value of attribute pages.
8 9 10 |
# File 'lib/stack/generator.rb', line 8 def pages @pages end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/stack/generator.rb', line 3 def parent @parent end |
#processed_at ⇒ Object
Returns the value of attribute processed_at.
10 11 12 |
# File 'lib/stack/generator.rb', line 10 def processed_at @processed_at end |
#source ⇒ Object
Returns the value of attribute source.
4 5 6 |
# File 'lib/stack/generator.rb', line 4 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
4 5 6 |
# File 'lib/stack/generator.rb', line 4 def target @target end |
#transformed_at ⇒ Object
Returns the value of attribute transformed_at.
10 11 12 |
# File 'lib/stack/generator.rb', line 10 def transformed_at @transformed_at end |
Instance Method Details
#process! ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/stack/generator.rb', line 28 def process! self.processed_at = Time.now read_layouts read_pages read_children end |
#read_children ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/stack/generator.rb', line 47 def read_children entries = Dir.entries(self.source) directories = entries.select { |e| File.directory?(File.join(self.source, e)) } directories = directories.reject { |d| d[0..0]=~/\.|_/ or d[-1..-1]=="~" } directories.each do |dir| self.children.push(Stack::Generator.new(File.join(self.source, dir), File.join(self.target, dir), self)) end end |
#read_layouts ⇒ Object
37 38 39 40 41 |
# File 'lib/stack/generator.rb', line 37 def read_layouts if File.exists?(File.join(self.source, "_layouts")) @layouts = @layouts.merge(read_pages_from_directory("_layouts", Stack::Templates::Layout)) end end |
#read_pages ⇒ Object
43 44 45 |
# File 'lib/stack/generator.rb', line 43 def read_pages @pages = read_pages_from_directory(self.source, Stack::Templates::Page) end |
#to_hash ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/stack/generator.rb', line 81 def to_hash { :processed_at => self.processed_at, :transformed_at => self.transformed_at, :time => Time.now } end |
#transform! ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/stack/generator.rb', line 56 def transform! self.transformed_at = Time.now self.pages.each do |name, page| page.write! end transform_assets self.children.each { |c| c.transform! } end |
#transform_assets ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/stack/generator.rb', line 68 def transform_assets files = Dir.entries(self.source) files = files.reject { |e| File.directory?(File.join(self.source, e)) } files = files.reject { |e| e[0..0]=~/\.|_/ or e[-1..-1]=="~" } files = files.reject { |e| (%w(.yaml .yml)+Stack::EXTENSIONS).include?(File.extname(e)) } # Exception cases FileUtils.mkdir_p(self.target) files.each do |f| FileUtils.cp(File.join(self.source, File.basename(f)), File.join(self.target, File.basename(f))) end end |