wax_tasks 1.0.2 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54e1d62bddb18ee554db5a1d517f65acc68998edce0a147d0f08d1c6807a3655
4
- data.tar.gz: 52437257c9777aaaefd078c4e4be8ad76ccf82fd2e57d0d8ef022912a789cf4c
3
+ metadata.gz: 8fd8340a2ecff9fe1d3fa57fa2bbd0d70dfbf33584131d2056a8805ee36e1902
4
+ data.tar.gz: db4172c4bbd872c5f07e042149137eb321d0b3dd7862819a2cdb4e758c5ae87c
5
5
  SHA512:
6
- metadata.gz: b2479c1ed3f348c749f78f6a2988f5aa5f98041bb09821bf17c51cee5bd761f542c2560532516567595d956e220f94ffcef0aadf60c2cf0df9e6559eff82a682
7
- data.tar.gz: cf0ba69cf4e2ab6b224bc55e9b532522ba766379f448330839d22a3e13fcbe0235df9f8a94fc9d3664350c56459de4b9491248fdaa97a8255010d63a08314f9a
6
+ metadata.gz: 7f001ba8520a410f2601eb6386fd2fca430af7f8feea875497e589454472822a6ceecb8bf41711be8cdff89b45a63f82393da7354a98bd8e0a4392515de4ae65
7
+ data.tar.gz: abbec63cdc47318a45b9dc3eb74d9341f39f3aac2ba807879bb9008467f1f78c9b4033e2ec344367b54e88d1434717456a71f59fb181d16ac35a5e779f7a7b99
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+
5
+ ---
6
+
7
+ **Describe the bug**
8
+ A clear and concise description of what the bug is.
9
+
10
+ **To Reproduce**
11
+ Steps to reproduce the behavior:
12
+ 1. Go to '...'
13
+ 2. Click on '....'
14
+ 3. Scroll down to '....'
15
+ 4. See error
16
+
17
+ **Expected behavior**
18
+ A clear and concise description of what you expected to happen.
19
+
20
+ **Screenshots**
21
+ If applicable, add screenshots to help explain your problem.
22
+
23
+ **Desktop (please complete the following information):**
24
+ - OS: [e.g. iOS]
25
+ - Browser [e.g. chrome, safari]
26
+ - Version [e.g. 22]
27
+
28
+ **Smartphone (please complete the following information):**
29
+ - Device: [e.g. iPhone6]
30
+ - OS: [e.g. iOS8.1]
31
+ - Browser [e.g. stock browser, safari]
32
+ - Version [e.g. 22]
33
+
34
+ **Additional context**
35
+ Add any other context about the problem here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+
5
+ ---
6
+
7
+ **Is your feature request related to a problem? Please describe.**
8
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9
+
10
+ **Describe the solution you'd like**
11
+ A clear and concise description of what you want to happen.
12
+
13
+ **Describe alternatives you've considered**
14
+ A clear and concise description of any alternative solutions or features you've considered.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,30 @@
1
+ name: ci:test
2
+ on:
3
+ pull_request:
4
+ paths-ignore:
5
+ - '**/README.md'
6
+ push:
7
+ paths-ignore:
8
+ - '**/README.md'
9
+
10
+ jobs:
11
+ rspec:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: change imagemagick policy to allow pdf->png conversion.
15
+ run: |
16
+ sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
17
+ - name: install ghostscript
18
+ run: sudo apt-get update && sudo apt-get install -y ghostscript
19
+ - uses: actions/checkout@v2
20
+ with:
21
+ fetch-depth: 1
22
+ - uses: ruby/setup-ruby@v1
23
+ with:
24
+ bundler-cache: true
25
+ - name: install
26
+ run: gem install bundler && bundle
27
+ - name: check for outdated gems
28
+ run: bundle outdated
29
+ - name: test
30
+ run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ Gemfile.lock
3
+ coverage
4
+ test_build
5
+ doc
6
+ .yardoc
7
+ DIANE
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.7
4
+ Exclude: ['spec/**/*', 'test_build/**/*']
5
+ Layout/LineLength:
6
+ IgnoredPatterns: ['raise', 'puts', 'set', 'warn', 'ÈÉÊË', 'EEEE', 'safe_join', 'spec']
7
+ Metrics/AbcSize:
8
+ Max: 28
9
+ Metrics/MethodLength:
10
+ Max: 15
11
+ Layout/EmptyComment:
12
+ Enabled: false
13
+ Layout/EmptyLineAfterGuardClause:
14
+ Enabled: false
15
+ Style/SingleArgumentDig:
16
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  # dev/test utilities
7
+ gem 'bundle-audit', require: false
8
+ gem 'diane', require: false
7
9
  gem 'rubocop', require: false
