bookman 0.0.1 → 0.1.0

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: db792b49944fae5b0ecaf4c3c1c810f43dc97df0
4
- data.tar.gz: 9d9f7477a68f3c12941fa88ccfe7dfa1af33535d
3
+ metadata.gz: 696312d864a28426c5e9920c377f7629f4d5735f
4
+ data.tar.gz: 4f673ba443afa10f43ed98e84c378d3ae3443bc6
5
5
  SHA512:
6
- metadata.gz: c7fed455ecf278b4380c6e8dded7fc86477e0a57de66b4074e0f6a7ba7308c1a6903606a4a991a5a22626d3e876151f234d4592cc5cb5a4b1d8179b82c0ddeac
7
- data.tar.gz: c886fe2c7cbf24985e53ac49444df546d72b61b4a663c1c6bcb2ff7f2779ea71f618229adbc3427a7fcc84cfd6da0540aee1a3caa6af37541dcc0c175b8bfd57
6
+ metadata.gz: 26644a52e34f235d2fba10517871fbb13dd198ac9334014f5d4f6d486d0949b1cb77b7f4d6b7c357b0cfe947b2df609637ccc2db11aaed4b4281949760807189
7
+ data.tar.gz: 714c40b722463d91c0ca8cd4e9066506cb7295920ecb953d93ec6eaaa9b0ad719f856d86a6395e52a9bc6ae1a95d46310e4920e537ef9263ee4e208bb131af1f
File without changes
@@ -3,4 +3,11 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/bookman.rb
6
+ lib/bookman/beer.rb
7
+ lib/bookman/bookman.rb
8
+ lib/bookman/config.rb
9
+ lib/bookman/football.rb
6
10
  lib/bookman/version.rb
11
+ lib/bookman/world.rb
12
+ test/helper.rb
13
+ test/test_basics.rb
@@ -1,11 +1,23 @@
1
1
  # encoding: utf-8
2
2
 
3
3
 
4
+ ###
5
+ # todo: add dependencies
6
+ ## - hybook ??
7
+ ## - datafile, bookfile ??
8
+
9
+
4
10
  ####################
5
11
  # our own code
6
12
 
7
13
  require 'bookman/version' # let it always go first
8
14
 
15
+ require 'bookman/bookman'
16
+ require 'bookman/config'
17
+ require 'bookman/world'
18
+ require 'bookman/football'
19
+ require 'bookman/beer'
20
+
9
21
 
10
22
 
