bookfile 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e627081c49ba840795a25e2b2aeda693727563a
4
- data.tar.gz: 9fa61a19d841748e24db5b8ae1184f2b32254b3f
3
+ metadata.gz: 4311caaae87c30b6ac285adb85a3495ddd177eaa
4
+ data.tar.gz: 4645efcb233160f0078bcc2d8919cda290d3c981
5
5
  SHA512:
6
- metadata.gz: 7f90ddbe193fab0612db0c3e8450a8615a6e188f8165dfeeb6c22a29191187af7c67bbd8db7adb6f0bb9956f1f2633c383bf0f24dfb0597ad0aacde99243b6b6
7
- data.tar.gz: 32cab29944e3f8da39666f205c8c7918c4b0f05479a44aabcabf4be7d1a7806b262842644266f0353103f6f8a65fa6132ebe9f66b6e89127667c42145b43fb1c
6
+ metadata.gz: c575efd458e00c39081e84ea811300de44736b5f79e7a44599438ceac6323f597fe10fbbdd468f06592244cdfe757eab6fb48e45b96be909d58388a02c55969c
7
+ data.tar.gz: b1df8f6c2766d0db1b51363c89ee8df6708d077fa28559a6f9eef674f18a781dfec4cd806dc8669500e9c68a04a251877f6718e4790fd354a8eaef82396a9438
data/Manifest.txt CHANGED
@@ -12,7 +12,9 @@ lib/bookfile/helpers/markdown.rb
12
12
  lib/bookfile/helpers/misc.rb
13
13
  lib/bookfile/package/package.rb
14
14
  lib/bookfile/version.rb
15
+ test/bookfile/beer.rb
15
16
  test/bookfile/world.rb
16
17
  test/helper.rb
18
+ test/test_beer.rb
17
19
  test/test_world.rb
18
20
  test/test_world_templates.rb
data/lib/bookfile.rb CHANGED
@@ -9,6 +9,10 @@ require 'ostruct'
9
9
  ##############
10
10
  # 3rd party gems
11
11
 
12
+ require 'logutils' # uses Logging etc.
13
+ require 'textutils' # uses File.read_utf8
14
+
15
+
12
16
  require 'fetcher'
13
17
  require 'zip' # use $ gem install rubyzip
14
18
  require 'hybook' # todo/fix: check if hybook required/needed for now??
@@ -4,7 +4,25 @@ module Bookfile
4
4
 
5
5
  class Bookfile
6
6
 
7
- ## include LogUtils::Logging
7
+ include LogUtils::Logging
8
+
9
+ ## convenience method - use like Bookfile.load_file()
10
+ def self.load_file( path='./Bookfile' )
11
+ # Note: return datafile (of course, NOT the builder)
12
+ # if you want a builder use Bookfile::Builder ;-)
13
+ builder = Builder.load_file( path )
14
+ builder.bookfile
15
+ end
16
+
17
+ ## another convenience method - use like Bookfile.load()
18
+ def self.load( code )
19
+ # Note: return datafile (of course, NOT the builder)
20
+ # if you want a builder use Bookfile::Builder ;-)
21
+ builder = Builder.load( code )
22
+ builder.bookfile
23
+ end
24
+
25
+
8
26
 
9
27
  attr_reader :packages
10
28
  attr_reader :databases
@@ -5,10 +5,10 @@ module Bookfile
5
5
 
6
6
  class Builder
7
7
 
8
- ## include LogUtils::Logging
8
+ include LogUtils::Logging
9
9
 
10
10
  def self.load_file( path )
11
- code = File.read( path )
11
+ code = File.read_utf8( path )
12
12
  self.load( code )
13
13
  end
14
14
 
@@ -32,11 +32,20 @@ class Builder
32
32
  @bookfile.packages << BookPackage.new( name, opts )
33
33
  end
34
34
 
35
+ ## database options
35
36
  def world( opts={} )
36
37
  puts "world opts: #{opts.inspect}"
37
- @bookfile.databases << World.new( opts )
38
+ @bookfile.databases << WorldDef.new( opts )
38
39
  end
39
40
 
