bookfile 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4311caaae87c30b6ac285adb85a3495ddd177eaa
4
- data.tar.gz: 4645efcb233160f0078bcc2d8919cda290d3c981
3
+ metadata.gz: 74b333b35376fce6fd4afde31fae74dab34ba163
4
+ data.tar.gz: 61c75af3c41c19bf6e722e061512fe19082548f9
5
5
  SHA512:
6
- metadata.gz: c575efd458e00c39081e84ea811300de44736b5f79e7a44599438ceac6323f597fe10fbbdd468f06592244cdfe757eab6fb48e45b96be909d58388a02c55969c
7
- data.tar.gz: b1df8f6c2766d0db1b51363c89ee8df6708d077fa28559a6f9eef674f18a781dfec4cd806dc8669500e9c68a04a251877f6718e4790fd354a8eaef82396a9438
6
+ metadata.gz: c221e53441b7f2ea5ef14ceb20fa9b967767f37dca002616c7da188ea4fb1b08a46e6e667fcde76619e032d5103a98b3d66edbc91e8e690dc3f4e900d58ed682
7
+ data.tar.gz: f2d98a2a3927abd4f265075473b3041259a75d772b9c43536dc330c03a0fac002e0ea4a1eccfe8e653ddfc24bffdf2171c91d25f855e79c09c05c087edebf3e4
@@ -16,21 +16,30 @@ class PageCtx ## page context for evaluate
16
16
 
17
17
  include HybookHelper
18
18
 
19
+ attr_reader :content
20
+
19
21
  def initialize( config ) ## BookConfig
20
- ## pass in templates_dir here
21
- ## ## TEMPLATES_DIR = ?? -- passed in as config
22
- ## or pass in class to help find templates???
23
- ## TemplateMan( ??? )
24
- @config = config
22
+ @config = config
23
+ @content = '' ## rename to body,text,buf,out - why, why not???
24
+
25
+ ## track rendering (stack) level - only output if in top-level (1)
26
+ ## -- check/todo - is there a better way???
27
+ ## use a (separate) partial method or keep using on render method etc. ???
28
+ ## any other ways??
29
+ @level = 0
25
30
  end
26
31
 
32
+
27
33
  def write( text )
28
34
  puts "*** write:"
29
- puts " #{text}"
35
+ ## puts " #{text}"
36
+
37
+ @content << text
30
38
  end
31
39
 
32
40
  def render( name, opts={}, locals={} ) ## possible? - make opts required ??
33
- puts "*** render #{name}:"
41
+ @level +=1
42
+ puts "*** render(#{@level}) #{name}:"
34
43
 
35
44
  tmpl = File.read_utf8( "#{@config.templates_dir}/#{name}.md" ) ## name e.g. includes/_city
36
45
 
@@ -42,7 +51,15 @@ class PageCtx ## page context for evaluate
42
51
 
43
52
  text = TextUtils::PageTemplate.new( tmpl ).render( binding )
44
53
 
45
- puts " #{text}"
54
+ ## note: only add text to content if top-level render call
55
+ ## (do NOT add for partials/includes/etc.)
56
+ if @level == 1
57
+ @content << text
58
+ end
59
+
60
+ @level -=1
61
+
62
+ ## puts " #{text}"
46
63
  text
47
64
  end
48
65
 
@@ -68,17 +85,25 @@ end # class PageCtx
68
85
 
69
86
  class BookCtx
70
87
 
71
- def initialize( config )
72
- @config = config
88
+ def initialize( config, book_opts={} )
89
+ @config = config
90
+ ## todo: add opts to config ???
91
+ ## e.g. title, layout, inline ??? - why? why not??
92
+ @builder = BookBuilder.new( config.pages_dir, book_opts )
73
93
  end
74
94
 
75
- def page( name, opts={} ) ## &block
76
- puts "[BookCtx#page] #{name} opts:#{opts.inspect}"
77
-
95
+ ## change name to path - why, why not??
96
+ def page( name, page_opts={} ) ## &block
97
+ puts "[BookCtx#page] #{name} opts:#{page_opts.inspect}"
98
+
78
99
  puts "[BookCtx#page] before yield"
