Class: Reacco::Generator
- Inherits:
-
Object
- Object
- Reacco::Generator
- Defined in:
- lib/reacco/generator.rb
Instance Method Summary collapse
-
#append_css ⇒ Object
Adds the CSS file to the style.css file.
- #copy_files(&blk) ⇒ Object
-
#html ⇒ Object
Returns the HTML contents.
-
#initialize(readme, dir, template = nil, css = nil) ⇒ Generator
constructor
A new instance of Generator.
- #template? ⇒ Boolean
-
#write! {|"#{@dir}/index.html"| ... } ⇒ Object
Writes to the output directory.
Constructor Details
Instance Method Details
#append_css ⇒ Object
Adds the CSS file to the style.css file.
32 33 34 35 |
# File 'lib/reacco/generator.rb', line 32 def append_css contents = File.read(@css) File.open("#{@dir}/style.css", 'a+') { |f| f.write "\n/* Custom */\n#{contents}" } end |
#copy_files(&blk) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/reacco/generator.rb', line 37 def copy_files(&blk) files = Dir.chdir(@template) { Dir['**/*'] } # For each of the template files... files.each do |f| next if File.basename(f)[0] == '_' next if File.fnmatch('index.*', f) ext = File.extname(f)[1..-1] fullpath = File.join @template, f # Try to render it with Tilt if possible. if Tilt.mappings.keys.include?(ext) contents = Tilt.new(fullpath).render outfile = f.match(/^(.*)(\.[^\.]+)$/) && $1 else contents = File.read(fullpath) outfile = f end yield "#{@dir}/#{outfile}" write_to "#{@dir}/#{outfile}", contents end end |
#html ⇒ Object
Returns the HTML contents.
11 12 13 14 15 16 17 |
# File 'lib/reacco/generator.rb', line 11 def html file = Dir["#{@template}/index.*"].first raise "No index file found in template path." unless file tpl = Tilt.new(file) out = tpl.render({}, @readme.locals) { @readme.html } end |
#template? ⇒ Boolean
27 28 29 |
# File 'lib/reacco/generator.rb', line 27 def template? File.directory?(@template) && Dir["#{@template}/index.*"].first end |
#write! {|"#{@dir}/index.html"| ... } ⇒ Object
Writes to the output directory.
20 21 22 23 24 25 |
# File 'lib/reacco/generator.rb', line 20 def write!(&blk) yield "#{@dir}/index.html" write_to "#{@dir}/index.html", html copy_files &blk append_css if @css end |