41
+ def beer( opts={} )
42
+ puts "beer opts: #{opts.inspect}"
43
+ ## todo: to avoid name class use BeerDef, WorldDef ?? etc.
44
+ @bookfile.databases << BeerDef.new( opts )
45
+ end
46
+
47
+
48
+
40
49
  def book( opts={}, &block )
41
50
  puts "book opts: #{opts.inspect}"
42
51
  @bookfile.books << BookDef.new( opts, block )
@@ -7,10 +7,22 @@ class Database
7
7
  def initialize( db_config )
8
8
  @db_config = db_config
9
9
  end
10
+
11
+ def connect
12
+ print " connecting..."
13
+ ActiveRecord::Base.establish_connection( @db_config )
14
+ puts "OK"
15
+ end
16
+
17
+ def setup ## use connect/prepare - why, why not??
18
+ prepare # step 1: prepare - require and include models
19
+ connect # step 2: connect
20
+ end
10
21
  end
11
22
 
12
23
 
13
- class World < Database ## change to WorldDatabase or DatabaseWorld - why, why not???
24
+
25
+ class WorldDef < Database ## change to WorldDatabase or DatabaseWorld - why, why not???
14
26
  def initialize( db_config ) ## check - if it works by default (no initialze specfied)
15
27
  super
16
28
  end
@@ -19,35 +31,59 @@ class World < Database ## change to WorldDatabase or DatabaseWorld - why, why
19
31
  puts "setup world: #{@db_config.inspect}"
20
32
 
21
33
  res = require 'worlddb/models'
22
- if res
23
- puts " include WorldDb::Models"
24
-
25
- ### check/fix: include as globals/top-level!!! how? possible???
26
- Builder.send :include, WorldDb::Models
27
- PageCtx.send :include, WorldDb::Models
28
- HybookHelper.send :include, WorldDb::Models ## constants not accesible (include in module too)
29
- ## BookCtx.send :include, WorldDb::Models -- needed for Book context too?? why, why not??
30
34
 
31
35
  ## also add to xxxx ???
32
36
  ## (possible to include as globals ???? how - Object.send :include ???) or
33
37
  ## Module.send :include ??
34
- else
35
38
  ## find a better check - check for constants defined??? if not define???
36
39
  ## or use constant_missing handler???
37
- puts " assume WorldDb::Models already included ??"
40
+
41
+ if res == false
42
+ puts " todo/fix: WorldDb::Models already included ??"
38
43
  end
39
- end
44
+
45
+ puts "include WorldDb::Models"
40
46
 
41
- def connect
42
- print " connecting..."
43
- ActiveRecord::Base.establish_connection( @db_config )
44
- puts "OK"
45
- end
47
+ ### check/fix: include as globals/top-level!!! how? possible???
48
+ Builder.send :include, WorldDb::Models
49
+ PageCtx.send :include, WorldDb::Models
50
+ HybookHelper.send :include, WorldDb::Models ## constants not accesible (include in module too)
51
+ ## BookCtx.send :include, WorldDb::Models -- needed for Book context too?? why, why not??
52
+ end # method prepare
53
+ end # class WorldDef
46
54
 
47
- def setup ## use connect/prepare - why, why not??
48
- prepare # step 1: prepare - require and include models
49
- connect # step 2: connect
55
+
56
+ class BeerDef < Database ## change to BeerDatabase or DatabaseBeer - why, why not???
57
+ def initialize( db_config ) ## check - if it works by default (no initialze specfied)
58
+ super
50
59
  end
51
- end # class World
60
+
61
+ def prepare ## change to require - why, why not??
62
+ puts "setup beer: #{@db_config.inspect}"
63
+
64
+ res = require 'beerdb/models'
65
+
66
+ ## also add to xxxx ???
67
+ ## (possible to include as globals ???? how - Object.send :include ???) or
68
+ ## Module.send :include ??
69
+
70
+ if res == false
71
+ ## find a better check - check for constants defined??? if not define???
72
+ ## or use constant_missing handler???
73
+ puts " todo/fix: BeerDb::Models already included ??"
74
+ end
75
+
76
+ ## for now always include
77
+ puts " include BeerDb::Models"
78
+
79
+ ### check/fix: include as globals/top-level!!! how? possible???
80
+ Builder.send :include, BeerDb::Models
81
+ PageCtx.send :include, BeerDb::Models
82
+ HybookHelper.send :include, BeerDb::Models ## constants not accesible (include in module too)
83
+
84
+
85
+ end # method prepare
86
+ end # class BeerDef
87
+
52
88
 
