wax_tasks 0.3.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ module WaxTasks
5
+ #
6
+ class Site
7
+ attr_reader :config
8
+
9
+ #
10
+ #
11
+ def initialize(config = nil)
12
+ @config = WaxTasks::Config.new(config || WaxTasks.config_from_file)
13
+ end
14
+
15
+ #
16
+ #
17
+ def collections
18
+ @config.collections
19
+ end
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
+
41
+ #
42
+ #
43
+ def generate_pages(name)
44
+ result = 0
45
+ collection = @config.find_collection name
46
+ raise WaxTasks::Error::InvalidCollection if collection.nil?
47
+
48
+ collection.records_from_metadata.each do |record|
49
+ result += record.write_to_page(collection.page_source)
50
+ end
51
+
52
+ puts Rainbow("#{result} pages were generated to #{collection.page_source}.").cyan
53
+ puts Rainbow("\nDone ✔").green
54
+ end
55
+
56
+ #
57
+ #
58
+ def generate_static_search(name)
59
+ search_config = @config.search name
60
+ index = WaxTasks::Index.new(search_config)
61
+
62
+ puts Rainbow("Generating #{name} search index to #{index.path}").cyan
63
+ index.write_to @config.source
64
+
65
+ puts Rainbow("\nDone ✔").green
66
+ end
67
+
68
+ #
69
+ #
70
+ def generate_derivatives(name, type)
71
+ collection = @config.find_collection name
72
+ raise WaxTasks::Error::InvalidCollection if collection.nil?
73
+ raise WaxTasks::Error::InvalidConfig unless %w[iiif simple].include? type
74
+
75
+ records = case type
76
+ when 'iiif'
77
+ collection.write_iiif_derivatives
78
+ when 'simple'
79
+ collection.write_simple_derivatives
80
+ end
81
+
82
+ collection.update_metadata records
83
+ puts Rainbow("\nDone ✔").green
84
+ end
85
+ end
86
+ end
@@ -1,17 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WaxTasks
2
4
  # Utility helper methods
3
5
  module Utils
4
- # Contructs permalink extension from site `permalink` variable
5
6
  #
6
- # @param site [Hash] the site config
7
- # @return [String] the end of the permalink, either '/' or '.html'
8
- def self.construct_permalink(site)
9
- case site.fetch(:permalink, false)
10
- when 'pretty' || '/'
11
- '/'
12
- else
13
- '.html'
14
- end
7
+ #
8
+ def self.ingest(source)
9
+ metadata = case File.extname source
10
+ when '.csv'
11
+ WaxTasks::Utils.validate_csv source
12
+ when '.json'
13
+ WaxTasks::Utils.validate_json source
14
+ when /\.ya?ml/
15
+ WaxTasks::Utils.validate_yaml source
16
+ else
17
+ raise Error::InvalidSource, "Can't load #{File.extname source} files. Culprit: #{source}"
18
+ end
19
+
20
+ WaxTasks::Utils.assert_pids metadata
21
+ WaxTasks::Utils.assert_unique metadata
15
22
  end
16
23
 
17
24
  # Checks and asserts presence of `pid` value for each item
@@ -20,7 +27,7 @@ module WaxTasks
20
27
  # @return [Array] same data unless a an item is missing the key `pid`
21
28
  # @raise WaxTasks::Error::MissingPid
22
29
  def self.assert_pids(data)
