Class: BookBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/hybook/builder/book.rb

Overview

fix: remove jekyll specific stuff

-- move to jekyll writer

Instance Method Summary collapse

Constructor Details

#initialize(user_pages_dir, opts = {}) ⇒ BookBuilder

Returns a new instance of BookBuilder.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hybook/builder/book.rb', line 27

def initialize( user_pages_dir, opts={} )
  
  #
  #
  #  fix: move user_pages_dir to opts ?? or remove
  #    only use for writer/renderer later
  
  @pages_dir = user_pages_dir   # add user_ to avoid conflict w/ attrib

  @inline    = opts[:inline ] == true ? true : false   # all-in-one page version or multi-page?

  @title     = opts[:title]  || 'Book Title Here'
  @layout    = opts[:layout] || 'book'


  ## if @inline create all-in-one book(.html) page
  if inline?
    path = "#{pages_dir}/book.md"      
    puts "[book] create all-in-one book page (#{path})"

    ## add frontmatter

    page_opts = { frontmatter: {
                     layout: layout,
                     title:  title,
                     permalink: '/book.html' } }

    TextUtils::Page.create( path, page_opts ) do |page|
      ## do nothing for now
    end
  end
end

Instance Method Details

#inline?Boolean

Returns:

  • (Boolean)


21
# File 'lib/hybook/builder/book.rb', line 21

def inline?()   @inline;    end

#layoutObject



23
# File 'lib/hybook/builder/book.rb', line 23

def layout()    @layout;    end

#page(name, opts = {}) ⇒ Object

fix: change to part/chapter/section/etc. ??



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/hybook/builder/book.rb', line 63

def page( name, opts={} )

  # add fallbacks/defaults
  opts[:title] ||= 'Page Title Here'
  opts[:id]    ||= TextUtils.slugify( @title )   ## add page/section counter to generated fallback id/anchor

  if inline?
    path = "#{pages_dir}/book.md"
    puts "[book] update all-in-one book page -- #{name} (#{path})"

    page_opts = {}.merge( opts )  ## for now pass along all opts; no built-in/auto-added opts -- in the future add page/section counter or similar, for example?
    TextUtils::Page.update( path, page_opts ) do |page|
      yield( page )
    end
  else
    path = "#{pages_dir}/#{name}.md"
    puts "[book] create page #{name} (#{path})"

    page_opts = { frontmatter: {
                     layout:    layout,                 # e.g. 'book'
                     title:     opts[:title],            # e.g. 'The Free Beer Book'
                     permalink: "/#{opts[:id]}.html"      # e.g. '/index.html'
                }}
    page_opts = page_opts.merge( opts )   ## pass along all opts

    TextUtils::Page.create( path, page_opts ) do |page|
      yield( page )
    end
  end
end

#pages_dirObject



24
# File 'lib/hybook/builder/book.rb', line 24

def pages_dir() @pages_dir; end

#titleObject



22
# File 'lib/hybook/builder/book.rb', line 22

def title()     @title;     end