8
10
  gem 'simplecov', require: false
9
11
  gem 'yard', require: false
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 marii nyrop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # wax_tasks 🐝
2
+ [![ci:test](https://github.com/minicomp/wax_tasks/actions/workflows/ci.yml/badge.svg)](https://github.com/minicomp/wax_tasks/actions/workflows/ci.yml) [![Depfu](https://badges.depfu.com/badges/6105c55b9634e74b1c27055b19bad8f0/overview.svg)](https://depfu.com/github/minicomp/wax_tasks?project_id=10548)
3
+ [![Gem Version](https://badge.fury.io/rb/wax_tasks.svg)](https://badge.fury.io/rb/wax_tasks)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/wax_tasks.svg?color=046d0b)](https://badge.fury.io/rb/wax_tasks)
5
+ [![docs](http://img.shields.io/badge/docs-rdoc.info-blue.svg?style=flat)](https://www.rubydoc.info/github/minicomp/wax_tasks/)
6
+
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/14408e7e962b9b84ec65/maintainability)](https://codeclimate.com/github/minicomp/wax_tasks/maintainability)
8
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/14408e7e962b9b84ec65/test_coverage)](https://codeclimate.com/github/minicomp/wax_tasks/test_coverage)
9
+ ![License](https://img.shields.io/github/license/minicomp/wax_tasks.svg?color=c6a1e0)
10
+
11
+ __wax_tasks__ is gem-packaged set of [Rake](https://ruby.github.io/rake/) tasks for creating minimal exhibition sites with [Wax](https://github.com/minicomp/wax/).
12
+
13
+ It can be used to:
14
+ - generate collection markdown pages from a metadata file ([wax:pages](#waxpages))
15
+ - generate a client-side search index ([wax:search](#waxsearch))
16
+ - generate either IIIF-compliant derivatives ([wax:derivatives:iiif](#waxderivativesiiif)) or simple image derivatives ([wax:derivatives:simple](#waxderivativessimple)) from local image and pdf files
17
+
18
+ <br>
19
+ <img src="https://raw.githubusercontent.com/minicomp/wiki/main/src/assets/wax_screen.gif?raw=true?raw=true"/>
20
+
21
+
22
+ # Getting Started
23
+
24
+ ## Prerequisites
25
+
26
+ You'll need `Ruby >= 2.4` with `bundler` installed. Check your versions with:
27
+ ```bash
28
+ $ ruby -v
29
+ ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin18]
30
+
31
+ $ bundler -v
32
+ Bundler version 1.16.1
33
+ ```
34
+
35
+ To use the image derivative tasks, you will also need to have ImageMagick and Ghostscript installed and functional. You can check to see if you have ImageMagick by running:
36
+ ```bash
37
+ $ convert -version
38
+ Version: ImageMagick 6.9.9-20 Q16 x86_64 2017-10-15 http://www.imagemagick.org
39
+ Copyright: (c) 1999-2017 ImageMagick Studio LLC
40
+ License: http://www.imagemagick.org/script/license.php
41
+ Features: Cipher DPC Modules
42
+ Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib
43
+ ```
44
+
45
+ ... and check Ghostscript with:
46
+ ```bash
47
+ $ gs -version
48
+ GPL Ghostscript 9.21 (2017-03-16)
49
+ Copyright (C) 2017 Artifex Software, Inc. All rights reserved.
50
+ ```
51
+
52
+ Next, you'll need a Jekyll site. You can clone the [minicomp/wax demo site](https://github.com/minicomp/wax/) or start a site from scratch with:
53
+
54
+ ```sh
55
+ $ gem install jekyll
56
+ $ jekyll new wax && cd wax
57
+ ```
58
+
59
+ ## Installation
60
+
61
+ Add `wax_tasks` to your Jekyll site's `Gemfile`:
62
+
63
+ ```ruby
64
+ gem 'wax_tasks'
65
+ ```
66
+
67
+ ... and install with bundler:
68
+
69
+ ```bash
70
+ $ bundle install
71
+ ```
72
+
73
+ Create a `Rakefile` with the following:
74
+ ```ruby
75
+ spec = Gem::Specification.find_by_name 'wax_tasks'
76
+ Dir.glob("#{spec.gem_dir}/lib/tasks/*.rake").each { |r| load r }
77
+ ```
78
+
79
+ # Usage
80
+
81
+ After following the installation instructions above, you will have access to the Rake tasks in your shell by running `$ bundle exec rake wax:taskname` in the root directory of your Jekyll site.
82
+ To see the available tasks, run
83
+
84
+ ```ruby
85
+ $ bundle exec rake --tasks
86
+ ```
87
+
88
+ ## Sample site `_config.yml` file:
89
+
90
+ ```yaml
91
+ # basic settings
92
+ title: Wax.
93
+ description: a jekyll theme for minimal exhibitions
94
+ url: 'https://minicomp.github.io'
95
+ baseurl: '/wax'
96
+
97
+ # build settings
98
+ permalink: pretty # optional, creates `/page/` link instead of `page.html` links
99
+
100
+ # wax collection settings
101
+ collections:
102
+ objects: # the collection name
103
+ layout: 'iiif-image-page'
104
+ output: true # this must be true for your .md pages to be built to html!
105
+ metadata:
106
+ source: 'objects.csv' # path to the metadata file, must be within '_data'
107
+ images:
108
+ source 'source_images/objects' # path to the directory of source images, must be within '_data'
109
+
110
+ # wax search index settings
111
+ search:
112
+ main:
113
+ index: 'js/lunr-index.json' # where the index will be generated
114
+ collections: # the collections to index
115
+ objects:
116
+ content: false # whether or not to index the markdown page content (below the YAML)
117
+ fields: # the metadata fields to index
118
+ - 'label'
119
+ - 'artist'
120
+ - 'location'
121
+ - 'object_type'
122
+ ```
123
+
124
+ The above example includes a single collection `objects` that comprises:
125
+ 1. a CSV `metadata:source` file (`objects.csv`), and
126
+ 2. a `images:source` directory of image and pdf files.
127
+
128
+ For more information on configuring Jekyll collections for __wax_tasks__, check out the [minicomp/wax wiki](https://minicomp.github.io/wiki/#/wax/) and <https://jekyllrb.com/docs/collections/>.
129
+
130
+ ## Running the tasks
131
+
132
+ ### wax:pages
133
+
134
+ Takes a CSV, JSON, or YAML file of collection metadata and generates a [markdown](https://daringfireball.net/projects/markdown/syntax) page for each record to a directory using a specified layout. [Read More](#TODO).
135
+
136
+ `$ bundle exec rake wax:pages collection-name`
137
+
138
+ ### wax:search
139
+
140
+ Generates a client-side JSON search index of your site for use with [ElasticLunr.js](http://elasticlunr.com/). [Read More](#TODO).
141
+
142
+ `$ bundle exec rake wax:search search-name`
143
+
144
+
145
+ ### wax:derivatives:simple
146
+
147
+ Takes a local directory of images and pdf files and generates a few image derivatives (i.e., 'thumbnail' 250w and 'full' 1140w) for Jekyll layouts and includes to use. [Read More](#TODO).
148
+
149
+ `$ bundle exec rake wax:derivatives:iiif collection-name`
150
+
151
+ ### wax:derivatives:iiif
152
+
153
+ Takes a local directory of images and pdf files and generates tiles and data that work with a IIIF compliant image viewer like [OpenSeaDragon](https://openseadragon.github.io/), [Mirador](http://projectmirador.org/), or [Leaflet IIIF](https://github.com/mejackreed/Leaflet-IIIF). [Read More](#TODO).
154
+
155
+ `$ bundle exec rake wax:derivatives:iiif collection-name`
156
+
157
+ ### wax:clobber
158
+
159
+ Destroys (or "clobbers") wax-generated files, i.e., pages generated from `wax:pagemaster`, derivatives generated from `wax:derivatives`, and search indexes generated with `wax:search` so you can start from scratch.
160
+
161
+ This task does *not* touch your source metadata or source image files! Instead, it simply clears a path for you to regenerate your collection materials in case you add/edit source materials.
162
+
163
+ `$ bundle exec rake wax:clobber collection-name`
164
+
165
+ # Contributing
166
+
167
+ Fork/clone the repository. After making code changes, run the tests (`$ bundle exec rubocop` and `$ bundle exec rspec`) before submitting a pull request. You can enable verbose tests with `$ DEBUG=true bundle exec rspec`.
168
+
169
+ # License
170
+
171
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'wax_tasks'
4
+
5
+ namespace :wax do
6
+ desc 'destroy wax-generated collection files, including pages, derivatives, and search index(es)'
7
+ task :clobber do
8
+ args = ARGV.drop(1).each { |a| task a.to_sym }
9
+ args.reject! { |a| a.start_with? '-' }
10
+
11
+ raise WaxTasks::Error::MissingArguments, Rainbow("You must specify a collection after 'wax:clobber'").magenta if args.empty?
12
+
13
+ site = WaxTasks::Site.new
14
+ args.each { |a| site.clobber a }
15
+ end
16
+ end
@@ -7,6 +7,8 @@ namespace :wax do
7
7
  desc 'generate iiif derivatives from local image files'
8
8
  task :iiif do
9
9
  args = ARGV.drop(1).each { |a| task a.to_sym }
10
+ args.reject! { |a| a.start_with? '-' }
11
+
10
12
  raise WaxTasks::Error::MissingArguments, Rainbow("You must specify a collection after 'wax:derivatives:iiif'").magenta if args.empty?
11
13
 
12
14
  site = WaxTasks::Site.new
@@ -4,9 +4,10 @@ require 'wax_tasks'
4
4
 
5
5
  namespace :wax do
6
6
  namespace :derivatives do
7
- desc 'generate iiif derivatives from local image files'
7
+ desc 'generate simple derivatives from local image files'
8
8
  task :simple do
9
9
  args = ARGV.drop(1).each { |a| task a.to_sym }
10
+ args.reject! { |a| a.start_with? '-' }
10
11
  raise WaxTasks::Error::MissingArguments, Rainbow("You must specify a collection after 'wax:derivatives:simple'").magenta if args.empty?
11
12
 
12
13
  site = WaxTasks::Site.new
data/lib/tasks/pages.rake CHANGED
@@ -6,6 +6,7 @@ namespace :wax do
6
6
  desc 'generate collection md pages from yaml or csv data source'
7
7
  task :pages do
8
8
  args = ARGV.drop(1).each { |a| task a.to_sym }
9
+ args.reject! { |a| a.start_with? '-' }
9
10
  raise WaxTasks::Error::MissingArguments, Rainbow('You must specify a collection after wax:pages').magenta if args.empty?
10
11
 
11
12
  site = WaxTasks::Site.new
@@ -6,6 +6,7 @@ namespace :wax do
6
6
  desc 'build lunr search index (with default UI if UI=true)'
7
7
  task :search do
8
8
  args = ARGV.drop(1).each { |a| task a.to_sym }
9
+ args.reject! { |a| a.start_with? '-' }
9
10
  raise WaxTasks::Error::MissingArguments, Rainbow('You must specify a collection after wax:search').magenta if args.empty?
10
11
 
11
12
  site = WaxTasks::Site.new
data/lib/wax_tasks.rb CHANGED
@@ -22,6 +22,7 @@ require_relative 'wax_tasks/item'
22
22
  require_relative 'wax_tasks/record'
23
23
  require_relative 'wax_tasks/site'
24
24
  require_relative 'wax_tasks/utils'
25
+ require_relative 'wax_tasks/version'
25
26
 
26
27
  #
27
28
  module WaxTasks
@@ -3,10 +3,11 @@
3
3
  #
4
4
  module WaxTasks
5
5
  Derivative = Struct.new(:path, :label, :img)
6
- attr_reader :id, :path
7
6
 
8
7
  #
9
8
  class Asset
9
+ attr_reader :id, :path
10
+
10
11
  def initialize(path, pid, variants)
11
12
  @path = path
12
13
  @pid = pid
@@ -17,7 +18,7 @@ module WaxTasks
17
18
  #
18
19
  #
19
20
  def asset_id
20
- id = File.basename(@path, '.*')
21
+ id = File.basename @path, '.*'
21
22
  id.prepend "#{@pid}_" unless id == @pid
22
23
  id
23
24
  end
@@ -26,7 +27,7 @@ module WaxTasks
26
27
  #
27
28
  def simple_derivatives
28
29
  @variants.map do |label, width|
29
- img = MiniMagick::Image.open(@path)
30
+ img = MiniMagick::Image.open @path
30
31
  if width > img.width
31
32
  warn Rainbow("Tried to create derivative #{width}px wide, but asset #{@id} for item #{@pid} only has a width of #{img.width}px.").yellow
32
33
  else
@@ -42,11 +43,13 @@ module WaxTasks
42
43
  #
43
44
  def to_iiif_image_record(is_only, index, base_opts)
44
45
  opts = base_opts.clone
46
+
45
47
  opts[:is_primary] = index.zero?
46
48
  opts[:section_label] = "Page #{index + 1}" unless is_only
47
49
  opts[:path] = @path
48
50
  opts[:manifest_id] = @pid
49
51
  opts[:id] = @id
52
+ opts[:variants] = @variants
50
53
 
51
54
  WaxIiif::ImageRecord.new(opts)
52
55
  end
@@ -7,23 +7,55 @@ module WaxTasks
7
7
  #
8
8
  class Collection
9
9
  attr_reader :name, :config, :ext, :search_fields,
10
- :page_source, :metadata_source, :imagedata_source
10
+ :page_source, :metadata_source, :imagedata_source,
11
+ :iiif_derivative_source, :simple_derivative_source
11
12
 
12
13
  include Collection::Metadata
13
14
  include Collection::Images
14
15
 
16
+ IMAGE_DERIVATIVE_DIRECTORY = 'img/derivatives'
17
+ DEFAULT_VARIANTS = { 'thumbnail' => 250, 'fullwidth' => 1140 }.freeze
18
+
15
19
  #
16
20
  #
17
21
  def initialize(name, config, source, collections_dir, ext)
18
- @name = name
19
- @config = config
20
- @page_extension = ext
21
- @site_source = source
22
- @page_source = Utils.safe_join source, collections_dir, "_#{name}"
23
- @metadata_source = Utils.safe_join source, '_data', config.dig('metadata', 'source')
24
- @imagedata_source = Utils.safe_join source, '_data', config.dig('images', 'source')
25
- @search_fields = %w[pid label thumbnail permalink collection]
26
- @image_variants = image_variants
22
+ @name = name
23
+ @config = config
24
+ @page_extension = ext
25
+ @site_source = source
26
+ @page_source = Utils.safe_join source, collections_dir, "_#{@name}"
27
+ @metadata_source = Utils.safe_join source, '_data', config.dig('metadata', 'source')
28
+ @imagedata_source = Utils.safe_join source, '_data', config.dig('images', 'source')
29
+ @iiif_derivative_source = Utils.safe_join source, IMAGE_DERIVATIVE_DIRECTORY, 'iiif'
30
+ @simple_derivative_source = Utils.safe_join source, IMAGE_DERIVATIVE_DIRECTORY, 'simple'
31
+ @search_fields = %w[pid label thumbnail permalink collection]
32
+ @image_variants = image_variants
33
+ end
34
+
35
+ #
36
+ #
37
+ def image_variants
38
+ vars = @config.dig('images', 'variants') || {}
39
+ DEFAULT_VARIANTS.merge vars
40
+ end
41
+
42
+ #
43
+ #
44
+ def clobber_pages
45
+ return unless Dir.exist? @page_source
46
+ puts Rainbow("Removing pages from #{@page_source}").cyan
47
+ FileUtils.remove_dir @page_source, true
48
+ end
49
+
50
+ #
51
+ #
52
+ def clobber_derivatives
53
+ [@iiif_derivative_source, @simple_derivative_source].each do |dir|
54
+ if Dir.exist? dir
55
+ puts Rainbow("Removing derivatives from #{dir}").cyan
56
+ FileUtils.remove_dir dir, true
57
+ end
58
+ end
27
59
  end
28
60
  end
29
61
  end
@@ -10,14 +10,6 @@ module WaxTasks
10
10
  class Collection
11
11
  #
12
12
  module Images
13
- #
14
- #
15
- def image_variants
16
- default_variants = { 'thumbnail' => 250, 'full' => 1140 }
17
- custom_variants = @config.dig('images', 'variants') || {}
18
- default_variants.merge custom_variants
19
- end
20
-
21
13
  #
22
14
  #
23
15
  def items_from_imagedata
@@ -27,14 +19,13 @@ module WaxTasks
27
19
  records = records_from_metadata
28
20
  Dir.glob(Utils.safe_join(@imagedata_source, '*')).map do |path|
29
21
  item = WaxTasks::Item.new(path, @image_variants)
30
- if item.valid?
31
- item.record = records.find { |r| r.pid == item.pid }
32
- item.iiif_config = @config.dig 'images', 'iiif'
33
- warn Rainbow("\nCould not find record in #{@metadata_source} for image item #{path}.\n").orange if item.record.nil?
34
- item
35
- else
36
- puts Rainbow("Skipping #{path} because type #{item.type} is not an accepted format").yellow unless item.type == '.pdf'
37
- end
22
+ next if item.type == '.pdf'
23
+ next puts Rainbow("Skipping #{path} because type #{item.type} is not an accepted format").yellow unless item.valid?
24
+
25
+ item.record = records.find { |r| r.pid == item.pid }
26
+ item.iiif_config = @config.dig 'images', 'iiif'
27
+ warn Rainbow("\nCould not find record in #{@metadata_source} for image item #{path}.\n").orange if item.record.nil?
28
+ item
38
29
  end.compact
39
30
  end
40
31
 
@@ -46,6 +37,7 @@ module WaxTasks
46
37
  next unless Dir.glob("#{target_dir}/*").empty?
47
38
 
48
39
  puts Rainbow("\nPreprocessing #{path} into image files. This may take a minute.\n").cyan
40
+
49
41
  opts = { output_dir: File.dirname(target_dir) }
50
42
  WaxIiif::Utilities::PdfSplitter.split(path, opts)
51
43
  end
@@ -53,18 +45,19 @@ module WaxTasks
53
45
 
54
46
  #
55
47
  #
56
- def write_simple_derivatives(dir)
48
+ def write_simple_derivatives
57
49
  puts Rainbow("Generating simple image derivatives for collection '#{@name}'\nThis might take awhile.").cyan
58
50
 
59
51
  bar = ProgressBar.new(items_from_imagedata.length)
52
+ bar.write
60
53
  items_from_imagedata.map do |item|
61
54
  item.simple_derivatives.each do |d|
62
- path = "#{dir}/#{d.path}"
55
+ path = "#{@simple_derivative_source}/#{d.path}"
63
56
  FileUtils.mkdir_p File.dirname(path)
64
57
  next if File.exist? path
65
58
 
66
59
  d.img.write path
67
- item.record.set d.label, path if item.record?
60
+ item.record.set d.label, "/#{path}" if item.record?
68
61
  end
69
62
  bar.increment!
70
63
  bar.write
@@ -78,9 +71,10 @@ module WaxTasks
78
71
  build_opts = {
79
72
  base_url: "{{ '/' | absolute_url }}#{dir}",
80
73
  output_dir: dir,
81
- collection_label: @name
74
+ collection_label: @name,
75
+ variants: @image_variants.dup.tap { |h| h.delete 'full' }
82
76
  }
83
- WaxIiif::Builder.new(build_opts)
77
+ WaxIiif::Builder.new build_opts
84
78
  end
85
79
 
86
80
  #
@@ -102,8 +96,8 @@ module WaxTasks
102
96
 
103
97
  json = JSON.parse manifest.to_json
104
98
  @image_variants.each do |k, _v|
105
- value = json.dig k
106
- record.set k, "/#{Utils.content_clean(value)}" unless value.nil?
99
+ value = json.fetch k, ''
100
+ record.set k, "/#{Utils.content_clean(value)}" unless value.empty?
107
101
  end
108
102
 
109
103
  record.set 'manifest', "/#{Utils.content_clean(manifest.id)}"
@@ -113,10 +107,10 @@ module WaxTasks
113
107
 
114
108
  #
115
109
  #
116
- def write_iiif_derivatives(dir)
110
+ def write_iiif_derivatives
117
111
  items = items_from_imagedata
118
112
  iiif_data = items.map(&:iiif_image_records).flatten
119
- builder = iiif_builder(dir)
113
+ builder = iiif_builder @iiif_derivative_source
120
114
 
121
115
  builder.load iiif_data
122
116
 
@@ -124,7 +118,7 @@ module WaxTasks
124
118
  builder.process_data
125
119
  records = items.map(&:record).compact
126
120
 
127
- add_font_matter_to_json_files dir
121
+ add_font_matter_to_json_files @iiif_derivative_source
128
122
  add_iiif_results_to_records records, builder.manifests
129
123
  end
130
124
  end
@@ -6,8 +6,12 @@ module WaxTasks
6
6
  attr_reader :collections
7
7
 
8
8
  def initialize(config)
9
- @config = config
10
- @collections = process_collections
9
+ @config = config
10
+ @collections = process_collections
11
+ end
12
+
13
+ def self
14
+ @config
11
15
  end
12
16
 
13
17
  #
@@ -34,7 +34,7 @@ module WaxTasks
34
34
  #
35
35
  #
36
36
  def write_to(dir)
37
- file_path = WaxTasks::Utils.safe_join Dir.pwd, dir, path
37
+ file_path = WaxTasks::Utils.safe_join dir, @path
38
38
  FileUtils.mkdir_p File.dirname(file_path)
39
39
  File.open(file_path, 'w') do |f|
40
40
  f.puts "---\nlayout: none\n---\n"
@@ -32,7 +32,7 @@ module WaxTasks
32
32
  #
33
33
  #
34
34
  def valid?
35
- accepted_image_formats.include?(@type) || @type == 'dir'
35
+ accepted_image_formats.include? @type or @type == 'dir'
36
36
  end
37
37
 
38
38
  #
@@ -47,7 +47,7 @@ module WaxTasks
47
47
  if accepted_image_formats.include? @type
48
48
  [Asset.new(@path, @pid, @variants)]
49
49
  elsif @type == 'dir'
50
- paths = Dir.glob("#{@path}/*{#{accepted_image_formats.join(',')}}")
50
+ paths = Dir.glob("#{@path}/*{#{accepted_image_formats.join(',')}}").sort
51
51
  paths.map { |p| Asset.new(p, @pid, @variants) }
52
52
  else
53
53
  []
@@ -3,12 +3,15 @@
3
3
  module WaxTasks
4
4
  #
5
5
  class Record
6
- attr_reader :pid, :hash, :order
6
+ attr_reader :pid, :hash
7
7
 
8
8
  def initialize(hash)
9
9
  @hash = hash
10
10
  @pid = @hash.dig 'pid'
11
- @order = @hash.dig 'order'
11
+ end
12
+
13
+ def order
14
+ @hash.dig 'order'
12
15
  end
13
16
 
14
17
  #
@@ -23,9 +26,13 @@ module WaxTasks
23
26
  @hash.keys
24
27
  end
25
28
 
26
- #
29
+ # PATCH :: rename 'fullwidth' to 'full' to
30
+ # (1) avoid breaking wax_iiif with special 'full' variant label
31
+ # (2) avoid breaking wax_theme which still expects 'full' to provide an image path
32
+ # this can be deprecated when a new version of wax_theme looks for another fullsize key
27
33
  #
28
34
  def set(key, value)
35
+ key = 'full' if key == 'fullwidth'
29
36
  @hash[key] = value
30
37
  end
31
38
 
@@ -38,7 +45,7 @@ module WaxTasks
38
45
  #
39
46
  #
40
47
  def order?
41
- @order.is_a? String
48
+ !order.to_s.empty?
42
49
  end
43
50
 
44
51
  #
@@ -5,7 +5,6 @@ module WaxTasks
5
5
  #
6
6
  class Site
7
7
  attr_reader :config
8
- IMAGE_DERIVATIVE_DIRECTORY = 'img/derivatives'
9
8
 
10
9
  #
11
10
  #
@@ -19,6 +18,26 @@ module WaxTasks
19
18
  @config.collections
20
19
  end
21
20
 
21
+ #
22
+ #
23
+ def clobber(name)
24
+ collection = @config.find_collection name
25
+ raise WaxTasks::Error::InvalidCollection if collection.nil?
26
+
27
+ collection.clobber_pages
28
+ collection.clobber_derivatives
29
+
30
+ @config.self.fetch('search', {}).each do |_name, search|
31
+ next unless search.key? 'index'
32
+ index = Utils.safe_join @config.source, search['index']
33
+ next unless File.exist? index
34
+ puts Rainbow("Removing search index #{index}").cyan
35
+ FileUtils.rm index
36
+ end
37
+
38
+ puts Rainbow("\nDone ✔").green
39
+ end
40
+
22
41
  #
23
42
  #
24
43
  def generate_pages(name)
@@ -53,12 +72,11 @@ module WaxTasks
53
72
  raise WaxTasks::Error::InvalidCollection if collection.nil?
54
73
  raise WaxTasks::Error::InvalidConfig unless %w[iiif simple].include? type
55
74
 
56
- output_dir = Utils.safe_join @config.source, IMAGE_DERIVATIVE_DIRECTORY, type
57
75
  records = case type
58
76
  when 'iiif'
59
- collection.write_iiif_derivatives output_dir
77
+ collection.write_iiif_derivatives
60
78
  when 'simple'
61
- collection.write_simple_derivatives output_dir
79
+ collection.write_simple_derivatives
62
80
  end
63
81
 
64
82
  collection.update_metadata records
@@ -27,7 +27,7 @@ module WaxTasks
27
27
  # @return [Array] same data unless a an item is missing the key `pid`
28
28
  # @raise WaxTasks::Error::MissingPid
29
29
  def self.assert_pids(data)
30
- data.each_with_index { |d, i| raise Error::MissingPid, "Collection is missing pid for item #{i}." unless d.key? 'pid' }
30
+ data.each_with_index { |d, i| raise Error::MissingPid, "Collection is missing pid for item #{i}.\nHint: review common .csv formatting issues (such as hidden characters) in the documentation: https://minicomp.github.io/wiki/wax/preparing-your-collection-data/metadata/" unless d.key? 'pid' }
31
31
  data
32
32
  end
33
33
 
@@ -90,7 +90,7 @@ module WaxTasks
90
90
  str.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
91
91
  str.gsub!(/{%(.*)%}/, '') # remove functional liquid
92
92
  str.gsub!(/{{.*}}/, '') # remove referential liquid
93
- str.gsub!(%r{<\/?[^>]*>}, '') # remove html
93
+ str.gsub!(%r{</?[^>]*>}, '') # remove html
94
94
  str.gsub!('\\n', '') # remove newlines
95
95
  str.gsub!(/\s+/, ' ') # remove extra space
96
96
  str.tr!('"', "'") # replace double quotes with single
@@ -114,7 +114,7 @@ module WaxTasks
114
114
  #
115
115
  #
116
116
  def self.safe_join(*args)
117
- File.join(args.compact)
117
+ File.join(args.compact).sub %r{^/}, ''
118
118
  end
119
119
 
120
120
  # Constructs the order variable for each page (if the collection
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WaxTasks
4
+ VERSION = '1.1.5'
5
+ end
data/wax_tasks.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/wax_tasks/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'wax_tasks'
7
+ spec.version = WaxTasks::VERSION
8
+ spec.authors = ['Marii Nyrop']
9
+ spec.email = ['marii@nyu.edu']
10
+ spec.license = 'MIT'
11
+ spec.homepage = 'https://github.com/minicomp/wax_tasks'
12
+ spec.summary = 'Rake tasks for minimal exhibition sites with Minicomp/Wax.'
13
+ spec.description = 'Rake tasks for minimal exhibition sites with Minicomp/Wax.'
14
+
15
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+
19
+ spec.test_files = Dir['spec/*']
20
+ spec.required_ruby_version = '>= 2.4'
21
+ spec.metadata['yard.run'] = 'yri'
22
+
23
+ spec.requirements << 'imagemagick'
24
+ spec.requirements << 'ghostscript'
25
+
26
+ spec.add_runtime_dependency 'progress_bar', '~> 1.3'
27
+ spec.add_runtime_dependency 'rainbow', '~> 3.0'
28
+ spec.add_runtime_dependency 'rake', '~> 13.0'
29
+ spec.add_runtime_dependency 'safe_yaml', '~> 1.0'
30
+ spec.add_runtime_dependency 'wax_iiif', '~> 0.2'
31
+
32
+ spec.add_development_dependency 'rspec', '~> 3'
33
+ 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: 1.0.2
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marii Nyrop
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-13 00:00:00.000000000 Z
11
+ date: 2021-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: progress_bar
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.3'
47
+ version: '13.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.3'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: safe_yaml
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,20 +70,14 @@ dependencies:
70
70
  name: wax_iiif
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 0.1.2
76
- - - "<"
73
+ - - "~>"
77
74
  - !ruby/object:Gem::Version
78
75
  version: '0.2'
79
76
  type: :runtime
80
77
  prerelease: false
81
78
  version_requirements: !ruby/object:Gem::Requirement
82
79
  requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: 0.1.2
86
- - - "<"
80
+ - - "~>"
87
81
  - !ruby/object:Gem::Version
88
82
  version: '0.2'
89
83
  - !ruby/object:Gem::Dependency
@@ -100,14 +94,25 @@ dependencies:
100
94
  - - "~>"
101
95
  - !ruby/object:Gem::Version
102
96
  version: '3'
103
- description: Rake tasks for minimal exhibition sites with Jekyll Wax.
97
+ description: Rake tasks for minimal exhibition sites with Minicomp/Wax.
104
98
  email:
105
- - m.nyrop@columbia.edu
99
+ - marii@nyu.edu
106
100
  executables: []
107
101
  extensions: []
108
102
  extra_rdoc_files: []
109
103
  files:
104
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
105
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
106
+ - ".github/workflows/ci.yml"
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - ".rubocop.yml"
110
+ - ".ruby-version"
111
+ - CODE_OF_CONDUCT.md
110
112
  - Gemfile
113
+ - LICENSE
114
+ - README.md
115
+ - lib/tasks/clobber.rake
111
116
  - lib/tasks/derivatives_iiif.rake
112
117
  - lib/tasks/derivatives_simple.rake
113
118
  - lib/tasks/pages.rake
@@ -124,14 +129,16 @@ files:
124
129
  - lib/wax_tasks/record.rb
125
130
  - lib/wax_tasks/site.rb
126
131
  - lib/wax_tasks/utils.rb
132
+ - lib/wax_tasks/version.rb
127
133
  - spec/setup.rb
128
134
  - spec/spec_helper.rb
135
+ - wax_tasks.gemspec
129
136
  homepage: https://github.com/minicomp/wax_tasks
130
137
  licenses:
131
138
  - MIT
132
139
  metadata:
133
140
  yard.run: yri
134
- post_install_message:
141
+ post_install_message:
135
142
  rdoc_options: []
136
143
  require_paths:
137
144
  - lib
@@ -148,11 +155,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
155
  requirements:
149
156
  - imagemagick
150
157
  - ghostscript
151
- rubyforge_project:
152
- rubygems_version: 2.7.6
153
- signing_key:
158
+ rubygems_version: 3.1.4
159
+ signing_key:
154
160
  specification_version: 4
155
- summary: Rake tasks for minimal exhibition sites with Jekyll Wax.
161
+ summary: Rake tasks for minimal exhibition sites with Minicomp/Wax.
156
162
  test_files:
157
163
  - spec/spec_helper.rb
158
164
  - spec/setup.rb