11
23
  # say hello
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ module Bookman
4
+
5
+ class BeerConfig < Config
6
+
7
+ def initialize( hash ) super; end
8
+
9
+ def collection() 'beer'; end
10
+
11
+ ############
12
+ # Bookfile
13
+ # -- remote
14
+ def bookfile_url()
15
+ ## note: for now always return beer.rb
16
+ ## use setup/layout-specific bookfiles?? allow selection of package,how?? why,why not??
17
+ "http://github.com/book-templates/bookfile/raw/master/beer.rb"
18
+ end
19
+
20
+ ########
21
+ # Datafile
22
+ # -- remote
23
+ def datafile_url() "http://github.com/openbeer/datafile/raw/master/#{setup}.rb"; end
24
+
25
+ #######
26
+ # Database
27
+ def db_path() "#{build_dir}/#{collection}/#{setup}/#{collection}.db"; end
28
+ def create_db!() BeerDb.create_all; end
29
+
30
+ ####
31
+ # Book Templates
32
+ ## rename to book_dir ?? why, why not? - split zip into book_dir and book_templates_dir why? why not?
33
+ def book_templates_unzip_dir() "#{build_dir}/#{collection}/#{setup}/book"; end
34
+
35
+ end # class BeerConfig
36
+
37
+
38
+ class Bookman
39
+ def self.create_beer_book_for( setup, opts={} )
40
+ config = BeerConfig.new( setup: setup )
41
+ Bookman.new( config )
42
+ end
43
+ end # class Bookman
44
+
45
+ end # module Bookman
@@ -0,0 +1,208 @@
1
+ # encoding: utf-8
2
+
3
+ module Bookman
4
+
5
+ class Bookman
6
+
7
+ ## todo: add logutils/logger here
8
+
9
+ def initialize( config )
10
+ @config = config
11
+
12
+ ## for debugging dump main config settings
13
+ puts "dataset:"
14
+ puts " - collection: #{@config.collection}"
15
+ puts " - setup: #{@config.setup}"
16
+ ## todo: add db_path - why, why not???
17
+
18
+ puts "datafile:"
19
+ puts " - datafile_url (remote): #{@config.datafile_url}"
20
+ puts " - datafile_dir (local): #{@config.datafile_dir}"
21
+ puts " - datafile_path (local): #{@config.datafile_path}"
22
+
23
+ puts "bookfile:"
24
+ puts " - bookfile_url (remote): #{@config.bookfile_url}"
25
+ puts " - bookfile_dir (local): #{@config.bookfile_dir}"
26
+ puts " - bookfile_path (local): #{@config.bookfile_path}"
27
+ ## todo: add bookfile_unzip_path - why, why not???
28
+ end
29
+
30
+
31
+ def dl_datasets
32
+ ## fetch Datafile
33
+ datafile_dir = @config.datafile_dir
34
+ datafile_path = @config.datafile_path
35
+
36
+ ## check if folders exists? if not create folder in path
37
+ FileUtils.mkdir_p( datafile_dir ) unless Dir.exists?( datafile_dir )
38
+
39
+ ## note: lets use http:// instead of https:// for now - lets us use person proxy (NOT working w/ https for now)
40
+ src = @config.datafile_url
41
+ ## dest will be something like './Datafile'
42
+
43
+ fetch_datafile( src, datafile_path )
44
+
45
+ datafile = Datafile::Datafile.load_file( datafile_path )
46
+ datafile.dump ## for debugging
47
+ datafile.download ## datafile step 1 - download all datasets/zips
48
+ end
49
+
50
+
51
+ def dl_book_templates
52
+ ## fetch Bookfile
53
+ bookfile_dir = @config.bookfile_dir
54
+ bookfile_path = @config.bookfile_path
55
+
56
+ ## check if folders exists? if not create folder in path
57
+ FileUtils.mkdir_p( bookfile_dir ) unless Dir.exists?( bookfile_dir )
58
+
59
+ ## note: lets use http:// instead of https:// for now - lets us use person proxy (NOT working w/ https for now)
60
+ src = @config.bookfile_url
61
+ ## dest will be something like './Bookfile'
62
+
63
+ fetch_bookfile( src, bookfile_path )
64
+
65
+
66
+ bookfile = Bookfile::Bookfile.load_file( bookfile_path )
67
+
68
+ bookfile.dump ## for debugging
69
+ bookfile.download ## bookfile step 1 - download all packages/zips (defaults to ./tmp)
70
+
71
+ ## todo/check: already checked in unzip if folder exists???
72
+ dest_unzip = @config.book_templates_unzip_dir
73
+ FileUtils.mkdir_p( dest_unzip ) unless Dir.exists?( dest_unzip )
74
+
75
+ bookfile.unzip( dest_unzip ) ## bookfile step 2 - unzip book templates
76
+ end
77
+
78
+
79
+ def connect
80
+ db_path = @config.db_path
81
+
82
+ db_config = {
83
+ adapter: 'sqlite3',
84
+ database: db_path
85
+ }
86
+
87
+ pp db_config
88
+ ActiveRecord::Base.establish_connection( db_config )
89
+
90
+ c = ActiveRecord::Base.connection
91
+
92
+ ## try to speed up sqlite
93
+ ## see http://www.sqlite.org/pragma.html
94
+ c.execute( 'PRAGMA synchronous=OFF;' )
95
+ c.execute( 'PRAGMA journal_mode=OFF;' )
96
+ ## c.execute( 'PRAGMA journal_mode=MEMORY;' )
97
+ c.execute( 'PRAGMA temp_store=MEMORY;' )
98
+ end
99
+
100
+
101
+ def build_db
102
+ ## clean; remove db if exits
103
+
104
+ db_path = @config.db_path
105
+ FileUtils.rm( db_path ) if File.exists?( db_path )
106
+
107
+ connect()
108
+ @config.create_db!
109
+
110
+ datafile_path = @config.datafile_path
111
+ pp datafile_path
112
+
113
+
114
+ ### hack/quick fix for at,de - "standalone quick test": todo
115
+ ## - find something better
116
+ if datafile_path.end_with?( 'at.rb' ) ||
117
+ datafile_path.end_with?( '/at/Datafile' )
118
+ ## standalone austria for debugging add country
119
+ WorldDb::Model::Country.create!( key: 'at',
120
+ name: 'Austria',
121
+ code: 'AUT',
122
+ pop: 0,
123
+ area: 0 )
124
+ elsif datafile_path.end_with?( 'de.rb' ) ||
125
+ datafile_path.end_with?( '/de/Datafile' )
126
+ WorldDb::Model::Country.create!( key: 'de',
127
+ name: 'Germany',
128
+ code: 'GER',
129
+ pop: 0,
130
+ area: 0 )
131
+ else
132
+ # no special case; continue
133
+ puts "[debug] - no special world archive case w/ start script; continue"
134
+ end
135
+
136
+
137
+ datafile = Datafile::Datafile.load_file( datafile_path )
138
+ datafile.dump ## for debugging
139
+
140
+ ## set "global" logger to debug
141
+ LogUtils::Logger.root.level = :debug
142
+
143
+ datafile.read ## datafile step 2 - read all datasets
144
+ end
145
+
146
+
147
+ def build_book
148
+ connect()
149
+
150
+ bookfile_path = @config.bookfile_path
151
+
152
+ bookfile = Bookfile::Bookfile.load_file( bookfile_path )
153
+ bookfile.dump ## for debugging
154
+
155
+ ### fix:
156
+ ### assume WorldDb::Models already included ??
157
+ ## - for now always include on prepare
158
+ bookfile.prepare( @config.book_templates_unzip_dir )
159
+
160
+ puts " contintents: #{WorldDb::Model::Continent.count}" ## for debugging
161
+
162
+ bookfile.build( @config.book_templates_unzip_dir )
163
+
164
+ puts 'Done.'
165
+ end
166
+
167
+
168
+ def run_jekyll
169
+ # change cwd folder
170
+ cwd = FileUtils.pwd
171
+ puts "cwd (before): #{FileUtils.pwd}"
172
+ FileUtils.cd( @config.book_templates_unzip_dir )
173
+ puts "cwd (after): #{FileUtils.pwd}"
174
+
175
+ ## use `cd #{book_dir}; jekyll build` -- why, why not???
176
+ puts `jekyll build`
177
+
178
+ # restore cwd folder
179
+ FileUtils.cd( cwd )
180
+ end
181
+
182
+
183
+ def build
184
+ ## all-in-one; do everything; complete all steps
185
+ dl_datasets
186
+ dl_book_templates
187
+
188
+ build_db
189
+ build_book
190
+ run_jekyll
191
+ end
192
+
193
+
194
+ private
195
+
196
+ def fetch_datafile( src, dest )
197
+ worker = Fetcher::Worker.new
198
+ worker.copy( src, dest )
199
+ end
200
+
201
+ def fetch_bookfile( src, dest )
202
+ worker = Fetcher::Worker.new
203
+ worker.copy( src, dest )
204
+ end
205
+
206
+ end # class Bookman
207
+
208
+ end # module Bookman
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module Bookman
4
+
5
+ class Config
6
+
7
+ def initialize( hash )
8
+ @hash = hash
9
+
10
+ ### add source_url e.g. https://github.com ?? - why, why not???
11
+
12
+ @build_dir = hash[:build_dir] || './build' ## note: defaults to ./build
13
+ @setup = hash[:setup]
14
+ end
15
+
16
+ def build_dir() @build_dir; end
17
+ def setup() @setup; end ## e.g. at, franken, worldcup, etc.
18
+
19
+ ######
20
+ # Datafile
21
+ # -- local
22
+ def datafile_dir() "#{build_dir}/#{collection}/#{setup}"; end
23
+ def datafile_path() "#{datafile_dir}/Datafile"; end
24
+
25
+ ######
26
+ # Bookfile -- allow multiple (more than one) bookfiles - how? why, why not???
27
+ # -- local
28
+ #
29
+ # todo: move bookfile_dir to unzip dir (e.g. move Bookfile into /book) - why, why not???
30
+ def bookfile_dir() "#{build_dir}/#{collection}/#{setup}"; end
31
+ def bookfile_path() "#{bookfile_dir}/Bookfile"; end
32
+ end
33
+
34
+ end # module Bookman
35
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ module Bookman
4
+
5
+ class FootballConfig < Config
6
+
7
+ def initialize( hash ) super; end
8
+
9
+ def collection() 'football'; end
10
+
11
+ ############
12
+ # Bookfile
13
+ # -- remote
14
+ def bookfile_url()
15
+ ## note: for now always return football.rb
16
+ ## use setup/layout-specific bookfiles?? allow selection of package,how?? why,why not??
17
+ "http://github.com/book-templates/bookfile/raw/master/football.rb"
18
+ end
19
+
20
+ ########
21
+ # Datafile
22
+ # -- remote
23
+ def datafile_url() "http://github.com/openfootball/datafile/raw/master/#{setup}.rb"; end
24
+
25
+ #######
26
+ # Database
27
+ def db_path() "#{build_dir}/#{collection}/#{setup}/#{collection}.db"; end
28
+
29
+ def create_db!()
30
+ SportDb.create_all
31
+ SportDb.read_builtin ## note: load built-in datasets (e.g. seasons etc.)
32
+ end
33
+
34
+ ####
35
+ # Book Templates
36
+ ## rename to book_dir ?? why, why not? - split zip into book_dir and book_templates_dir why? why not?
37
+ def book_templates_unzip_dir() "#{build_dir}/#{collection}/#{setup}/book"; end
38
+
39
+ end # class FootballConfig
40
+
41
+
42
+ class Bookman
43
+ def self.create_football_book_for( setup, opts={} )
44
+ config = FootballConfig.new( setup: setup )
45
+ Bookman.new( config )
46
+ end
47
+ end # class Bookman
48
+
49
+ end # module Bookman
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Bookman
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
 