53
89
  end # module Bookfile
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Bookfile
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
6
6
 
7
7
  ## add module alias
@@ -0,0 +1,120 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ package 'book-templates/beer'
5
+
6
+
7
+ beer adapter: 'sqlite3', database: './beer.db'
8
+
9
+
10
+ book do |b|
11
+
12
+ ### generate what's news in 2014
13
+
14
+ years = [2014,2013,2012,2011,2010]
15
+ years.each do |year|
16
+ b.page( "#{year}", title: "What's News in #{year}?",
17
+ id: "#{year}" ) do |page|
18
+ page.write render_whats_news_in_year( year, opts )
19
+ end
20
+ end
21
+
22
+
23
+ ### generate breweries index
24
+
25
+ b.page( 'breweries', title: 'Breweries Index',
26
+ id: 'breweries' ) do |page|
27
+ page.write render_breweries_idx( opts )
28
+ end
29
+
30
+ ### generate beers index
31
+
32
+ b.page( 'beers', title: 'Beers Index',
33
+ id: 'beers' ) do |page|
34
+ page.write render_beers_idx( opts )
35
+ end
36
+
37
+ ### generate brands index
38
+
39
+ b.page( 'brands', title: 'Brands Index',
40
+ id: 'brands' ) do |page|
41
+ page.write render_brands_idx( opts )
42
+ end
43
+
44
+
45
+ ### generate table of contents (toc)
46
+
47
+ b.page( 'index', title: 'Contents',
48
+ id: 'index' ) do |page|
49
+ page.write render_toc( opts )
50
+ end
51
+
52
+
53
+ ### generate pages for countries
54
+
55
+ country_count=0
56
+ # Country.where( "key in ('at','mx','hr', 'de', 'be', 'nl', 'cz')" ).each do |country|
57
+ Country.order(:id).each do |country|
58
+ beers_count = country.beers.count
59
+ breweries_count = country.breweries.count
60
+ next if beers_count == 0 && breweries_count == 0
61
+
62
+ country_count += 1
63
+ puts "build country page #{country.key}..."
64
+
65
+ path = country.to_path
66
+ puts "path=#{path}"
67
+ b.page( path, title: "#{country.title} (#{country.code})",
68
+ id: "#{country.key}" ) do |page|
69
+ page.write render_country( country, opts )
70
+ end
71
+
72
+ ## todo - add b.divider() - for inline version - why, why not ????
73
+
74
+ ## break if country_count == 3 # note: for testing only build three country pages
75
+ end
76
+ end
77
+
78
+
79
+ =begin
80
+ ###
81
+ ## todo: move to its own bookfile
82
+ ## - how to pass in country parameter ???
83
+
84
+ def build_book_for_country( country_code, opts={} )
85
+
86
+ country = Country.find_by_key!( country_code )
87
+
88
+ b = BookBuilder.new( PAGES_DIR, opts )
89
+
90
+ ### generate breweries index
91
+
92
+ b.page( "#{country.key}-breweries", title: 'Breweries Index',
93
+ id: "/#{country.key}-breweries" ) do |page|
94
+ page.write render_breweries_idx( opts )
95
+ end
96
+
97
+ ### generate pages for countries
98
+
99
+ puts "build country page #{country.key}..."
100
+
101
+ path = country.to_path
102
+ puts "path=#{path}"
103
+ b.page( path, title: "#{country.title} (#{country.code})",
104
+ id: "#{country.key}" ) do |page|
105
+ page.write render_country( country, opts )
106
+ end
107
+
108
+ b.page( "#{country.key}-mini", title: "#{country.title} (#{country.code}) - Mini",
109
+ id: "#{country.key}-mini" ) do |page|
110
+ page.write render_country_mini( country, opts )
111
+ end
112
+
113
+ b.page( "#{country.key}-stats", title: "#{country.title} (#{country.code}) - Stats",
114
+ id: "#{country.key}-stats.html" ) do |page|
115
+ page.write render_country_stats( country, opts )
116
+ end
117
+
118
+ end
119
+ =end
120
+
@@ -39,17 +39,17 @@ book do |b|
39
39
  puts "self.class.name (in book block): #{self.class.name}"
