wax_tasks 0.3.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,136 +0,0 @@
1
- module WaxTasks
2
- # Class for running the Rake tasks in ./tasks
3
- # TaskRunner is responsible for loading and parsing the site config
4
- # from `_config.yml`, which can be overridden with .override(opts)
5
- #
6
- # @attr site [Hash] main variables from site config normalized + symbolized
7
- class TaskRunner
8
- attr_reader :site
9
-
10
- # Creates a new TaskRunner with a config hash or default config file
11
- #
12
- # @param env [String] test/prod. only affects Branch module
13
- # @param config [Hash] optional hash, should mirror a parsed _config.yml
14
- # @example give a custom config
15
- # config = {
16
- # title: 'custom title',
17
- # url: 'custom.url',
18
- # collections: {...}
19
- # }
20
- # WaxTasks::TaskRunner.new(config)
21
- # @example use default config from file
22
- # WaxTasks::TaskRunner.new
23
- def initialize(config = {}, env = 'prod')
24
- config = YAML.load_file(DEFAULT_CONFIG).symbolize_keys if config.empty?
25
- @site = {
26
- env: env,
27
- title: config.fetch(:title, ''),
28
- url: config.fetch(:url, ''),
29
- baseurl: config.fetch(:baseurl, ''),
30
- repo_name: config.fetch(:repo_name, ''),
31
- source_dir: config.fetch(:source, nil),
32
- collections_dir: config.fetch(:collections_dir, nil),
33
- collections: config.fetch(:collections, {}),
34
- js: config.fetch(:js, false),
35
- permalink: Utils.construct_permalink(config)
36
- }
37
- rescue StandardError => e
38
- raise Error::InvalidSiteConfig, "Could not load _config.yml. => #{e}"
39
- end
40
-
41
- # Overrides a specific part of @site
42
- #
43
- # @param opts [Hash] part of the site config to be overwritten
44
- # @example override title + url
45
- # runner = WaxTasks::TaskRunner.new
46
- # runner.override({ title: 'my new title', url: 'my-new.url' })
47
- def override(opts)
48
- opts.each { |k, v| @site[k] = v }
49
- @site[:permalink] = Utils.construct_permalink(opts)
50
- self
51
- end
52
-
53
- # Given an array of command line arguments `args`,
54
- # creates a PagemasterCollection for each and generates markdown
55
- # pages from its specified data `source` file
56
- #
57
- # @param args [Array] the arguments/collection names from wax:pagemaster
58
- # @return [Nil]
59
- def pagemaster(args)
60
- args.each do |name|
61
- PagemasterCollection.new(name, @site).generate_pages
62
- end
63
- end
64
-
65
- # Creates a LunrCollection for each collection
66
- # that has lunr_index parameters in the site config
67
- # and generates a lunr-index.json file from the collection data
68
- #
69
- # @param generate_ui [Boolean] whether/not to generate a default lunr UI
70
- # @return [Nil]
71
- def lunr(generate_ui: false)
72
- lunr_collections = Utils.get_lunr_collections(@site)
73
- lunr_collections.map! { |name| LunrCollection.new(name, @site) }
74
-
75
- index = LunrIndex.new(lunr_collections)
76
- index_path = Utils.make_path(@site[:source_dir], LUNR_INDEX_PATH)
77
-
78
- FileUtils.mkdir_p(File.dirname(index_path))
79
- File.open(index_path, 'w') { |f| f.write(index) }
80
- puts "Writing lunr search index to #{index_path}.".cyan
81
-
82
- if generate_ui
83
- ui_path = Utils.make_path(@site[:source_dir], LUNR_UI_PATH)
84
- puts "Writing default lunr UI to #{ui_path}.".cyan
85
- File.open(ui_path, 'w') { |f| f.write(index.default_ui) }
86
- end
87
- end
88
-
89
- # Given an array of command line arguments `args`,
90
- # creates a IiifCollection for each and generates iiif
91
- # derivative images, manifests, etc. from source image files
92
- #
93
- # @param args [Array] the arguments/collection names from wax:pagemaster
94
- # @return [Nil]
95
- def iiif(args)
96
- args.each do |name|
97
- IiifCollection.new(name, @site).process
98
- end
99
- end
100
-
101
- # Finds the JS dependencies listed in site config and
102
- # writes them to a package.json file
103
- # in orderto easily track / monitor / update them
104
- #
105
- # @return [Nil]
106
- def js_package
107
- names = []
108
- package = {
109
- 'name' => site[:title],
110
- 'version' => '1.0.0',
111
- 'dependencies' => {}
112
- }
113
- site[:js].each do |dependency|
114
- name = dependency[0]
115
- names << name
116
- version = dependency[1]['version']
117
- package['dependencies'][name] = '^' + version
118
- end
119
- package
120
- end
121
-
122
- # Constructs a TravisBranch or LocalBranch object
123
- # with appropriate Git credentials and pushes
124
- # the compiled Jekyll site to the target GitHub branch
125
- #
126
- # @param target [String] the name of the Git branch to deploy to
127
- # @return [Nil]
128
- def push_branch(target)
129
- if ENV.fetch('CI', false)
130
- TravisBranch.new(self.site, target).push
131
- else
132
- LocalBranch.new(self.site, target).push
133
- end
134
- end
135
- end
136
- end
@@ -1,28 +0,0 @@
1
- require 'time'
2
-
3
- module WaxTasks
4
- # Branch object for `$ wax:push` task when run on Travis-CI VM
5
- # using encrypted Travis environment vars
6
- #
7
- # @attr repo_slug [String] the 'user/repo_name'
8
- # @attr user [String] the GitHub user making the commit/push
9
- # @attr token [String] secret git access token
10
- # @attr commit_msg [String] the commit message to use on push
11
- # @attr origin [String] the current repository remote
12
- # @attr baseurl [String] the site baseurl to build with (if on gh-pages)
13
- # @attr success_msg [String] informative message to be output to console
14
- class TravisBranch < Branch
15
- def initialize(site, target)
16
- super(site, target)
17
-
18
- @repo_slug = ENV['TRAVIS_REPO_SLUG']
19
- @user = @repo_slug.split('/').first
20
- @token = ENV['ACCESS_TOKEN']
21
-
22
- @commit_msg = "Updated via #{ENV['TRAVIS_COMMIT']} @#{Time.now.utc}"
23
- @origin = "https://#{@user}:#{@token}@github.com/#{@repo_slug}.git"
24
- @baseurl = "/#{@repo_slug.split('/').last}"
25
- @success_msg = "Deploying to #{@target} branch from Travis as #{@user}."
26
- end
27
- end
28
- end