6
6
  def self.banner
7
7
  "bookman/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ module Bookman
4
+
5
+ class WorldConfig < Config
6
+
7
+ def initialize( hash ) super; end
8
+
9
+ def collection() 'world'; end
10
+
11
+ ############
12
+ # Bookfile
13
+ # -- remote
14
+ def bookfile_url()
15
+ ## note: for now always return world.rb
16
+ ## use country specific bookfiles ?? allow selection of package,how?? why,why not??
17
+ "https://github.com/book-templates/bookfile/raw/master/world.rb"
18
+ end
19
+
20
+ ########
21
+ # Datafile
22
+ # -- remote
23
+ def datafile_url() "https://github.com/openmundi/datafile/raw/master/#{setup}.rb"; end
24
+
25
+ #######
26
+ # Database
27
+ def db_path() "#{build_dir}/#{collection}/#{setup}/#{collection}.db"; end
28
+ def create_db!() WorldDb.create_all; end
29
+
30
+
31
+ ######################
32
+ ## rename to book_dir ?? why, why not? - split zip into book_dir and book_templates_dir why? why not?
33
+ def book_templates_unzip_dir() "#{build_dir}/#{collection}/#{setup}/book"; end
34
+
35
+ end # class WorldConfig
36
+
37
+
38
+ class Bookman
39
+ def self.create_world_book_for( setup, opts={} )
40
+ config = WorldConfig.new( setup: setup )
41
+ Bookman.new( config )
42
+ end
43
+ end # class Bookman
44
+
45
+ end # module Bookman
@@ -0,0 +1,11 @@
1
+ #encoding: utf-8
2
+
3
+ ## minitest setup
4
+ require 'minitest/autorun'
5
+
6
+ ## extra stdlibs
7
+ require 'pp'
8
+
9
+ ## our own code
10
+ require 'bookman'
11
+
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_basics.rb
6
+
7
+ require 'helper'
8
+
9
+ class TestBasics < MiniTest::Test
10
+
11
+ def test_banner
12
+
13
+ banner = "bookman/#{Bookman::VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
14
+
15
+ assert_equal banner, Bookman.banner
16
+ assert_equal banner, BookMan.banner ## check module alias
17
+ end
18
+
19
+ def test_football_config
20
+ cfg = Bookman::FootballConfig.new( setup: 'at' )
21
+ pp cfg
22
+ assert true
23
+ end
24
+
25
+ def test_football_builder
26
+ b = Bookman::Bookman.create_football_book_for( 'at' )
27
+ assert true
28
+ end
29
+
30
+ def test_world_builder
31
+ b = Bookman::Bookman.create_world_book_for( 'at' )
32
+ assert true
33
+ end
34
+
35
+ def test_beer_builder
36
+ b = Bookman::Bookman.create_beer_book_for( 'at' )
37
+ assert true
38
+ end
39
+
40
+ end # class Basics
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -103,12 +103,20 @@ extra_rdoc_files:
103
103
  - Manifest.txt
104
104
  - README.md
105
105
  files:
106
+ - ".gemtest"
106
107
  - HISTORY.md
107
108
  - Manifest.txt
108
109
  - README.md
109
110
  - Rakefile
110
111
  - lib/bookman.rb
112
+ - lib/bookman/beer.rb
113
+ - lib/bookman/bookman.rb
114
+ - lib/bookman/config.rb
115
+ - lib/bookman/football.rb
111
116
  - lib/bookman/version.rb
117
+ - lib/bookman/world.rb
118
+ - test/helper.rb
119
+ - test/test_basics.rb
112
120
  homepage: https://github.com/hybook/bookman
113
121
  licenses:
114
122
  - Public Domain
@@ -135,4 +143,5 @@ rubygems_version: 2.4.2
135
143
  signing_key:
136
144
  specification_version: 4
137
145
  summary: bookman - yet another builder for books
138
- test_files: []
146
+ test_files:
147
+ - test/test_basics.rb