40
40
 
41
41
  b.page 'index', title: 'Contents',
42
- id: 'index' do |p|
42
+ id: 'index' do |page|
43
43
  puts "enter index"
44
- p.write "render_toc()" ## render_toc() ## render_toc( opts )
45
- p.write "render_toc() 2x"
46
- p.write "render_toc() 3x"
47
-
48
- p.render_toc( {} )
44
+ page.write "render_toc()" ## render_toc() ## render_toc( opts )
45
+ page.write "render_toc() 2x"
46
+ page.write "render_toc() 3x"
47
+
48
+ page.render_toc( {} )
49
49
  ## render :toc -- auto includes opts???
50
50
 
51
51
  puts "self.class.name (in page block): #{self.class.name}"
52
- p.write "continent.count: #{Continent.count}"
52
+ page.write "continent.count: #{Continent.count}"
53
53
  puts "leave index"
54
54
 
55
55
  puts "continent.count: #{Continent.count}"
@@ -67,9 +67,9 @@ book do |b|
67
67
  puts "path=#{path}"
68
68
 
69
69
  b.page path, title: "#{country.name} (#{country.code})",
70
- id: country.key do |p|
71
- p.write "render_country(#{country.name})" ## render_country( country ) ## render_country( country, opts )
72
- p.render_country( country, {} ) ### fix: auto-include opts in render - how??
70
+ id: country.key do |page|
71
+ 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??
73
73
  end
74
74
  end
75
75
  end
data/test/test_beer.rb ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_beer.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestBeer < MiniTest::Test
11
+
12
+ def test_beer
13
+ book_templates_unzip_dir = './tmp/book-beer'
14
+
15
+ bookfile = Bookfile::Bookfile.load_file( './test/bookfile/beer.rb' )
16
+
17
+ bookfile.download # download book packages (templates n scripts)
18
+ bookfile.unzip( book_templates_unzip_dir )
19
+
20
+ bookfile.prepare( book_templates_unzip_dir )
21
+ bookfile.connect
22
+
23
+ bookfile.build( book_templates_unzip_dir )
24
+
25
+ assert true # if we get here - test success
26
+ end
27
+
28
+ end # class TestWorld
29
+
data/test/test_world.rb CHANGED
@@ -10,13 +10,12 @@ require 'helper'
10
10
  class TestWorld < MiniTest::Test
11
11
 
12
12
  def test_world
13
- book_templates_unzip_dir = './tmp/book'
13
+ book_templates_unzip_dir = './tmp/book-world'
14
14
 
15
- builder = Bookfile::Builder.load_file( './test/bookfile/world.rb' )
16
- bookfile = builder.bookfile
15
+ bookfile = Bookfile::Bookfile.load_file( './test/bookfile/world.rb' )
17
16
 
18
17
  # bookfile.download # download book packages (templates n scripts)
19
- # bookfile.unzip( book_templates_unzip_dir )
18
+ bookfile.unzip( book_templates_unzip_dir )
20
19
 
21
20
  bookfile.prepare( book_templates_unzip_dir )
22
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.0
4
+ version: 0.1.1
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-15 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props
@@ -146,8 +146,10 @@ files:
146
146
  - lib/bookfile/helpers/misc.rb
147
147
  - lib/bookfile/package/package.rb
148
148
  - lib/bookfile/version.rb
149
+ - test/bookfile/beer.rb
149
150
  - test/bookfile/world.rb
150
151
  - test/helper.rb
152
+ - test/test_beer.rb
151
153
  - test/test_world.rb
152
154
  - test/test_world_templates.rb
153
155
  homepage: https://github.com/hybook/bookfile
@@ -177,5 +179,6 @@ signing_key:
177
179
  specification_version: 4
178
180
  summary: bookfile - builder for books
179
181
  test_files:
182
+ - test/test_beer.rb
180
183
  - test/test_world.rb
181
184
  - test/test_world_templates.rb