Sha256: e10ef47ce27d3d394bd5a06b39549a14607d5278a8fcd283f309a6fc91632e6f

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require 'rubygems'
require 'tilt'
require 'rdiscount'
require 'yaml'

class Bonfire < Thor

  desc "draft", "Makes a single HTML file of sections in the correct order"

  def draft
    Dir.chdir(Dir.pwd) do
      bonfire = YAML.load(File.open('bonfire.yml')) || {}

      directory File.join(Dir.pwd, 'source/css'), 'output/draft/css'
      directory File.join(Dir.pwd, 'source/images'), 'output/draft/images'

      book_name = bonfire['book_name']
      sections  = bonfire['sections'].collect do |section|
        section = "#{section}.md" #unless section.match(/\.md$/)
        Tilt.new("source/sections/#{section}").render
      end
      css_files = Dir.chdir(File.join(Dir.pwd, 'source')) { Dir.glob('css/**/*.css') }

      scope     = Scope.build(:title     => book_name,
                              :css_files => css_files,
                              :body      => sections.join("\n\n<hr/>\n\n"))
      template  = load_template("draft/draft.haml")

      FileUtils.mkdir_p('output/draft')
      create_file "output/draft/#{book_name}_draft.html" do
        template.render(scope)
      end
    end
  end

  no_tasks do
    def load_template(filename)
      template_path = File.join(Bonfire.source_root, 'templates', filename)
      Tilt.new(template_path)
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bonfire-0.1.1 lib/bonfire/draft.rb
bonfire-0.1.0 lib/bonfire/draft.rb