wax_tasks 0.0.41 → 0.0.42
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tasks/ghbranch.rake +3 -2
- data/lib/tasks/iiif.rake +17 -12
- data/lib/tasks/jspackage.rake +5 -4
- data/lib/tasks/lunr.rake +4 -2
- data/lib/tasks/pagemaster.rake +6 -6
- data/lib/wax_tasks/collection.rb +35 -25
- data/lib/wax_tasks/helpers.rb +11 -9
- data/lib/wax_tasks/lunr.rb +13 -8
- data/lib/wax_tasks.rb +2 -4
- data/spec/spec_helper.rb +1 -7
- data/spec/test_tasks.rb +44 -0
- metadata +5 -4
- data/lib/tasks/config.rake +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d92dedaceae47d24df69b152689a3380ab9eaf71
|
4
|
+
data.tar.gz: ffd41f9e22e2945a30c921637174f8750f4dc5ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dd009a8aa640ac7afcfd64998cac60de07c74be01d127a68a709b6a7c64a225aed7a4aac48e2e58fa2d2b2e3af6df7f6d78871dbaa68fbb181a15c976e6d1cb
|
7
|
+
data.tar.gz: 61dfb031a8b480492e24302710b672028ad8220e82b83c33c3c4d7dbf5baa175791c3c21c0675341e9dd3d108ed7b055d966ea03251587d9f9ad1402148c8828
|
data/lib/tasks/ghbranch.rake
CHANGED
@@ -2,14 +2,15 @@ require 'wax_tasks'
|
|
2
2
|
|
3
3
|
namespace :wax do
|
4
4
|
desc 'build site with gh-baseurl and publish to gh-pages branch'
|
5
|
-
task :ghbranch
|
5
|
+
task :ghbranch do
|
6
|
+
config = read_config
|
6
7
|
FileUtils.rm_rf('_site')
|
7
8
|
|
8
9
|
opts = {
|
9
10
|
'source' => '.',
|
10
11
|
'destination' => '_site',
|
11
12
|
'config' => '_config.yml',
|
12
|
-
'baseurl' =>
|
13
|
+
'baseurl' => config['gh-baseurl'],
|
13
14
|
'incremental' => true,
|
14
15
|
'verbose' => true
|
15
16
|
}
|
data/lib/tasks/iiif.rake
CHANGED
@@ -2,24 +2,29 @@ require 'wax_tasks'
|
|
2
2
|
require 'iiif_s3'
|
3
3
|
|
4
4
|
namespace :wax do
|
5
|
-
task :iiif
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
task :iiif do
|
6
|
+
config = read_config
|
7
|
+
argv = read_argv
|
8
|
+
|
9
|
+
abort "You must specify a collections after 'bundle exec rake wax:iiif'.".magenta if argv.empty?
|
10
|
+
|
11
|
+
FileUtils.mkdir './iiif'
|
12
|
+
|
9
13
|
all_records = []
|
10
14
|
id_counter = 0
|
15
|
+
|
11
16
|
build_opts = {
|
12
|
-
:base_url =>
|
13
|
-
:output_dir =>
|
17
|
+
:base_url => config['baseurl'] + '/iiif',
|
18
|
+
:output_dir => './iiif',
|
14
19
|
:tile_scale_factors => [1, 2],
|
15
20
|
:verbose => true
|
16
21
|
}
|
17
|
-
|
22
|
+
argv.each do |a|
|
18
23
|
id_counter += 1
|
19
|
-
inpath = './
|
24
|
+
inpath = './_data/iiif/' + a
|
20
25
|
abort "Source path '#{inpath}' does not exist. Exiting.".magenta unless Dir.exist?(inpath)
|
21
|
-
paged =
|
22
|
-
collection_records = make_records(a, inpath, paged)
|
26
|
+
paged = config['collections'][a]['iiif_paged'] == true
|
27
|
+
collection_records = make_records(a, inpath, paged, config)
|
23
28
|
all_records.concat collection_records
|
24
29
|
end
|
25
30
|
builder = IiifS3::Builder.new(build_opts)
|
@@ -28,7 +33,7 @@ namespace :wax do
|
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
|
-
def make_records(collection_name, inpath, paged)
|
36
|
+
def make_records(collection_name, inpath, paged, config)
|
32
37
|
counter = 1
|
33
38
|
collection_records = []
|
34
39
|
imagefiles = Dir[inpath + '/*'].sort!
|
@@ -38,7 +43,7 @@ def make_records(collection_name, inpath, paged)
|
|
38
43
|
:id => collection_name + '-' + basename,
|
39
44
|
:is_document => paged,
|
40
45
|
:path => imagefile,
|
41
|
-
:label =>
|
46
|
+
:label => config['title'] + ' - ' + collection_name + ' - ' + basename
|
42
47
|
}
|
43
48
|
counter += 1
|
44
49
|
collection_records << IiifS3::ImageRecord.new(record_opts)
|
data/lib/tasks/jspackage.rake
CHANGED
@@ -3,15 +3,16 @@ require 'json'
|
|
3
3
|
|
4
4
|
namespace :wax do
|
5
5
|
desc 'write a simple package.json'
|
6
|
-
task :jspackage
|
6
|
+
task :jspackage do
|
7
|
+
config = read_config
|
7
8
|
package = {
|
8
|
-
'name' =>
|
9
|
+
'name' => config['title'],
|
9
10
|
'version' => '1.0.0',
|
10
|
-
'description' =>
|
11
|
+
'description' => config['description'],
|
11
12
|
'dependencies' => {}
|
12
13
|
}
|
13
14
|
names = []
|
14
|
-
|
15
|
+
config['js'].each do |dependency|
|
15
16
|
name = dependency[0]
|
16
17
|
names << name
|
17
18
|
version = dependency[1]['version']
|
data/lib/tasks/lunr.rake
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'wax_tasks'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
namespace :wax do
|
4
5
|
desc 'build lunr search index'
|
5
|
-
task :lunr
|
6
|
+
task :lunr do
|
7
|
+
config = read_config
|
6
8
|
Dir.mkdir('js') unless File.exist?('js')
|
7
9
|
yaml = "---\nlayout: none\n---\n"
|
8
|
-
lunr = Lunr.new(
|
10
|
+
lunr = Lunr.new(config)
|
9
11
|
|
10
12
|
# write index to json file
|
11
13
|
idx = yaml + lunr.index
|
data/lib/tasks/pagemaster.rake
CHANGED
@@ -2,15 +2,15 @@ require 'wax_tasks'
|
|
2
2
|
|
3
3
|
namespace :wax do
|
4
4
|
desc 'generate collection md pages from yaml or csv data source'
|
5
|
-
task :pagemaster
|
6
|
-
|
5
|
+
task :pagemaster do
|
6
|
+
config = read_config
|
7
|
+
argv = read_argv
|
8
|
+
if argv.empty?
|
7
9
|
puts "You must specify one or more collections after 'bundle exec rake wax:pagemaster' to generate.".magenta
|
8
10
|
exit 1
|
9
11
|
else
|
10
|
-
|
11
|
-
|
12
|
-
collections_dir = $config['collections_dir'].nil? ? '' : $config.fetch('collections_dir').to_s + '/'
|
13
|
-
collection = Collection.new(collection_name, collection_config, collections_dir)
|
12
|
+
argv.each do |name|
|
13
|
+
collection = Collection.new(config, name)
|
14
14
|
collection.pagemaster
|
15
15
|
end
|
16
16
|
end
|
data/lib/wax_tasks/collection.rb
CHANGED
@@ -1,44 +1,48 @@
|
|
1
1
|
include FileUtils
|
2
|
+
require 'csv'
|
3
|
+
require 'json'
|
2
4
|
|
3
5
|
# initializes a wax collection for use with pagemaster,lunr,and iiif tasks
|
4
6
|
class Collection
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(collection_name, collection_config, collections_dir)
|
7
|
+
def initialize(config, collection_name)
|
8
8
|
@name = collection_name
|
9
|
-
@config =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
@
|
9
|
+
@config = config
|
10
|
+
|
11
|
+
cdir = @config['collections_dir'].nil? ? '' : @config.fetch('collections_dir').to_s + '/'
|
12
|
+
collection = valid_collection_config
|
13
|
+
|
14
|
+
@src = '_data/' + collection.fetch('source')
|
15
|
+
@layout = File.basename(collection.fetch('layout'), '.*')
|
16
|
+
@dir = cdir + '_' + @name
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def valid_collection_config
|
20
|
+
c = @config['collections'][@name]
|
21
|
+
abort "Cannot find the collection #{@name} in _config.yml. Exiting.".magenta if c.nil?
|
22
|
+
abort "Cannot find 'source' for the collection '#{@name}' in _config.yml. Exiting.".magenta if c['source'].nil?
|
23
|
+
abort "Cannot find 'layout' for the collection '#{@name}' in _config.yml. Exiting.".magenta if c['layout'].nil?
|
24
|
+
abort "Cannot find the file '#{'_data/' + c['source']}'. Exiting.".magenta unless File.file?('_data/' + c['source'])
|
25
|
+
c
|
23
26
|
end
|
24
27
|
|
25
|
-
def ingest
|
26
|
-
if File.extname(
|
27
|
-
|
28
|
-
elsif File.extname(
|
29
|
-
|
28
|
+
def ingest(src)
|
29
|
+
if File.extname(src) == '.csv'
|
30
|
+
data = CSV.read(src, :headers => true, :encoding => 'utf-8').map(&:to_hash)
|
31
|
+
elsif File.extname(src) == '.json'
|
32
|
+
data = JSON.parse(File.read(@src).encode("UTF-8"))
|
30
33
|
else
|
31
34
|
puts "File type for #{@src} must be .csv or .json. Please fix and rerun."
|
32
35
|
exit 1
|
33
36
|
end
|
37
|
+
detect_duplicates(data)
|
34
38
|
puts "Processing #{src}...."
|
39
|
+
data
|
35
40
|
rescue StandardError
|
36
41
|
puts "Cannot load #{src}. check for typos and rebuild.".magenta
|
37
|
-
exit 1
|
38
42
|
end
|
39
43
|
|
40
|
-
def generate_pages
|
41
|
-
perma_ext =
|
44
|
+
def generate_pages(data)
|
45
|
+
perma_ext = @config['permalink'] == 'pretty' ? '/' : '.html'
|
42
46
|
completed = 0
|
43
47
|
skipped = 0
|
44
48
|
data.each do |item|
|
@@ -59,10 +63,16 @@ class Collection
|
|
59
63
|
abort "#{completed} pages were generated before failure, most likely a record is missing a valid 'pid' value.".magenta
|
60
64
|
end
|
61
65
|
|
62
|
-
def detect_duplicates
|
66
|
+
def detect_duplicates(data)
|
63
67
|
pids = []
|
64
|
-
|
68
|
+
data.each { |d| pids << d['pid'] }
|
65
69
|
duplicates = pids.detect { |p| pids.count(p) > 1 } || []
|
66
70
|
raise "\nYour collection has the following duplicate ids. please fix and rerun.\n#{duplicates}".magenta unless duplicates.empty?
|
67
71
|
end
|
72
|
+
|
73
|
+
def pagemaster
|
74
|
+
mkdir_p(@dir)
|
75
|
+
data = ingest(@src)
|
76
|
+
generate_pages(data)
|
77
|
+
end
|
68
78
|
end
|
data/lib/wax_tasks/helpers.rb
CHANGED
@@ -8,14 +8,6 @@ def clean(str)
|
|
8
8
|
str
|
9
9
|
end
|
10
10
|
|
11
|
-
def valid_pagemaster(collection_name)
|
12
|
-
c = $config.fetch('collections').fetch(collection_name)
|
13
|
-
abort "Cannot find 'source' for the collection '#{collection_name}' in _config.yml. Exiting.".magenta if c.fetch('source').nil?
|
14
|
-
abort "Cannot find 'layout' for the collection '#{collection_name}' in _config.yml. Exiting.".magenta if c.fetch('layout').nil?
|
15
|
-
abort "Cannot find the file '#{'_data/' + c['source']}'. Exiting.".magenta unless File.file?('_data/' + c.fetch('source'))
|
16
|
-
c
|
17
|
-
end
|
18
|
-
|
19
11
|
def rm_diacritics(str)
|
20
12
|
to_replace = "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž"
|
21
13
|
replaced_by = "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz"
|
@@ -27,6 +19,16 @@ def slug(str)
|
|
27
19
|
end
|
28
20
|
|
29
21
|
def thing2string(thing)
|
30
|
-
thing = thing.join(" ") if thing.is_a?(Array)
|
22
|
+
thing = thing.join(" || ") if thing.is_a?(Array)
|
31
23
|
thing.to_s
|
32
24
|
end
|
25
|
+
|
26
|
+
def read_config
|
27
|
+
YAML.load_file('_config.yml')
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_argv
|
31
|
+
argv = ARGV.drop(1)
|
32
|
+
argv.each { |a| task a.to_sym }
|
33
|
+
argv
|
34
|
+
end
|
data/lib/wax_tasks/lunr.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
include FileUtils
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
# for generating Lunr Index and Lunr UI files
|
4
5
|
class Lunr
|
@@ -22,6 +23,17 @@ class Lunr
|
|
22
23
|
total_fields.uniq
|
23
24
|
end
|
24
25
|
|
26
|
+
def page_hash(page, c_fields, c, count)
|
27
|
+
yaml = YAML.load_file(page)
|
28
|
+
hash = {
|
29
|
+
'lunr_id' => count,
|
30
|
+
'link' => "{{'" + yaml.fetch('permalink') + "' | relative_url }}"
|
31
|
+
}
|
32
|
+
c_fields.each { |f| hash[f] = rm_diacritics(thing2string(yaml[f])) }
|
33
|
+
hash['content'] = rm_diacritics(clean(File.read(page))) if c[1]['lunr_index']['content']
|
34
|
+
hash
|
35
|
+
end
|
36
|
+
|
25
37
|
def index
|
26
38
|
full_index = []
|
27
39
|
count = 0
|
@@ -38,15 +50,8 @@ class Lunr
|
|
38
50
|
puts "Loading #{c_pages.length} pages from #{c_dir}"
|
39
51
|
# index each page in collection
|
40
52
|
c_pages.each do |page|
|
41
|
-
|
42
|
-
hash = {
|
43
|
-
'lunr_id' => count,
|
44
|
-
'link' => "{{'" + yaml.fetch('permalink') + "' | relative_url }}"
|
45
|
-
}
|
46
|
-
c_fields.each { |f| hash[f] = rm_diacritics(thing2string(yaml[f])) }
|
47
|
-
hash['content'] = rm_diacritics(clean(File.read(page))) if c[1]['lunr_index']['content']
|
53
|
+
full_index << page_hash(page, c_fields, c, count)
|
48
54
|
count += 1
|
49
|
-
full_index << hash
|
50
55
|
end
|
51
56
|
end
|
52
57
|
JSON.pretty_generate(full_index)
|
data/lib/wax_tasks.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/test_tasks.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'fake/helpers'
|
4
|
+
require 'fake/site'
|
5
|
+
require 'fake/data'
|
6
|
+
|
7
|
+
# run + test wax:config
|
8
|
+
describe 'wax_tasks' do
|
9
|
+
Fake.site
|
10
|
+
collection_data = Fake.data
|
11
|
+
config = YAML.load_file('_config.yml')
|
12
|
+
argv = collection_data.map { |col| col[0] }
|
13
|
+
add_collections_to_config(argv, collection_data, config)
|
14
|
+
add_lunr_data(config, collection_data)
|
15
|
+
|
16
|
+
it 'accesses _config.yml and argv' do
|
17
|
+
expect(config.length)
|
18
|
+
expect(argv.length)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'generates pages' do
|
22
|
+
system("bundle exec rake wax:pagemaster #{argv.join(' ')}")
|
23
|
+
argv.each { |a| expect(Dir.exist?('_' + a)) }
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'generates a lunr index' do
|
27
|
+
system("bundle exec rake wax:lunr")
|
28
|
+
index = File.open('js/lunr-index.json', 'r').read
|
29
|
+
ui = File.open('js/lunr-ui.js', 'r').read
|
30
|
+
expect(index.length > 1000)
|
31
|
+
expect(ui.length > 100)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'generates iiif tiles and data' do
|
35
|
+
images = Dir.glob('./_data/iiif/*.jpg')
|
36
|
+
collection_data.each do |coll|
|
37
|
+
new_dir = './_data/iiif/' + coll[0]
|
38
|
+
mkdir_p(new_dir)
|
39
|
+
images.each { |f| cp(File.expand_path(f), new_dir) }
|
40
|
+
end
|
41
|
+
rm_r(images)
|
42
|
+
system("bundle exec rake wax:iiif #{argv.first}")
|
43
|
+
end
|
44
|
+
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.0.42
|
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-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -144,7 +144,6 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- Gemfile
|
147
|
-
- lib/tasks/config.rake
|
148
147
|
- lib/tasks/ghbranch.rake
|
149
148
|
- lib/tasks/iiif.rake
|
150
149
|
- lib/tasks/jspackage.rake
|
@@ -157,6 +156,7 @@ files:
|
|
157
156
|
- lib/wax_tasks/helpers.rb
|
158
157
|
- lib/wax_tasks/lunr.rb
|
159
158
|
- spec/spec_helper.rb
|
159
|
+
- spec/test_tasks.rb
|
160
160
|
homepage: https://github.com/mnyrop/wax_tasks
|
161
161
|
licenses:
|
162
162
|
- MIT
|
@@ -177,9 +177,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.6.
|
180
|
+
rubygems_version: 2.6.14
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Rake tasks for minimal exhibitions.
|
184
184
|
test_files:
|
185
185
|
- spec/spec_helper.rb
|
186
|
+
- spec/test_tasks.rb
|
data/lib/tasks/config.rake
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'wax_tasks'
|
2
|
-
|
3
|
-
namespace :wax do
|
4
|
-
desc 'get _config.yaml and parse cmd line args'
|
5
|
-
task :config do
|
6
|
-
begin
|
7
|
-
$config = YAML.load_file('_config.yml')
|
8
|
-
$argv = ARGV.drop(1)
|
9
|
-
$argv.each { |a| task a.to_sym }
|
10
|
-
rescue StandardError
|
11
|
-
abort 'Cannot load _config.yml'.magenta
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|