79
- ctx = PageCtx.new( @config ) ## pass along book configs
100
+ ctx = PageCtx.new( @config ) ## pass along self (bookctx) as parent
80
101
  yield( ctx ) ## same as - ctx.instance_eval( &block )
81
102
  puts "[BookCtx#page] after yield"
103
+
104
+ @builder.page( name, page_opts ) do |page|
105
+ page.write ctx.content
106
+ end
82
107
  end
83
108
 
84
109
  end # class BootCtx
@@ -92,9 +117,19 @@ class BookDef
92
117
  end
93
118
 
94
119
  def build( unzip_dir )
95
- config = BookConfig.new( templates_dir: "#{unzip_dir}/_templates" )
96
- ctx = BookCtx.new( config )
97
- @proc.call( ctx ) ## same as - ctx.instance_eval( &@codeblock ) -- use instance_eval - why, why not??
120
+ defaults = { templates_dir: "#{unzip_dir}/_templates",
121
+ pages_dir: "#{unzip_dir}/_pages" }
122
+
123
+ ## note:
124
+ ## (auto)build two versions:
125
+ ## 1) multi-page version - for (easy) browsing
126
+ ## 2) all-in-one-page version - for (easy)pdf conversion
127
+
128
+ multi_page_ctx = BookCtx.new( BookConfig.new( defaults ))
129
+ @proc.call( multi_page_ctx ) ## same as - ctx.instance_eval( &@codeblock ) -- use instance_eval - why, why not??
130
+
131
+ one_page_ctx = BookCtx.new( BookConfig.new( defaults ), inline: true )
132
+ @proc.call( one_page_ctx ) ## same as - ctx.instance_eval( &@codeblock ) -- use instance_eval - why, why not??
98
133
  end
99
134
  end # class BookDef
100
135
 
@@ -11,7 +11,12 @@ class BookConfig
11
11
  def templates_dir
12
12
  @hash[:templates_dir]
13
13
  end
14
+
15
+ def pages_dir
16
+ @hash[:pages_dir]
17
+ end
14
18
  end
15
19
 
16
20
 
17
21
  end # module Bookfile
22
+
@@ -19,21 +19,14 @@ end
19
19
  def columns_begin( opts={} )
20
20
  # note: will add columns2 or columns3 etc. depending on columns option passed in
21
21
 
22
- columns = opts[:columns] || 2
22
+ ## note: default was 2 (columns) for world.db, 300 (px) for beer.db
23
+ columns = opts[:columns] || 300
23
24
 
24
- buf = ''
25
- buf << "\n"
26
- buf << "<div class='columns#{columns}' markdown='1'>\n"
27
- buf << "\n"
28
- buf
25
+ "\n<div class='columns#{columns}' markdown='1'>\n\n"
29
26
  end
30
27
 
31
28
  def columns_end
32
- buf = ''
33
- buf << "\n"
34
- buf << "</div>\n"
35
- buf << "\n"
36
- buf
29
+ "\n</div>\n\n"
37
30
  end
38
31
 
39
32
  ### todo: check if we can use columns simply w/ yield for body ??
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Bookfile
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
 
7
7
  ## add module alias
@@ -9,13 +9,16 @@ beer adapter: 'sqlite3', database: './beer.db'
9
9
 
10
10
  book do |b|
11
11
 
12
- ### generate what's news in 2014
12
+ ## todo/fix:
13
+ ## find a way to pass along opts - why, why not??
14
+ opts = {}
13
15
 
14
- years = [2014,2013,2012,2011,2010]
16
+ ### generate what's news in 2015
17
+ years = [2015,2014,2013,2012,2011,2010]
15
18
  years.each do |year|
16
19
  b.page( "#{year}", title: "What's News in #{year}?",
17
20
  id: "#{year}" ) do |page|
