Class: Bonfire

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bonfire.rb,
lib/bonfire/new.rb,
lib/bonfire/draft.rb,
lib/bonfire/version.rb

Constant Summary collapse

VERSION =
"0.1.1"
@@source_root =
File.join(File.dirname(__FILE__), '..')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#book_nameObject (readonly)

Returns the value of attribute book_name.



3
4
5
# File 'lib/bonfire/new.rb', line 3

def book_name
  @book_name
end

Class Method Details

.source_rootObject



8
9
10
# File 'lib/bonfire.rb', line 8

def self.source_root
  @@source_root
end

.template_dirObject



12
13
14
# File 'lib/bonfire.rb', line 12

def self.template_dir
  @@template_dir
end

Instance Method Details

#draftObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bonfire/draft.rb', line 10

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

#new(name = "bonfire_book") ⇒ Object



6
7
8
9
# File 'lib/bonfire/new.rb', line 6

def new(name = "bonfire_book")
  @book_name = name
  directory "templates/new", name
end