Class: WaxTasks::TaskRunner
- Inherits:
-
Object
- Object
- WaxTasks::TaskRunner
- Defined in:
- lib/wax_tasks/task_runner.rb
Overview
Class for running the Rake tasks in ./tasks TaskRunner is responsible for loading and parsing the site config from ‘_config.yml`, which can be overridden with .override(opts)
Instance Attribute Summary collapse
-
#site ⇒ Hash
main variables from site config normalized + symbolized.
Instance Method Summary collapse
-
#iiif(args) ⇒ Nil
Given an array of command line arguments ‘args`, creates a IiifCollection for each and generates iiif derivative images, manifests, etc.
-
#initialize(config = {}, env = 'prod') ⇒ TaskRunner
constructor
Creates a new TaskRunner with a config hash or default config file.
-
#js_package ⇒ Nil
Finds the JS dependencies listed in site config and writes them to a package.json file in orderto easily track / monitor / update them.
-
#lunr(generate_ui: false) ⇒ Nil
Creates a LunrCollection for each collection that has lunr_index parameters in the site config and generates a lunr-index.json file from the collection data.
-
#override(opts) ⇒ Object
Overrides a specific part of @site.
-
#pagemaster(args) ⇒ Nil
Given an array of command line arguments ‘args`, creates a PagemasterCollection for each and generates markdown pages from its specified data `source` file.
-
#push_branch(target) ⇒ Nil
Constructs a TravisBranch or LocalBranch object with appropriate Git credentials and pushes the compiled Jekyll site to the target GitHub branch.
Constructor Details
#initialize(config = {}, env = 'prod') ⇒ TaskRunner
Creates a new TaskRunner with a config hash or default config file
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wax_tasks/task_runner.rb', line 23 def initialize(config = {}, env = 'prod') config = YAML.load_file(DEFAULT_CONFIG).symbolize_keys if config.empty? @site = { env: env, title: config.fetch(:title, ''), url: config.fetch(:url, ''), baseurl: config.fetch(:baseurl, ''), repo_name: config.fetch(:repo_name, ''), source_dir: config.fetch(:source, nil), collections_dir: config.fetch(:collections_dir, nil), collections: config.fetch(:collections, {}), js: config.fetch(:js, false), permalink: Utils.construct_permalink(config) } rescue StandardError => e raise Error::InvalidSiteConfig, "Could not load _config.yml. => #{e}" end |
Instance Attribute Details
#site ⇒ Hash
main variables from site config normalized + symbolized
7 8 9 |
# File 'lib/wax_tasks/task_runner.rb', line 7 def site @site end |
Instance Method Details
#iiif(args) ⇒ Nil
Given an array of command line arguments ‘args`, creates a IiifCollection for each and generates iiif derivative images, manifests, etc. from source image files
95 96 97 98 99 |
# File 'lib/wax_tasks/task_runner.rb', line 95 def iiif(args) args.each do |name| IiifCollection.new(name, @site).process end end |
#js_package ⇒ Nil
Finds the JS dependencies listed in site config and writes them to a package.json file in orderto easily track / monitor / update them
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/wax_tasks/task_runner.rb', line 106 def js_package names = [] package = { 'name' => site[:title], 'version' => '1.0.0', 'dependencies' => {} } site[:js].each do |dependency| name = dependency[0] names << name version = dependency[1]['version'] package['dependencies'][name] = '^' + version end package end |
#lunr(generate_ui: false) ⇒ Nil
Creates a LunrCollection for each collection that has lunr_index parameters in the site config and generates a lunr-index.json file from the collection data
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wax_tasks/task_runner.rb', line 71 def lunr(generate_ui: false) lunr_collections = Utils.get_lunr_collections(@site) lunr_collections.map! { |name| LunrCollection.new(name, @site) } index = LunrIndex.new(lunr_collections) index_path = Utils.make_path(@site[:source_dir], LUNR_INDEX_PATH) FileUtils.mkdir_p(File.dirname(index_path)) File.open(index_path, 'w') { |f| f.write(index) } puts "Writing lunr search index to #{index_path}.".cyan if generate_ui ui_path = Utils.make_path(@site[:source_dir], LUNR_UI_PATH) puts "Writing default lunr UI to #{ui_path}.".cyan File.open(ui_path, 'w') { |f| f.write(index.default_ui) } end end |
#override(opts) ⇒ Object
Overrides a specific part of @site
47 48 49 50 51 |
# File 'lib/wax_tasks/task_runner.rb', line 47 def override(opts) opts.each { |k, v| @site[k] = v } @site[:permalink] = Utils.construct_permalink(opts) self end |
#pagemaster(args) ⇒ Nil
Given an array of command line arguments ‘args`, creates a PagemasterCollection for each and generates markdown pages from its specified data `source` file
59 60 61 62 63 |
# File 'lib/wax_tasks/task_runner.rb', line 59 def pagemaster(args) args.each do |name| PagemasterCollection.new(name, @site).generate_pages end end |
#push_branch(target) ⇒ Nil
Constructs a TravisBranch or LocalBranch object with appropriate Git credentials and pushes the compiled Jekyll site to the target GitHub branch
128 129 130 131 132 133 134 |
# File 'lib/wax_tasks/task_runner.rb', line 128 def push_branch(target) if ENV.fetch('CI', false) TravisBranch.new(self.site, target).push else LocalBranch.new(self.site, target).push end end |