wax_tasks 0.0.47 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/modules/iiif.rb +19 -29
- data/lib/modules/lunr.rb +67 -51
- data/lib/modules/pagemaster.rb +45 -40
- data/lib/tasks/iiif.rake +4 -5
- data/lib/tasks/jspackage.rake +4 -2
- data/lib/tasks/lunr.rake +1 -1
- data/lib/tasks/pagemaster.rake +5 -5
- data/lib/tasks/push_gh.rake +6 -8
- data/lib/tasks/{push_s3.rake → push_static.rake} +7 -3
- data/lib/tasks/test.rake +9 -13
- data/lib/wax_tasks.rb +26 -25
- data/spec/spec_helper.rb +97 -30
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f996fd8c491dac2f46d075b4b28dc9064f6f4b4f74005e41da3a624080c7aa4
|
4
|
+
data.tar.gz: bd3acb6ae9045c3d89c226d4fd6600b8e8349ee931a2cd9df9232761f18eea33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 310e898680e1598c0e58926e0bb3faf8b6eb678fa853fd133940ad6220441fc05e9a938330fe1a9e286b8ffa347480d115e1077f9a3bc738970669623ce01406
|
7
|
+
data.tar.gz: 875d638a7d3cefad2fa77793ed458ecfd4392e5bb7c278de2fb6b931df81925d5ccb7041f50f0120617aea2849a559379944b8d2920dae46a0ceed55781b2388
|
data/Gemfile
CHANGED
data/lib/modules/iiif.rb
CHANGED
@@ -1,45 +1,35 @@
|
|
1
|
+
require 'colorized_string'
|
1
2
|
require 'json'
|
2
3
|
require 'wax_iiif'
|
3
4
|
|
4
5
|
# module for generating IIIF derivatives + json from local images
|
5
6
|
module Iiif
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
all_records = []
|
11
|
-
id_counter = 0
|
12
|
-
build_opts = Iiif.build_options(site_config)
|
13
|
-
args.each do |a|
|
14
|
-
id_counter += 1
|
15
|
-
inpath = './_data/iiif/' + a
|
16
|
-
abort "Source path '#{inpath}' does not exist. Exiting.".magenta unless Dir.exist?(inpath)
|
17
|
-
collection_records = make_records(a, inpath)
|
18
|
-
all_records.concat collection_records
|
7
|
+
def self.process(name, site_config)
|
8
|
+
inpath = "./_data/iiif/#{name}"
|
9
|
+
unless Dir.exist?(inpath)
|
10
|
+
abort "Source path '#{inpath}' does not exist. Exiting.".magenta
|
19
11
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
{
|
27
|
-
:base_url => site_config['baseurl'] + '/iiif',
|
28
|
-
:output_dir => './iiif',
|
29
|
-
:verbose => true
|
12
|
+
FileUtils.mkdir_p("./iiif/#{name}", verbose: false)
|
13
|
+
build_opts = {
|
14
|
+
base_url: "#{site_config['baseurl']}/iiif/#{name}",
|
15
|
+
output_dir: "./iiif/#{name}",
|
16
|
+
verbose: true,
|
17
|
+
variants: { med: 600, lg: 1140 }
|
30
18
|
}
|
19
|
+
builder = IiifS3::Builder.new(build_opts)
|
20
|
+
builder.load(make_records(name, inpath))
|
21
|
+
builder.process_data(true)
|
31
22
|
end
|
32
23
|
|
33
|
-
def self.make_records(
|
24
|
+
def self.make_records(name, inpath)
|
34
25
|
counter = 1
|
35
26
|
records = []
|
36
|
-
|
37
|
-
imagefiles.each do |imagefile|
|
27
|
+
Dir["#{inpath}/*"].sort!.each do |imagefile|
|
38
28
|
basename = File.basename(imagefile, '.*').to_s
|
39
29
|
record_opts = {
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
30
|
+
id: basename,
|
31
|
+
path: imagefile,
|
32
|
+
label: "#{name} #{basename}"
|
43
33
|
}
|
44
34
|
counter += 1
|
45
35
|
records << IiifS3::ImageRecord.new(record_opts)
|
data/lib/modules/lunr.rb
CHANGED
@@ -1,34 +1,33 @@
|
|
1
|
-
|
1
|
+
require 'colorized_string'
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
# module for generating elasticlunr index and default jquery ui
|
5
5
|
module Lunr
|
6
|
-
def self.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
def self.write_index(site_config)
|
7
|
+
index = index(site_config)
|
8
|
+
FileUtils.mkdir_p('js')
|
9
|
+
index = "---\nlayout: none\n---\n" + index
|
10
|
+
path = 'js/lunr-index.json'
|
11
|
+
File.open(path, 'w') { |file| file.write(index) }
|
12
|
+
puts "Writing lunr index to #{path}".cyan
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.
|
16
|
-
|
17
|
-
|
15
|
+
def self.index(site_config)
|
16
|
+
collections = collections_to_index(site_config)
|
17
|
+
collections_dir = site_config['collections_dir'].to_s
|
18
18
|
|
19
|
-
def self.index(cdir, collections)
|
20
19
|
index = []
|
21
20
|
count = 0
|
22
|
-
abort 'There are no valid collections to index.'.magenta if collections.nil?
|
23
21
|
|
24
|
-
collections.each do |
|
25
|
-
dir =
|
26
|
-
|
22
|
+
collections.each do |collection|
|
23
|
+
dir = "_#{collection[:name]}"
|
24
|
+
dir.prepend("#{collections_dir}/") unless collections_dir.empty?
|
27
25
|
pages = Dir.glob(dir + '/*.md')
|
28
|
-
get_content =
|
26
|
+
get_content = collection[:lunr_index].key?('content') ? collection[:lunr_index]['content'] : false
|
27
|
+
fields = collection[:lunr_index]['fields']
|
29
28
|
# catch
|
30
|
-
abort "There are no
|
31
|
-
abort "There are no fields
|
29
|
+
abort "There are no pages in '#{dir}'".magenta if pages.empty?
|
30
|
+
abort "There are no fields for #{collection.name}.".magenta if fields.empty?
|
32
31
|
puts "Loading #{pages.length} pages from #{dir}"
|
33
32
|
# index each page in collection
|
34
33
|
pages.each do |page|
|
@@ -39,55 +38,72 @@ module Lunr
|
|
39
38
|
JSON.pretty_generate(index)
|
40
39
|
end
|
41
40
|
|
42
|
-
def self.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
def self.write_ui(site_config)
|
42
|
+
ui_str = ui(site_config)
|
43
|
+
ui = "---\nlayout: none\n---\n" + ui_str
|
44
|
+
path = 'js/lunr-ui.js'
|
45
|
+
if File.exist?(path)
|
46
|
+
puts "Lunr UI already exists at #{path}. Skipping".cyan
|
47
|
+
else
|
48
|
+
File.open(path, 'w') { |file| file.write(ui) }
|
49
|
+
puts "Writing lunr ui to #{path}".cyan
|
50
|
+
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def self.ui(
|
53
|
+
def self.ui(site_config)
|
54
54
|
# set up index
|
55
|
-
|
55
|
+
ui = "$.getJSON(\"{{ site.baseurl }}/js/lunr-index.json\", function(index_json) {\nwindow.index = new elasticlunr.Index;\nwindow.store = index_json;\nindex.saveDocument(false);\nindex.setRef('lunr_id');"
|
56
56
|
# add fields to index
|
57
|
-
total_fields
|
57
|
+
total_fields = total_fields(site_config)
|
58
|
+
total_fields.each { |field| ui += "\nindex.addField('#{field}');" }
|
58
59
|
# add docs
|
59
|
-
|
60
|
+
ui += "\n// add docs\nfor (i in store){index.addDoc(store[i]);}"
|
60
61
|
# gui
|
61
|
-
|
62
|
+
ui += "\n$('input#search').on('keyup', function() {\nvar results_div = $('#results');\nvar query = $(this).val();\nvar results = index.search(query, { boolean: 'AND', expand: true });\nresults_div.empty();\nif (results.length > 10) {\nresults_div.prepend(\"<p><small>Displaying 10 of \" + results.length + \" results.</small></p>\");\n}\nfor (var r in results.slice(0, 9)) {\nvar ref = results[r].ref;\nvar item = store[ref];"
|
62
63
|
# add fields as display vars
|
63
|
-
total_fields.each { |field|
|
64
|
-
|
65
|
-
|
64
|
+
total_fields.each { |field| ui += "var #{field} = item.#{field};\n" }
|
65
|
+
ui += "var result = '<div class=\"result\"><b><a href=\"' + item.link + '\">' + title + '</a></b></p></div>';\nresults_div.append(result);\n}\n});\n});"
|
66
|
+
ui
|
66
67
|
end
|
67
68
|
|
68
|
-
def self.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
def self.collections_to_index(site_config)
|
70
|
+
to_index = site_config['collections'].find_all { |c| c[1].key?('lunr_index') }
|
71
|
+
to_index.map! { |c| c[0] }
|
72
|
+
abort 'There are no valid collections to index.'.magenta if to_index.nil?
|
73
|
+
collections = []
|
74
|
+
to_index.each do |c|
|
75
|
+
collections << WaxTasks.collection(c, site_config)
|
76
|
+
end
|
77
|
+
collections
|
74
78
|
end
|
75
79
|
|
76
|
-
def self.
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
puts "Writing lunr ui to #{path}".cyan
|
80
|
+
def self.total_fields(site_config)
|
81
|
+
total_fields = ['pid']
|
82
|
+
site_config['collections'].each do |c|
|
83
|
+
if c[1].key?('lunr_index') && c[1]['lunr_index'].key?('fields')
|
84
|
+
total_fields = total_fields.concat(c[1]['lunr_index']['fields'])
|
85
|
+
total_fields << 'content' if c[1]['lunr_index']['content']
|
86
|
+
end
|
84
87
|
end
|
88
|
+
total_fields.uniq
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.page_hash(page, fields, get_content, count)
|
92
|
+
yaml = YAML.load_file(page)
|
93
|
+
hash = {
|
94
|
+
'lunr_id' => count,
|
95
|
+
'link' => "{{'" + yaml.fetch('permalink') + "' | relative_url }}",
|
96
|
+
'collection' => yaml.fetch('permalink').to_s[%r{^\/([^\/]*)\/}].tr('/', '')
|
97
|
+
}
|
98
|
+
fields.each { |f| hash[f] = rm_diacritics(thing2string(yaml[f])) }
|
99
|
+
hash['content'] = rm_diacritics(clean(File.read(page))) if get_content
|
100
|
+
hash
|
85
101
|
end
|
86
102
|
|
87
103
|
def self.clean(str)
|
88
104
|
str.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
|
89
105
|
str.gsub!(/{%(.*)%}/, '') # remove functional liquid
|
90
|
-
str.gsub!(
|
106
|
+
str.gsub!(%r{<\/?[^>]*>}, '') # remove html
|
91
107
|
str.gsub!('\\n', '') # remove newlines
|
92
108
|
str.gsub!(/\s+/, ' ') # remove extra space
|
93
109
|
str.tr!('"', "'") # replace double quotes with single
|
data/lib/modules/pagemaster.rb
CHANGED
@@ -1,68 +1,73 @@
|
|
1
|
+
require 'colorized_string'
|
2
|
+
require 'csv'
|
3
|
+
require 'fileutils'
|
1
4
|
require 'json'
|
2
5
|
require 'yaml'
|
3
|
-
require 'csv'
|
4
6
|
|
5
7
|
# module for generating markdown collection pages from csv/json/yaml records
|
6
8
|
module Pagemaster
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
collection_config = site_config['collections'][name]
|
12
|
-
abort "Cannot find source for '#{name}'. Exiting.".magenta unless collection_config['source']
|
13
|
-
abort "Cannot find layout for '#{name}'. Exiting.".magenta unless collection_config['layout']
|
14
|
-
abort "Cannot find the file _data/#{collection_config['source']}.".magenta unless File.file?('_data/' + collection_config['source'])
|
15
|
-
collection_config
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.ingest(src)
|
19
|
-
src = "_data/#{src}"
|
20
|
-
case File.extname(src)
|
21
|
-
when '.csv' then data = CSV.read(src, :headers => true, :encoding => 'utf-8').map(&:to_hash)
|
22
|
-
when '.json' then data = JSON.parse(File.read(src))
|
23
|
-
when '.yml' then data = YAML.load_file(src)
|
24
|
-
else abort "File type for #{src} must be .csv, .json, or .yml. Please fix and rerun."
|
25
|
-
end
|
26
|
-
puts "Processing #{src}...."
|
27
|
-
detect_duplicates(data)
|
28
|
-
data
|
29
|
-
rescue StandardError
|
30
|
-
puts "Cannot load #{src}. check for typos and rebuild.".magenta
|
31
|
-
end
|
9
|
+
def self.generate(collection, site_config)
|
10
|
+
records = ingest(collection[:source])
|
11
|
+
dir = target_dir(collection[:name], site_config)
|
12
|
+
permalink_style = WaxTasks.permalink_style(site_config)
|
32
13
|
|
33
|
-
def self.generate_pages(data, name, layout, cdir, order, perma)
|
34
|
-
dir = cdir + '_' + name
|
35
|
-
mkdir_p(dir)
|
36
14
|
completed = 0
|
37
15
|
skipped = 0
|
38
|
-
|
16
|
+
|
17
|
+
records.each_with_index do |item, index|
|
39
18
|
pagename = WaxTasks.slug(item.fetch('pid'))
|
40
19
|
pagepath = dir + '/' + pagename + '.md'
|
41
20
|
if File.exist?(pagepath)
|
42
21
|
puts "#{pagename}.md already exits. Skipping."
|
43
22
|
skipped += 1
|
44
23
|
else
|
45
|
-
item['permalink'] = '/' + name + '/' + pagename +
|
46
|
-
item['layout'] = layout
|
47
|
-
item['order'] = padded_int(index,
|
24
|
+
item['permalink'] = '/' + collection[:name] + '/' + pagename + permalink_style
|
25
|
+
item['layout'] = collection[:layout]
|
26
|
+
item['order'] = padded_int(index, records.length) if collection[:keep_order]
|
48
27
|
File.open(pagepath, 'w') { |f| f.write(item.to_yaml.to_s + '---') }
|
49
28
|
completed += 1
|
50
29
|
end
|
51
30
|
end
|
31
|
+
|
52
32
|
puts "\n#{completed} pages were generated to #{dir} directory.".cyan
|
53
33
|
puts "\n#{skipped} pre-existing items were skipped.".cyan
|
54
|
-
rescue StandardError
|
55
|
-
abort "#{completed} pages
|
34
|
+
rescue StandardError => e
|
35
|
+
abort "Failure after #{completed} pages, likely from missing pid.".magenta + "\n#{e}"
|
56
36
|
end
|
57
37
|
|
58
|
-
def self.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
38
|
+
def self.ingest(source)
|
39
|
+
src = "_data/#{source}"
|
40
|
+
opts = { headers: true, encoding: 'utf-8' }
|
41
|
+
|
42
|
+
case File.extname(src)
|
43
|
+
when '.csv' then data = CSV.read(src, opts).map(&:to_hash)
|
44
|
+
when '.json' then data = JSON.parse(File.read(src))
|
45
|
+
when '.yml' then data = YAML.load_file(src)
|
46
|
+
else abort "Source #{src} must be .csv, .json, or .yml.".magenta
|
47
|
+
end
|
48
|
+
|
49
|
+
puts "Processing #{src}...."
|
50
|
+
validate(data)
|
51
|
+
rescue StandardError => e
|
52
|
+
abort "Cannot load #{src}. check for typos and rebuild.".magenta + "\n#{e}"
|
63
53
|
end
|
64
54
|
|
65
55
|
def self.padded_int(index, max_idx)
|
66
56
|
index.to_s.rjust(Math.log10(max_idx).to_i + 1, '0')
|
67
57
|
end
|
58
|
+
|
59
|
+
def self.validate(data)
|
60
|
+
pids = data.map { |d| d['pid'] }
|
61
|
+
duplicates = pids.detect { |p| pids.count(p) > 1 } || []
|
62
|
+
abort "Fix duplicate pids: \n#{duplicates}".magenta unless duplicates.empty?
|
63
|
+
data
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.target_dir(collection_name, site_config)
|
67
|
+
collections_dir = site_config['collections_dir'].to_s
|
68
|
+
dir = collections_dir.empty? ? '_' : collections_dir + '/_'
|
69
|
+
dir += collection_name
|
70
|
+
FileUtils.mkdir_p(dir)
|
71
|
+
dir
|
72
|
+
end
|
68
73
|
end
|
data/lib/tasks/iiif.rake
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
|
1
|
+
require 'colorized_string'
|
2
2
|
require 'wax_tasks'
|
3
|
-
require 'wax_iiif'
|
4
3
|
|
5
4
|
namespace :wax do
|
6
5
|
task :iiif do
|
7
6
|
args = ARGV.drop(1).each { |a| task a.to_sym }
|
8
|
-
|
9
|
-
|
10
|
-
WaxTasks.iiif(
|
7
|
+
abort "Please specify a collections after 'wax:iiif'".magenta if args.empty?
|
8
|
+
site_config = WaxTasks.site_config
|
9
|
+
args.each { |collection_name| WaxTasks.iiif(collection_name, site_config) }
|
11
10
|
end
|
12
11
|
end
|
data/lib/tasks/jspackage.rake
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'colorized_string'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
+
require 'wax_tasks'
|
5
|
+
|
4
6
|
namespace :wax do
|
5
7
|
desc 'write a simple package.json'
|
6
8
|
task :jspackage do
|
7
|
-
site_config = WaxTasks.
|
9
|
+
site_config = WaxTasks.site_config
|
8
10
|
package = {
|
9
11
|
'name' => site_config['title'],
|
10
12
|
'version' => '1.0.0',
|
data/lib/tasks/lunr.rake
CHANGED
data/lib/tasks/pagemaster.rake
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
+
require 'colorized_string'
|
1
2
|
require 'wax_tasks'
|
2
3
|
|
3
4
|
namespace :wax do
|
4
5
|
desc 'generate collection md pages from yaml or csv data source'
|
5
6
|
task :pagemaster do
|
6
7
|
args = ARGV.drop(1).each { |a| task a.to_sym }
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
args.each { |a| WaxTasks.pagemaster(a, site_config) }
|
8
|
+
abort "Please specify a collection after 'wax:pagemaster'".magenta if args.empty?
|
9
|
+
args.each do |collection_name|
|
10
|
+
site_config = WaxTasks.site_config
|
11
|
+
WaxTasks.pagemaster(collection_name, site_config)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/tasks/push_gh.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'wax_tasks'
|
1
|
+
require 'colorized_string'
|
3
2
|
require 'jekyll'
|
3
|
+
require 'wax_tasks'
|
4
4
|
|
5
5
|
namespace :wax do
|
6
6
|
namespace :push do
|
@@ -19,21 +19,19 @@ namespace :wax do
|
|
19
19
|
COMMIT_MSG = "Site updated at #{Time.now.utc}".freeze
|
20
20
|
puts 'Deploying to gh-pages branch from local task'
|
21
21
|
end
|
22
|
-
config =
|
23
|
-
rm_rf('_site')
|
24
|
-
|
25
|
-
baseurl = config['gh-baseurl'] || REPO_NAME.to_s
|
22
|
+
config = WaxTasks.site_config
|
23
|
+
FileUtils.rm_rf('_site')
|
26
24
|
|
27
25
|
opts = {
|
28
26
|
'source' => '.',
|
29
27
|
'destination' => '_site',
|
30
28
|
'config' => '_config.yml',
|
31
|
-
'baseurl' => baseurl
|
29
|
+
'baseurl' => config['gh-baseurl'] || REPO_NAME.to_s
|
32
30
|
}
|
33
31
|
|
34
32
|
Jekyll::Site.new(Jekyll.configuration(opts)).process
|
35
33
|
Dir.mktmpdir do |tmp|
|
36
|
-
cp_r '_site/.', tmp
|
34
|
+
FileUtils.cp_r '_site/.', tmp
|
37
35
|
Dir.chdir tmp
|
38
36
|
system 'git init'
|
39
37
|
system "git add . && git commit -m '#{COMMIT_MSG}'"
|
@@ -1,11 +1,15 @@
|
|
1
|
-
include FileUtils
|
2
1
|
require 'wax_tasks'
|
3
2
|
|
4
3
|
namespace :wax do
|
5
4
|
namespace :push do
|
6
5
|
desc 'push built site to s3 branch'
|
7
|
-
task :
|
6
|
+
task :static do
|
8
7
|
if ENV['CI']
|
8
|
+
puts "Build type=#{ENV['TRAVIS_EVENT_TYPE']}"
|
9
|
+
unless ENV['TRAVIS_BRANCH'] == 'master'
|
10
|
+
puts "Skipping deploy from branch #{ENV['TRAVIS_BRANCH']}"
|
11
|
+
next
|
12
|
+
end
|
9
13
|
REPO_SLUG = ENV['TRAVIS_REPO_SLUG']
|
10
14
|
USER = REPO_SLUG.split('/')[0]
|
11
15
|
TOKEN = ENV['ACCESS_TOKEN']
|
@@ -19,7 +23,7 @@ namespace :wax do
|
|
19
23
|
end
|
20
24
|
|
21
25
|
Dir.mktmpdir do |tmp|
|
22
|
-
cp_r '_site/.', tmp
|
26
|
+
FileUtils.cp_r '_site/.', tmp
|
23
27
|
Dir.chdir tmp
|
24
28
|
system 'git init'
|
25
29
|
system "git add . && git commit -m '#{COMMIT_MSG}'"
|
data/lib/tasks/test.rake
CHANGED
@@ -1,23 +1,19 @@
|
|
1
|
-
require '
|
1
|
+
require 'colorized_string'
|
2
2
|
require 'html-proofer'
|
3
3
|
|
4
4
|
namespace :wax do
|
5
5
|
desc 'run htmlproofer, rspec if exists'
|
6
6
|
task :test do
|
7
7
|
opts = {
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
8
|
+
check_external_hash: true,
|
9
|
+
allow_hash_href: true,
|
10
|
+
check_html: true,
|
11
|
+
disable_external: true,
|
12
|
+
empty_alt_ignore: true,
|
13
|
+
only_4xx: true,
|
14
|
+
verbose: true
|
15
15
|
}
|
16
|
-
|
17
|
-
HTMLProofer.check_directory('./_site', opts).run
|
18
|
-
rescue StandardError
|
19
|
-
puts('Failed to run wax:texts. Make sure you are using `bundle exec`.').magenta
|
20
|
-
end
|
16
|
+
HTMLProofer.check_directory('./_site', opts).run
|
21
17
|
sh 'bundle exec rspec' if File.exist?('.rspec')
|
22
18
|
end
|
23
19
|
end
|
data/lib/wax_tasks.rb
CHANGED
@@ -1,43 +1,44 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
require_relative 'modules/iiif'
|
2
4
|
require_relative 'modules/lunr'
|
3
5
|
require_relative 'modules/pagemaster'
|
4
6
|
|
5
|
-
require 'yaml'
|
6
|
-
require 'wax_iiif'
|
7
|
-
|
8
7
|
# umbrella module for registering task modules
|
9
8
|
module WaxTasks
|
10
|
-
def self.pagemaster(
|
11
|
-
|
12
|
-
|
13
|
-
src = collection_config['source']
|
14
|
-
data = Pagemaster.ingest(src)
|
15
|
-
layout = collection_config.fetch('layout').to_s
|
16
|
-
perma = config['permalink'] == 'pretty' ? '/' : '.html'
|
17
|
-
cdir = site_config['collections_dir'].to_s
|
18
|
-
order = collection_config.key?('keep_order') ? collection_config.fetch('keep_order') : false
|
19
|
-
|
20
|
-
Pagemaster.generate_pages(data, name, layout, cdir, order, perma)
|
9
|
+
def self.pagemaster(collection_name, site_config)
|
10
|
+
collection = collection(collection_name, site_config)
|
11
|
+
Pagemaster.generate(collection, site_config)
|
21
12
|
end
|
22
13
|
|
23
14
|
def self.lunr(site_config)
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
Lunr.write_index(site_config)
|
16
|
+
Lunr.write_ui(site_config)
|
17
|
+
end
|
27
18
|
|
28
|
-
|
29
|
-
|
19
|
+
def self.iiif(collection_name, site_config)
|
20
|
+
Iiif.process(collection_name, site_config)
|
21
|
+
end
|
30
22
|
|
31
|
-
|
32
|
-
|
23
|
+
def self.site_config
|
24
|
+
YAML.load_file('_config.yml')
|
33
25
|
end
|
34
26
|
|
35
|
-
def self.
|
36
|
-
|
27
|
+
def self.permalink_style(site_config)
|
28
|
+
site_config['permalink'] == 'pretty' ? '/' : '.html'
|
37
29
|
end
|
38
30
|
|
39
|
-
def self.
|
40
|
-
|
31
|
+
def self.collection(collection_name, site_config)
|
32
|
+
conf = site_config.fetch('collections').fetch(collection_name)
|
33
|
+
{
|
34
|
+
name: collection_name,
|
35
|
+
source: conf['source'],
|
36
|
+
layout: conf['layout'],
|
37
|
+
keep_order: conf.key?('keep_order') ? conf['keep_order'] : false,
|
38
|
+
lunr_index: conf['lunr_index']
|
39
|
+
}
|
40
|
+
rescue StandardError => e
|
41
|
+
abort "Collection '#{collection_name}' is not properly configured.".magenta + "\n#{e}"
|
41
42
|
end
|
42
43
|
|
43
44
|
def self.slug(str)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
2
3
|
|
3
4
|
require_relative 'fake/data'
|
4
5
|
require_relative 'fake/site'
|
@@ -6,59 +7,123 @@ require_relative 'fake/site'
|
|
6
7
|
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
7
8
|
require 'wax_tasks'
|
8
9
|
|
9
|
-
|
10
|
-
Fake.
|
10
|
+
silence_output do
|
11
|
+
Fake.site
|
12
|
+
Fake.data
|
13
|
+
end
|
14
|
+
|
15
|
+
site_config = WaxTasks.site_config
|
16
|
+
bad_src_config = {
|
17
|
+
'collections' => {
|
18
|
+
'test' => {
|
19
|
+
'source' => 'test.jpg'
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
missing_src_config = {
|
24
|
+
'collections' => {
|
25
|
+
'test' => {
|
26
|
+
'source' => 'test.csv'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
11
30
|
|
12
31
|
describe 'wax:pagemaster' do
|
13
|
-
|
14
|
-
args
|
15
|
-
|
16
|
-
|
17
|
-
|
32
|
+
args = site_config['collections'].map { |c| c[0] }
|
33
|
+
args.each do |collection_name|
|
34
|
+
silence_output { WaxTasks.pagemaster(collection_name, site_config) }
|
35
|
+
end
|
36
|
+
it 'generates pages to the correct directories' do
|
37
|
+
args.each do |a|
|
38
|
+
dir = Pagemaster.target_dir(a, site_config)
|
39
|
+
pages = Dir.glob("#{dir}/*.md")
|
40
|
+
expect(pages.length).to be > 0
|
41
|
+
Fake.content(pages)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context 'when given a collection arg not in config' do
|
45
|
+
collection_name = 'not_a_collection'
|
46
|
+
it 'throws a configuration error' do
|
47
|
+
expect { silence_output { WaxTasks.pagemaster(collection_name, site_config) } }.to raise_error(SystemExit)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context 'when given config with bad source' do
|
51
|
+
collection_name = bad_src_config['collections'].first[0]
|
52
|
+
it 'throws ingest error' do
|
53
|
+
expect { silence_output { WaxTasks.pagemaster(collection_name, bad_src_config) } }.to raise_error(SystemExit)
|
54
|
+
end
|
18
55
|
end
|
19
|
-
|
20
|
-
|
56
|
+
context 'when given config with missing source' do
|
57
|
+
collection_name = missing_src_config['collections'].first[0]
|
58
|
+
it 'throws io error' do
|
59
|
+
expect { silence_output { WaxTasks.pagemaster(collection_name, missing_src_config) } }.to raise_error(SystemExit)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
context 'when trying to genrate pages that already exist' do
|
63
|
+
it 'skips them' do
|
64
|
+
expect { WaxTasks.pagemaster(args.first, site_config) }.to output(/.*Skipping.*/).to_stdout
|
65
|
+
end
|
21
66
|
end
|
22
67
|
end
|
23
68
|
|
24
69
|
describe 'wax:lunr' do
|
25
|
-
|
70
|
+
silence_output { WaxTasks.lunr(site_config) }
|
26
71
|
it 'generates a lunr index' do
|
27
|
-
index = File.open('js/lunr-index.json', 'r').read
|
28
|
-
expect(index.length > 1000
|
72
|
+
index = File.open('./js/lunr-index.json', 'r').read
|
73
|
+
expect(index.length).to be > 1000
|
29
74
|
end
|
30
|
-
|
31
75
|
it 'generates a lunr ui' do
|
32
|
-
ui = File.open('js/lunr-ui.js', 'r').read
|
33
|
-
expect(ui.length > 100
|
76
|
+
ui = File.open('./js/lunr-ui.js', 'r').read
|
77
|
+
expect(ui.length).to be > 100
|
78
|
+
end
|
79
|
+
context 'when a ui already exists' do
|
80
|
+
it 'skips over it' do
|
81
|
+
expect { WaxTasks.lunr(site_config) }.to output(/.*Skipping.*/).to_stdout
|
82
|
+
end
|
34
83
|
end
|
35
84
|
end
|
36
85
|
|
37
86
|
describe 'wax:iiif' do
|
38
|
-
|
39
|
-
|
87
|
+
collection_name = site_config['collections'].first[0]
|
88
|
+
images = Dir.glob('./_data/iiif/*.jpg')
|
89
|
+
iiif_src_dir = "./_data/iiif/#{collection_name}"
|
90
|
+
|
91
|
+
FileUtils.mkdir_p(iiif_src_dir)
|
92
|
+
images.each { |f| FileUtils.cp(File.expand_path(f), iiif_src_dir) }
|
93
|
+
silence_output { WaxTasks.iiif(collection_name, site_config) }
|
40
94
|
|
41
|
-
it 'generates
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
95
|
+
it 'generates collections' do
|
96
|
+
expect(File.exist?("./iiif/#{collection_name}/collection/top.json")).to be true
|
97
|
+
end
|
98
|
+
it 'generates manifests' do
|
99
|
+
expect(File.exist?("./iiif/#{collection_name}/1/manifest.json")).to be true
|
100
|
+
end
|
101
|
+
it 'generates derivatives' do
|
102
|
+
expect(Dir.exist?("./iiif/#{collection_name}/images")).to be true
|
103
|
+
end
|
104
|
+
it 'generates image variants' do
|
105
|
+
[250, 600, 1140].each do |size|
|
106
|
+
expect(File.exist?("./iiif/#{collection_name}/images/1-1/full/#{size},/0/default.jpg")).to be true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
context 'when looking for a missing dir' do
|
110
|
+
it 'throws an io error' do
|
111
|
+
collection_name = 'not_a_collection'
|
112
|
+
expect { silence_output { WaxTasks.iiif(collection_name, site_config) } }.to raise_error(SystemExit)
|
47
113
|
end
|
48
|
-
rm_r(images)
|
49
|
-
system("bundle exec rake wax:iiif #{args.first} > /dev/null")
|
50
|
-
args.each { |a| expect(Dir.exist?('iiif/images' + a)) }
|
51
114
|
end
|
52
115
|
end
|
53
116
|
|
54
117
|
describe 'jekyll' do
|
55
118
|
it 'builds successfully' do
|
56
|
-
Bundler.with_clean_env { system('bundle exec jekyll build
|
119
|
+
silence_output { Bundler.with_clean_env { system('bundle exec jekyll build') } }
|
57
120
|
end
|
58
121
|
end
|
59
122
|
|
60
123
|
describe 'wax:jspackage' do
|
61
|
-
|
124
|
+
before(:all) do
|
125
|
+
silence_output { system('bundle exec rake wax:jspackage') }
|
126
|
+
end
|
62
127
|
it 'writes a package.json file' do
|
63
128
|
package = File.open('package.json', 'r').read
|
64
129
|
expect(package.length > 90)
|
@@ -66,5 +131,7 @@ describe 'wax:jspackage' do
|
|
66
131
|
end
|
67
132
|
|
68
133
|
describe 'wax:test' do
|
69
|
-
it 'passes html-proofer' do
|
134
|
+
it 'passes html-proofer' do
|
135
|
+
silence_output { system('bundle exec rake wax:test') }
|
136
|
+
end
|
70
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wax_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marii Nyrop
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: wax_iiif
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.0.2
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.0.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,11 +152,11 @@ files:
|
|
152
152
|
- lib/tasks/lunr.rake
|
153
153
|
- lib/tasks/pagemaster.rake
|
154
154
|
- lib/tasks/push_gh.rake
|
155
|
-
- lib/tasks/
|
155
|
+
- lib/tasks/push_static.rake
|
156
156
|
- lib/tasks/test.rake
|
157
157
|
- lib/wax_tasks.rb
|
158
158
|
- spec/spec_helper.rb
|
159
|
-
homepage: https://github.com/
|
159
|
+
homepage: https://github.com/minicomp/wax_tasks
|
160
160
|
licenses:
|
161
161
|
- MIT
|
162
162
|
metadata: {}
|
@@ -174,7 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
- - ">="
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
|
-
requirements:
|
177
|
+
requirements:
|
178
|
+
- imagemagick
|
178
179
|
rubyforge_project:
|
179
180
|
rubygems_version: 2.7.6
|
180
181
|
signing_key:
|