wax_tasks 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f3ee5c37e9bdd609505415066d2e024f0ae2c98
4
+ data.tar.gz: c0f9c31e128a27ba5e474df8987c9105317a1a98
5
+ SHA512:
6
+ metadata.gz: b57d647c1cbc1851d67bf5c1e5bd267a7feb3224d906dbfd8b59ac9e73f4a91645542051447d74e5e31157a0cdcf6d6e665ea1ab715b13ca6a9da993d5d09ecc
7
+ data.tar.gz: 65574cf6e3366c037df690884f06b8f2944d1241998c180c46f11964b58af8bd5417da3a0de5ee23b06c629f40539da128057062cb419dfcc34a556bf133cb28
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # wax_tasks [![Gem Version](https://badge.fury.io/rb/wax_tasks.svg)](https://badge.fury.io/rb/wax_tasks) [![Dependency Status](https://gemnasium.com/badges/github.com/mnyrop/wax_tasks.svg)](https://gemnasium.com/github.com/mnyrop/wax_tasks)
2
+
3
+ ## [minicomp](https://github.com/minicomp) rake tasks for jekyll [wax](https://minicomp.github.io/wax)
4
+
5
+ ### current tasks:
6
+
7
+ `wax:pagemaster`: generates markdown pages for jekyll collections from csv or yaml files. (same as [`pagemaster`](https://github.com/mnyrop/pagemaster) gem).
8
+
9
+ `wax:iiif`: generates iiif image tiles and associated json for jekyll collections from local jpgs. (uses [`iiif_s3`](https://github.com/cmoa/iiif_s3) gem).
10
+
11
+ `wax:ghbranch`: builds your jekyll site and overwrites the `gh-pages` branch to publish your compiled `_site` directory with `gh-baseurl`.
12
+
13
+ `wax:s3branch`: builds your jekyll site and overwrites the `s3` branch to publish your compiled `_site` directory with `baseurl`.
14
+
15
+ `wax:lunr` builds a Lunrjs search index for your site.
16
+
17
+ `wax:test` runs htmlproofer and, if there is an .rspec file, runs your rspec tests.
18
+
19
+
20
+ ### set-up:
21
+ 1. add the `wax_tasks` gem to your jekyll site's `Gemfile` and install with `bundle install`:
22
+ ```
23
+ gem 'wax_tasks'
24
+ ```
25
+ 2. Create a `Rakefile` in the root of your jekyll site and add the following to load the wax_tasks:
26
+ ```
27
+ spec = Gem::Specification.find_by_name 'wax_tasks'
28
+ Dir.glob("#{spec.gem_dir}/lib/tasks/*.rake").each {|r| load r}
29
+ ```
30
+ 3. Configure the collection information in your site's `_config.yaml`.
31
+ ```yaml
32
+ # Collection params for wax:pagemaster
33
+ collections:
34
+ paintings:
35
+ output: true
36
+ source: paintings-metadata.csv
37
+ directory: paintings
38
+ layout: painting-page
39
+ artists:
40
+ output: true
41
+ source: artist-data.yaml
42
+ directory: artists
43
+ layout: author-info-page
44
+ ```
45
+ 4. If generating a Lunrjs search index, add Lunr Params to `_config.yaml`.
46
+ ```bash
47
+ # Lunr Search Params (for wax:lunr)
48
+ lunr:
49
+ content: true
50
+ multi-language: true
51
+ meta:
52
+ - dir: "_projects"
53
+ permalink: "/projects"
54
+ fields:
55
+ - title
56
+ - era
57
+ - tags
58
+ - dir: "_posts"
59
+ permalink: "posts"
60
+ fields:
61
+ - title
62
+ - category
63
+ - tags
64
+ ```
65
+ ### to use:
66
+ ```bash
67
+ $ bundle exec rake wax:<task_name> <option>
68
+ ```
69
+ #### ex 1: generate md pages for `paintings` and `artists` from data files
70
+ ```bash
71
+ $ bundle exec rake wax:pagemaster paintings artists
72
+ ```
73
+ #### ex 2: generate iiif image tiles and associated json for `paintings` from local jpgs:
74
+ ```bash
75
+ $ bundle exec rake wax:iiif paintings
76
+ ```
77
+ #### ex 3: publish `_site` to `gh-pages` branch
78
+ ```bash
79
+ $ bundle exec rake wax:ghbranch
80
+ ```
81
+ #### ex 4: publish `_site` to `s3` branch
82
+ ```bash
83
+ $ bundle exec rake wax:s3branch
84
+ ```
85
+ #### ex 5: (re)generate lunrjs search index
86
+ ```bash
87
+ $ bundle exec rake wax:lunr
88
+ ```
89
+ #### ex 6: run CI test(s)
90
+ ```bash
91
+ $ bundle exec rake wax:test
92
+ ```
@@ -0,0 +1,16 @@
1
+ require 'yaml'
2
+ require 'colorized_string'
3
+
4
+ namespace :wax do
5
+ desc 'get _config.yaml and parse cmd line args'
6
+ task :config do
7
+ begin
8
+ $config = YAML.load_file('_config.yml')
9
+ $argv = ARGV.drop(1)
10
+ $argv.each { |a| task a.to_sym do ; end }
11
+ rescue
12
+ puts "Cannot load _config.yml".magenta
13
+ exit 1
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require 'jekyll'
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+ require 'colorized_string'
5
+
6
+ namespace :wax do
7
+ desc 'build site with gh-baseurl and publish to gh-pages branch'
8
+ task :ghbranch => :config do
9
+ FileUtils.rm_rf('_site')
10
+
11
+ baseurl = $config['gh-baseurl']
12
+
13
+ Jekyll::Site.new(Jekyll.configuration({
14
+ "source" => ".",
15
+ "destination" => "_site",
16
+ "config" => "_config.yml",
17
+ "baseurl" => baseurl,
18
+ "incremental" => true,
19
+ "verbose" => true
20
+ })).process
21
+
22
+ origin = `git config --get remote.origin.url`
23
+
24
+ Dir.mktmpdir do |tmp|
25
+ cp_r "_site/.", tmp
26
+ Dir.chdir tmp
27
+
28
+ system "git init" # Init the repo.
29
+ system "git add . && git commit -m 'Site updated at #{Time.now.utc}'"
30
+ system "git remote add origin #{origin}"
31
+ system "git push origin master:refs/heads/gh-pages --force"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,52 @@
1
+ require 'colorized_string'
2
+ require 'iiif_s3'
3
+
4
+ namespace :wax do
5
+ task :iiif => :config do
6
+
7
+ FileUtils::mkdir_p 'tiles'
8
+ imagedata = []
9
+ id_counter = 0
10
+
11
+ if $argv.empty?
12
+ puts "You must specify one or more collections after 'bundle exec rake wax:iiif' to generate.".magenta
13
+ exit 1
14
+ else
15
+ $argv.each do |a|
16
+ dirpath = './_iiif/' + a
17
+ unless Dir.exist?(dirpath)
18
+ puts ("Source path '" + dirpath + "' does not exist. Exiting.").magenta
19
+ exit 1
20
+ else
21
+ id_counter+=1
22
+ imagefiles = Dir[dirpath + "/*"].sort!
23
+ counter = 1
24
+ imagefiles.each do |imagefile|
25
+ begin
26
+ basename = File.basename(imagefile, ".*")
27
+ opts = {}
28
+ opts[:id] = basename
29
+ opts[:is_document] = false
30
+ opts[:path] = imagefile
31
+ opts[:label] = $config["title"] + " - " + a + " - " + basename
32
+ i = IiifS3::ImageRecord.new(opts)
33
+ counter = counter + 1
34
+ imagedata.push(i)
35
+ rescue
36
+ puts ("Failed to convert image " + imagefile + ".").magenta
37
+ exit 1
38
+ end
39
+ end
40
+ end
41
+ end
42
+ builder = IiifS3::Builder.new({
43
+ :base_url => $config["baseurl"] + "/tiles",
44
+ :output_dir => "./tiles",
45
+ :tile_scale_factors => [1,2],
46
+ :verbose => true
47
+ })
48
+ builder.load(imagedata)
49
+ builder.process_data()
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,79 @@
1
+ require 'json'
2
+ require 'yaml'
3
+ require 'colorized_string'
4
+
5
+ namespace :wax do
6
+ desc 'build lunr search index'
7
+ task :lunr => :config do
8
+
9
+ meta = $config['lunr']['meta']
10
+ name = $config['lunr']['name'].to_s
11
+ total_fields = []
12
+ count = 0
13
+
14
+ front_matter = "---\nlayout: null\n---"
15
+ store_string = "\nvar store = ["
16
+ index_string = "\nvar index = new elasticlunr.Index;\nindex.setRef('lunr_id');\nindex.saveDocument(false);"
17
+ if $config['lunr']['multi-language'].to_s == 'true'
18
+ index_string += "\nindex.pipeline.remove(elasticlunr.trimmer);" # remove elasticlunr.trimmer if multilanguage is true
19
+ end
20
+
21
+ if meta.to_s.empty?
22
+ puts "Lunr index parameters are not properly cofigured.".magenta
23
+ exit 1
24
+ else
25
+ meta.each { |group| total_fields += group['fields'] }
26
+ if total_fields.uniq.empty?
27
+ puts "Fields are not properly configured.".magenta
28
+ exit 1
29
+ else
30
+ total_fields.uniq.each do |f|
31
+ index_string += "\nindex.addField(" + "'" + f + "'" + "); "
32
+ end
33
+
34
+ meta.each do |collection|
35
+
36
+ dir = collection['dir']
37
+ perma = collection['permalink']
38
+ fields = collection['fields']
39
+
40
+ puts ("Loading pages from " + dir).cyan
41
+
42
+ Dir.glob(dir+"/*").each do |md|
43
+ begin
44
+ yaml = YAML.load_file(md)
45
+ hash = Hash.new
46
+ hash['lunr_id'] = count
47
+ hash['link'] = "{{ site.baseurl }}" + yaml['permalink']
48
+ fields.each { |f| hash[f] = clean(yaml[f].to_s) }
49
+ if $config['lunr']['content']
50
+ hash['content'] = clean(File.read(md))
51
+ end
52
+ index_string += "\nindex.addDoc(" + hash.to_json + "); "
53
+ store_string += "\n" + hash.to_json + ", "
54
+ count += 1
55
+ rescue
56
+ puts ("Cannot load data from markdown pages in " + dir + ".").magenta
57
+ exit 1
58
+ end
59
+ end
60
+ end
61
+
62
+ store_string = store_string.chomp(", ") + "];"
63
+
64
+ Dir.mkdir('js') unless File.exists?('js')
65
+ File.open("js/lunr-index.js", 'w') { |file| file.write( front_matter + index_string + store_string ) }
66
+ puts ("Writing lunr index to " + "js/lunr-index.js").green
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def clean(str)
73
+ str = str.gsub(/\A---(.|\n)*?---/, "") # remove yaml front matter
74
+ str = str.gsub(/{%(.*)%}/, "") # remove functional liquid
75
+ str = str.gsub(/<\/?[^>]*>/, "") # remove html
76
+ str = str.gsub("\\n", "").gsub(/\s+/, ' ') # remove newlines and extra space
77
+ str = str.gsub('"',"'").to_s # replace double quotes with single
78
+ return str
79
+ end
@@ -0,0 +1,81 @@
1
+ require 'yaml'
2
+ require 'csv'
3
+
4
+ namespace :wax do
5
+ desc 'generate collection md pages from yaml or csv data source'
6
+ task :pagemaster => :config do
7
+
8
+ collections = $config['collections']
9
+ if $argv.empty?
10
+ puts "You must specify one or more collections after 'bundle exec rake wax:pagemaster' to generate.".magenta
11
+ exit 1
12
+ else
13
+ $argv.each do |a|
14
+ collection = collections[a]
15
+ if collection.nil?
16
+ puts ("The collection '" + a + "' does not exist. Check for typos in terminal and _config.yml.").magenta
17
+ exit 1
18
+ else
19
+
20
+ meta = Hash.new
21
+ meta['src'] = '_data/' + File.basename( collection['source'], ".*" ) + ".csv"
22
+ meta['layout'] = File.basename( collection['layout'], ".*" )
23
+ meta['dir'] = collection['directory']
24
+
25
+ $skipped, $completed = 0,0
26
+
27
+ unless [ meta['src'], meta['dir'], meta['layout'] ].all?
28
+ puts ("Your collection " + a +" is missing one or more of the required parameters (source, directory, layout) in config. please fix and rerun.").magenta
29
+ exit 1
30
+ else
31
+ FileUtils::mkdir_p meta['dir']
32
+ data = ingest(meta['src'])
33
+ generate_pages(meta, data)
34
+ puts ("\n" + $completed.to_s + " pages were generated to " + meta['dir'] + " directory.").green
35
+ puts ($skipped.to_s + " pre-existing items were skipped.").green
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def ingest(src)
44
+ begin
45
+ data = CSV.read(src, :headers => true, :encoding => 'utf-8')
46
+ duplicates = data['pid'].detect{ |i| data.count(i) > 1 }.to_s
47
+ unless duplicates.empty?
48
+ puts ("Your collection has the following duplicate ids. please fix and rerun.\n").magenta + duplicates +"\n"
49
+ exit 1
50
+ end
51
+ puts ("\nProcessing " + src + "....\n").cyan
52
+ return data.map(&:to_hash)
53
+ rescue
54
+ puts ("Cannot load " + src + ". check for typos and rebuild.").magenta
55
+ exit 1
56
+ end
57
+ end
58
+
59
+ def generate_pages(meta, data)
60
+ if $config['permalink'] == 'pretty'
61
+ perma_ext = "/"
62
+ else
63
+ perma_ext = ".html"
64
+ end
65
+ data.each do |item|
66
+ begin
67
+ pagename = item['pid']
68
+ pagepath = meta['dir'] + "/" + pagename + ".md"
69
+ if !File.exist?(pagepath)
70
+ File.open(pagepath, 'w') { |file| file.write( item.to_yaml.to_s + "permalink: /" + meta['dir'] + "/" + pagename + perma_ext + "\n" + "layout: " + meta['layout'] + "\n---" ) }
71
+ $completed+=1
72
+ else
73
+ puts pagename + ".md already exits. Skipping."
74
+ $skipped+=1
75
+ end
76
+ rescue
77
+ puts ($completed.to_s + " pages were generated before failure, most likely a record is missing a valid 'pid' value.").magenta
78
+ exit 1
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,33 @@
1
+ require 'jekyll'
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+ require 'iiif_s3'
5
+
6
+ namespace :wax do
7
+ desc 'build site with baseurl and publish to s3 branch'
8
+ task :s3branch => :config do
9
+ FileUtils.rm_rf('_site')
10
+ baseurl = $config['baseurl']
11
+
12
+ Jekyll::Site.new(Jekyll.configuration({
13
+ "source" => ".",
14
+ "destination" => "_site",
15
+ "config" => "_config.yml",
16
+ "incremental" => true,
17
+ "verbose" => true,
18
+ "baseurl" => baseurl
19
+ })).process
20
+
21
+ origin = `git config --get remote.origin.url`
22
+
23
+ Dir.mktmpdir do |tmp|
24
+ cp_r "_site/.", tmp
25
+ Dir.chdir tmp
26
+
27
+ system "git init" # Init the repo.
28
+ system "git add . && git commit -m 'Site updated at #{Time.now.utc}'"
29
+ system "git remote add origin #{origin}"
30
+ system "git push origin master:refs/heads/s3 --force"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'html-proofer'
2
+ require 'iiif_s3'
3
+
4
+ namespace :wax do
5
+ desc 'run htmlproofer, rspec if exists'
6
+ task :test do
7
+ options = {
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
+ }
16
+ begin
17
+ HTMLProofer.check_directory("./_site", options).run
18
+ rescue => msg
19
+ puts "#{msg}"
20
+ end
21
+ if File.exist?('.rspec')
22
+ sh 'bundle exec rspec'
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wax_tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marii Nyröp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: html-proofer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: iiif_s3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ description: 'Rake tasks for minimal exhibition sites with Jekyll. See: minicomp/wax.'
70
+ email:
71
+ - m.nyrop@columbia.edu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - README.md
77
+ - lib/tasks/config.rake
78
+ - lib/tasks/ghbranch.rake
79
+ - lib/tasks/iiif.rake
80
+ - lib/tasks/lunr.rake
81
+ - lib/tasks/pagemaster.rake
82
+ - lib/tasks/s3branch.rake
83
+ - lib/tasks/test.rake
84
+ homepage: https://github.com/mnyrop/wax_tasks
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.6.9
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Rake tasks for minimal exhibitions.
108
+ test_files: []