18
- page.write render_whats_news_in_year( year, opts )
21
+ page.render_whats_news_in_year( year, opts )
19
22
  end
20
23
  end
21
24
 
@@ -24,21 +27,21 @@ book do |b|
24
27
 
25
28
  b.page( 'breweries', title: 'Breweries Index',
26
29
  id: 'breweries' ) do |page|
27
- page.write render_breweries_idx( opts )
30
+ page.render_breweries_idx( opts )
28
31
  end
29
32
 
30
33
  ### generate beers index
31
34
 
32
35
  b.page( 'beers', title: 'Beers Index',
33
36
  id: 'beers' ) do |page|
34
- page.write render_beers_idx( opts )
37
+ page.render_beers_idx( opts )
35
38
  end
36
39
 
37
40
  ### generate brands index
38
41
 
39
42
  b.page( 'brands', title: 'Brands Index',
40
43
  id: 'brands' ) do |page|
41
- page.write render_brands_idx( opts )
44
+ page.render_brands_idx( opts )
42
45
  end
43
46
 
44
47
 
@@ -46,7 +49,7 @@ book do |b|
46
49
 
47
50
  b.page( 'index', title: 'Contents',
48
51
  id: 'index' ) do |page|
49
- page.write render_toc( opts )
52
+ page.render_toc( opts )
50
53
  end
51
54
 
52
55
 
@@ -66,7 +69,7 @@ book do |b|
66
69
  puts "path=#{path}"
67
70
  b.page( path, title: "#{country.title} (#{country.code})",
68
71
  id: "#{country.key}" ) do |page|
69
- page.write render_country( country, opts )
72
+ page.render_country( country, opts )
70
73
  end
71
74
 
72
75
  ## todo - add b.divider() - for inline version - why, why not ????
@@ -30,11 +30,20 @@ end
30
30
  =end
31
31
 
32
32
 
33
+ #################
34
+ # self.class.name (in top level): Bookfile::Builder
35
+ # self.class.name (in book block): Bookfile::Builder
36
+ # self.class.name (in page block): Bookfile::Builder
37
+
33
38
  puts "self.class.name (in top level): #{self.class.name}"
34
39
 
35
40
 
36
41
  book do |b|
37
-
42
+
43
+ ## todo/fix:
44
+ ## find a way to pass along opts - why, why not??
45
+ opts = {}
46
+
38
47
  puts "before first page"
39
48
  puts "self.class.name (in book block): #{self.class.name}"
40
49
 
@@ -45,7 +54,7 @@ book do |b|
45
54
  page.write "render_toc() 2x"
46
55
  page.write "render_toc() 3x"
47
56
 
48
- page.render_toc( {} )
57
+ page.render_toc( opts )
49
58
  ## render :toc -- auto includes opts???
50
59
 
51
60
  puts "self.class.name (in page block): #{self.class.name}"
@@ -69,7 +78,7 @@ book do |b|
69
78
  b.page path, title: "#{country.name} (#{country.code})",
70
79
  id: country.key do |page|
71
80
  page.write "render_country(#{country.name})" ## render_country( country ) ## render_country( country, opts )
72
- page.render_country( country, {} ) ### fix: auto-include opts in render - how??
81
+ page.render_country( country, opts ) ### fix: auto-include opts in render - how??
73
82
  end
74
83
  end
75
84
  end
data/test/test_world.rb CHANGED
@@ -14,8 +14,8 @@ class TestWorld < MiniTest::Test
14
14
 
15
15
  bookfile = Bookfile::Bookfile.load_file( './test/bookfile/world.rb' )
16
16
 
17
- # bookfile.download # download book packages (templates n scripts)
18
- bookfile.unzip( book_templates_unzip_dir )
17
+ ## bookfile.download # download book packages (templates n scripts)
18
+ ## bookfile.unzip( book_templates_unzip_dir )
19
19
 
20
20
  bookfile.prepare( book_templates_unzip_dir )
21
21
  bookfile.connect
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props