23
- data.each_with_index { |d, i| raise Error::MissingPid, "Collection #{@name} 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' }
24
31
  data
25
32
  end
26
33
 
@@ -33,6 +40,7 @@ module WaxTasks
33
40
  pids = data.map { |d| d['pid'] }
34
41
  not_unique = pids.select { |p| pids.count(p) > 1 }.uniq! || []
35
42
  raise Error::NonUniquePid, "#{@name} has the following nonunique pids:\n#{not_unique}" unless not_unique.empty?
43
+
36
44
  data
37
45
  end
38
46
 
@@ -53,8 +61,8 @@ module WaxTasks
53
61
  # @return [Array] validated JSON data as an Array of Hashes
54
62
  # @raise WaxTasks::Error::InvalidJSON
55
63
  def self.validate_json(source)
56
- file = File.read(source)
57
- JSON.parse(file)
64
+ file = File.read source
65
+ JSON.parse file
58
66
  rescue StandardError => e
59
67
  raise Error::InvalidJSON, " #{e}"
60
68
  end
@@ -65,42 +73,23 @@ module WaxTasks
65
73
  # @return [Array] validated YAML data as an Array of Hashes
66
74
  # @raise WaxTasks::Error::InvalidYAML
67
75
  def self.validate_yaml(source)
68
- YAML.load_file(source)
76
+ SafeYAML.load_file source
69
77
  rescue StandardError => e
70
78
  raise WaxTasks::Error::InvalidYAML, " #{e}"
71
79
  end
72
80
 
73
- # Creates a file path valid file path with empty strings and
74
- # null values dropped
75
- #
76
- # @param args [Array] items to concatenate in path
77
- # @return [String] file path
78
- def self.make_path(*args)
79
- args.compact.reject(&:empty?).join('/')
80
- end
81
-
82
- # Finds collections in site config where `lunr_index` is enabled
83
- #
84
- # @param site [Hash] the site config
85
- # @return [Array] a list of collection names
86
- # @raise WaxTasks::Error::NoLunrCollections
87
- def self.get_lunr_collections(site)
88
- to_index = site[:collections].find_all { |c| c[1].key?('lunr_index') }
89
- raise Error::NoLunrCollections, 'There are no lunr collections to index.' if to_index.nil?
90
- to_index.map { |c| c[0] }
91
- end
92
-
93
81
  # Removes YAML front matter from a string
94
82
  # @return [String]
95
83
  def self.remove_yaml(str)
96
84
  str.to_s.gsub!(/\A---(.|\n)*?---/, '')
97
85
  end
98
86
 
99
- # Cleans YAML front matter + markdown pages for lunr indexing
87
+ # Scrubs yaml, liquid, html, and etc from content strings
100
88
  # @return [String]
101
- def self.html_strip(str)
89
+ def self.content_clean(str)
102
90
  str.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
103
91
  str.gsub!(/{%(.*)%}/, '') # remove functional liquid
92
+ str.gsub!(/{{.*}}/, '') # remove referential liquid
104
93
  str.gsub!(%r{<\/?[^>]*>}, '') # remove html
105
94
  str.gsub!('\\n', '') # remove newlines
106
95
  str.gsub!(/\s+/, ' ') # remove extra space
@@ -113,91 +102,50 @@ module WaxTasks
113
102
  def self.remove_diacritics(str)
114
103
  to_replace = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž'
115
104
  replaced_by = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz'
116
- str.to_s.tr(to_replace, replaced_by)
105
+ str.to_s.tr to_replace, replaced_by
117
106
  end
118
107
 
119
108
  # Converts string to snake case and swaps out special chars
120
109
  # @return [String]
121
110
  def self.slug(str)
122
- str.to_s.downcase.tr(' ', '_').gsub(/[^\w-]/, '')
111
+ Utils.remove_diacritics(str).to_s.downcase.tr(' ', '_').gsub(/[^\w-]/, '')
123
112
  end
124
- end
125
- end
126
-
127
- # Monkey-patched String class
128
- class String
129
- # Normalizes string without diacritics for lunr indexing
130
- # @return [String]
131
- def lunr_normalize
132
- WaxTasks::Utils.remove_diacritics(self)
133
- end
134
-
135
- # Colorizes console output to magenta (errors)
136
- # @return [String]
137
- def magenta
138
- "\e[35m#{self}\e[0m"
139
- end
140
-
141
- # Colorizes console output to cyan (messages)
142
- # @return [String]
143
- def cyan
144
- "\e[36m#{self}\e[0m"
145
- end
146
113
 
147
- # Colorizes console output to orange (warnings)
148
- # @return [String]
149
- def orange
150
- "\e[33m#{self}\e[0m"
151
- end
152
- end
153
-
154
- # Monkey-patched Array class
155
- class Array
156
- # Normalizes an array as a string or array of hashes
157
- # without diacritics for lunr indexing
158
- # @return [Hash || String] description
159
- def lunr_normalize
160
- if self.first.is_a? Hash
161
- self
162
- else
163
- WaxTasks::Utils.remove_diacritics(self.join(', '))
114
+ #
115
+ #
116
+ def self.safe_join(*args)
117
+ File.join(args.compact).sub %r{^\/}, ''
164
118
  end
165
- end
166
- end
167
119
 
168
- # Monkey-patched Hash class
169
- class Hash
170
- # Normalizes hash as itself for lunr indexing
171
- # @return [Hash]
172
- def lunr_normalize
173
- self
174
- end
120
+ # Constructs the order variable for each page (if the collection
121
+ # needs to preserve the order of items from the file)
122
+ #
123
+ # @return [Integer] the order if the item padded with '0's for sorting
124
+ def self.padded_int(idx, max_idx)
125
+ idx.to_s.rjust(Math.log10(max_idx).to_i + 1, '0')
126
+ end
175
127
 
176
- # Converts hash keys to symbols
177
- # @return [Hash]
178
- def symbolize_keys
179
- hash = self
180
- hash.clone.each_key do |key|
181
- hash[key.to_sym || key] = hash.delete(key)
128
+ def self.lunr_normalize(val)
129
+ case val
130
+ when String || Integer
131
+ WaxTasks::Utils.remove_diacritics val.to_s
132
+ when Array
133
+ return val if val.first.is_a? Hash
134
+ WaxTasks::Utils.remove_diacritics val.join(', ')
135
+ else
136
+ val
137
+ end
182
138
  end
183
- hash
184
- end
185
- end
186
139
 
187
- # Monkey-patched Integer class
188
- class Integer
189
- # Normalizes integer as a string for lunr indexing
190
- # @return [String]
191
- def lunr_normalize
192
- self.to_s
193
- end
194
- end
140
+ def self.add_yaml_front_matter_to_file(file)
141
+ front_matter = "---\nlayout: none\n---\n"
142
+ filestring = File.read file
143
+ return if filestring.start_with? front_matter
195
144
 
196
- # Monkey-patched Nil class
197
- class NilClass
198
- # Normalizes integer as a string for lunr indexing
199
- # @return [String]
200
- def lunr_normalize
201
- self.to_s
145
+ File.open(file, 'w') do |f|
146
+ f.puts front_matter
147
+ f.puts filestring
148
+ end
149
+ end
202
150
  end
203
151
  end
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
  #constants
4
4
  ROOT = `pwd`.strip.freeze
5
5
  SAMPLE = "#{ROOT}/spec/sample_site".freeze
6
- BUILD = "#{ROOT}/build".freeze
6
+ BUILD = "#{ROOT}/test_build".freeze
7
7
 
8
8
  # helper methods
9
9
  def quiet_stdout
@@ -28,11 +28,11 @@ def quiet_stdout
28
28
  end
29
29
  end
30
30
 
31
- module WaxTasks::Test
31
+ module Test
32
32
  def self.reset
33
33
  Dir.chdir(ROOT)
34
34
  FileUtils.rm_r(BUILD) if File.directory?(BUILD)
35
- FileUtils.copy_entry SAMPLE, BUILD
35
+ FileUtils.copy_entry(SAMPLE, BUILD)
36
36
  Dir.chdir(BUILD)
37
37
  end
38
38
  end
@@ -3,21 +3,26 @@
3
3
  QUIET = !ENV['DEBUG']
4
4
 
5
5
  # use codecov + add requirements
6
+ require 'setup'
6
7
  require 'simplecov'
7
8
  SimpleCov.start do
8
9
  add_filter 'spec'
9
- add_filter 'branch'
10
10
  end
11
-
12
- # load + setup
13
11
  require 'wax_tasks'
14
- require 'setup'
15
12
 
16
13
  # provide shared context for tests
17
14
  shared_context 'shared', :shared_context => :metadata do
18
- let(:task_runner) { WaxTasks::TaskRunner.new }
19
- let(:default_site) { task_runner.site }
20
- let(:args) { default_site[:collections].map{ |c| c[0] } }
21
- let(:index_path) { WaxTasks::LUNR_INDEX_PATH }
22
- let(:ui_path) { WaxTasks::LUNR_UI_PATH }
15
+ let(:config_from_file) { WaxTasks.config_from_file }
16
+ let(:invalid_content_config) { WaxTasks.config_from_file("#{BUILD}/_invalid_content_config.yml") }
17
+ let(:invalid_format_config) { WaxTasks.config_from_file("#{BUILD}/_invalid_format_config.yml") }
18
+ let(:empty_config) { Hash.new }
19
+
20
+ let(:site_from_config_file) { WaxTasks::Site.new(config_from_file) }
21
+ let(:site_from_empty_config) { WaxTasks::Site.new(empty_config) }
22
+ let(:site_from_invalid_config) { WaxTasks::Site.new(invalid_content_config) }
23
+
24
+ let(:args_from_file) { %w[csv_collection json_collection yaml_collection] }
25
+ let(:csv) { args_from_file.first }
26
+ let(:json) { args_from_file[1] }
27
+ let(:yaml) { args_from_file[2] }
23
28
  end
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wax_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.1.1
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: 2018-09-21 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: html-proofer
14
+ name: progress_bar
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3'
19
+ version: '1.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3'
26
+ version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: jekyll
28
+ name: rainbow
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12'
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'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: wax_iiif
56
+ name: safe_yaml
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.2
61
+ version: '1.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.2
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: bundler
70
+ name: wax_iiif
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1'
76
- type: :development
75
+ version: '0.2'
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: '1'
82
+ version: '0.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,39 +94,39 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3'
97
- description: Rake tasks for minimal exhibition sites with Jekyll Wax.
97
+ description: Rake tasks for minimal exhibition sites with Minicomp/Wax.
98
98
  email:
99
- - m.nyrop@columbia.edu
99
+ - marii@nyu.edu
100
100
  executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - Gemfile
105
- - lib/tasks/iiif.rake
106
- - lib/tasks/jspackage.rake
107
- - lib/tasks/lunr.rake
108
- - lib/tasks/pagemaster.rake
109
- - lib/tasks/push.rake
110
- - lib/tasks/test.rake
105
+ - lib/tasks/clobber.rake
106
+ - lib/tasks/derivatives_iiif.rake
107
+ - lib/tasks/derivatives_simple.rake
108
+ - lib/tasks/pages.rake
109
+ - lib/tasks/search.rake
111
110
  - lib/wax_tasks.rb
112
- - lib/wax_tasks/branch.rb
111
+ - lib/wax_tasks/asset.rb
113
112
  - lib/wax_tasks/collection.rb
113
+ - lib/wax_tasks/collection/images.rb
114
+ - lib/wax_tasks/collection/metadata.rb
115
+ - lib/wax_tasks/config.rb
114
116
  - lib/wax_tasks/error.rb
115
- - lib/wax_tasks/iiif_collection.rb
116
- - lib/wax_tasks/local_branch.rb
117
- - lib/wax_tasks/lunr_collection.rb
118
- - lib/wax_tasks/lunr_index.rb
119
- - lib/wax_tasks/pagemaster_collection.rb
120
- - lib/wax_tasks/task_runner.rb
121
- - lib/wax_tasks/travis_branch.rb
117
+ - lib/wax_tasks/index.rb
118
+ - lib/wax_tasks/item.rb
119
+ - lib/wax_tasks/record.rb
120
+ - lib/wax_tasks/site.rb
122
121
  - lib/wax_tasks/utils.rb
123
122
  - spec/setup.rb
124
123
  - spec/spec_helper.rb
125
124
  homepage: https://github.com/minicomp/wax_tasks
126
125
  licenses:
127
126
  - MIT
128
- metadata: {}
129
- post_install_message:
127
+ metadata:
128
+ yard.run: yri
129
+ post_install_message:
130
130
  rdoc_options: []
131
131
  require_paths:
132
132
  - lib
@@ -134,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
137
+ version: '2.4'
138
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="
@@ -142,11 +142,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  requirements:
144
144
  - imagemagick
145
- rubyforge_project:
146
- rubygems_version: 2.7.6
147
- signing_key:
145
+ - ghostscript
146
+ rubyforge_project:
147
+ rubygems_version: 2.7.6.2
148
+ signing_key:
148
149
  specification_version: 4
149
- summary: Rake tasks for minimal exhibition sites with Jekyll Wax.
150
+ summary: Rake tasks for minimal exhibition sites with Minicomp/Wax.
150
151
  test_files:
151
152
  - spec/spec_helper.rb
152
153
  - spec/setup.rb