Class: Hybook::BookPress
- Inherits:
-
Object
- Object
- Hybook::BookPress
- Defined in:
- lib/hybook/press/press.rb,
lib/hybook/press/beer.rb,
lib/hybook/press/world.rb,
lib/hybook/press/football.rb
Overview
todo: change/rename class to Press from BookPress - why, why not??
Class Method Summary collapse
- .create_beer_book_for(setup, opts = {}) ⇒ Object
- .create_football_book_for(setup, opts = {}) ⇒ Object
- .create_world_book_for(setup, opts = {}) ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
- #build_book ⇒ Object
- #build_db ⇒ Object
- #connect ⇒ Object
- #dl_book_templates ⇒ Object
- #dl_datasets ⇒ Object
-
#initialize(config) ⇒ BookPress
constructor
A new instance of BookPress.
- #run_jekyll ⇒ Object
Constructor Details
#initialize(config) ⇒ BookPress
Returns a new instance of BookPress.
10 11 12 |
# File 'lib/hybook/press/press.rb', line 10 def initialize( config ) @config = config end |
Class Method Details
.create_beer_book_for(setup, opts = {}) ⇒ Object
39 40 41 42 |
# File 'lib/hybook/press/beer.rb', line 39 def self.create_beer_book_for( setup, opts={} ) config = BeerConfig.new( setup: setup ) BookPress.new( config ) end |
.create_football_book_for(setup, opts = {}) ⇒ Object
34 35 36 37 |
# File 'lib/hybook/press/football.rb', line 34 def self.create_football_book_for( setup, opts={} ) config = FootballConfig.new( setup: setup ) BookPress.new( config ) end |
.create_world_book_for(setup, opts = {}) ⇒ Object
39 40 41 42 |
# File 'lib/hybook/press/world.rb', line 39 def self.create_world_book_for( setup, opts={} ) config = WorldConfig.new( setup: setup ) BookPress.new( config ) end |
Instance Method Details
#build ⇒ Object
167 168 169 170 171 172 173 174 175 |
# File 'lib/hybook/press/press.rb', line 167 def build ## all-in-one; do everything; complete all steps dl_datasets dl_book_templates build_db build_book run_jekyll end |
#build_book ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/hybook/press/press.rb', line 131 def build_book connect() bookfile_path = @config.bookfile_path bookfile = Bookfile::Bookfile.load_file( bookfile_path ) bookfile.dump ## for debugging ### fix: ### assume WorldDb::Models already included ?? ## - for now always include on prepare bookfile.prepare( @config.book_templates_unzip_dir ) puts " contintents: #{WorldDb::Model::Continent.count}" ## for debugging bookfile.build( @config.book_templates_unzip_dir ) puts 'Done.' end |
#build_db ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/hybook/press/press.rb', line 85 def build_db ## clean; remove db if exits db_path = @config.db_path FileUtils.rm( db_path ) if File.exists?( db_path ) connect() @config.create_db! datafile_path = @config.datafile_path pp datafile_path ### hack/quick fix for at,de - "standalone quick test": todo ## - find something better if datafile_path.end_with?( 'at.rb' ) || datafile_path.end_with?( '/at/Datafile' ) ## standalone austria for debugging add country WorldDb::Model::Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 0, area: 0 ) elsif datafile_path.end_with?( 'de.rb' ) || datafile_path.end_with?( '/de/Datafile' ) WorldDb::Model::Country.create!( key: 'de', name: 'Germany', code: 'GER', pop: 0, area: 0 ) else # no special case; continue puts "[debug] - no special world archive case w/ start script; continue" end datafile = Datafile::Datafile.load_file( datafile_path ) datafile.dump ## for debugging logger = LogUtils::Logger.root logger.level = :debug datafile.read ## datafile step 2 - read all datasets end |
#connect ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hybook/press/press.rb', line 63 def connect db_path = @config.db_path db_config = { adapter: 'sqlite3', database: db_path } pp db_config ActiveRecord::Base.establish_connection( db_config ) c = ActiveRecord::Base.connection ## try to speed up sqlite ## see http://www.sqlite.org/pragma.html c.execute( 'PRAGMA synchronous=OFF;' ) c.execute( 'PRAGMA journal_mode=OFF;' ) ## c.execute( 'PRAGMA journal_mode=MEMORY;' ) c.execute( 'PRAGMA temp_store=MEMORY;' ) end |
#dl_book_templates ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hybook/press/press.rb', line 35 def dl_book_templates ## fetch Bookfile bookfile_dir = @config.bookfile_dir bookfile_path = @config.bookfile_path ## check if folders exists? if not create folder in path FileUtils.mkdir_p( bookfile_dir ) unless Dir.exists?( bookfile_dir ) ## note: lets use http:// instead of https:// for now - lets us use person proxy (NOT working w/ https for now) src = @config.bookfile_url ## dest will be something like './Bookfile' fetch_bookfile( src, bookfile_path ) bookfile = Bookfile::Bookfile.load_file( bookfile_path ) bookfile.dump ## for debugging bookfile.download ## bookfile step 1 - download all packages/zips (defaults to ./tmp) ## todo/check: already checked in unzip if folder exists??? dest_unzip = @config.book_templates_unzip_dir FileUtils.mkdir_p( dest_unzip ) unless Dir.exists?( dest_unzip ) bookfile.unzip( dest_unzip ) ## bookfile step 2 - unzip book templates end |
#dl_datasets ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hybook/press/press.rb', line 15 def dl_datasets ## fetch Datafile datafile_dir = @config.datafile_dir datafile_path = @config.datafile_path ## check if folders exists? if not create folder in path FileUtils.mkdir_p( datafile_dir ) unless Dir.exists?( datafile_dir ) ## note: lets use http:// instead of https:// for now - lets us use person proxy (NOT working w/ https for now) src = @config.datafile_url ## dest will be something like './Datafile' fetch_datafile( src, datafile_path ) datafile = Datafile::Datafile.load_file( datafile_path ) datafile.dump ## for debugging datafile.download ## datafile step 1 - download all datasets/zips end |
#run_jekyll ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/hybook/press/press.rb', line 152 def run_jekyll # change cwd folder cwd = FileUtils.pwd puts "cwd (before): #{cwd}" FileUtils.cd( @config.book_templates_unzip_dir ) puts "cwd (after): #{cwd}" ## use `cd #{book_dir}; jekyll build` -- why, why not??? puts `jekyll build` # restore cwd folder FileUtils.cd( cwd ) end |