wax_tasks 1.0.0.pre.beta → 1.0.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.
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ module WaxTasks
5
+ #
6
+ class Site
7
+ attr_reader :config
8
+ IMAGE_DERIVATIVE_DIRECTORY = 'img/derivatives'
9
+
10
+ #
11
+ #
12
+ def initialize(config = nil)
13
+ @config = WaxTasks::Config.new(config || WaxTasks.config_from_file)
14
+ end
15
+
16
+ #
17
+ #
18
+ def collections
19
+ @config.collections
20
+ end
21
+
22
+ #
23
+ #
24
+ def generate_pages(name)
25
+ result = 0
26
+ collection = @config.find_collection name
27
+ raise WaxTasks::Error::InvalidCollection if collection.nil?
28
+
29
+ collection.records_from_metadata.each do |record|
30
+ result += record.write_to_page(collection.page_source)
31
+ end
32
+
33
+ puts Rainbow("#{result} pages were generated to #{collection.page_source}.").cyan
34
+ puts Rainbow("\nDone ✔").green
35
+ end
36
+
37
+ #
38
+ #
39
+ def generate_static_search(name)
40
+ search_config = @config.search name
41
+ index = WaxTasks::Index.new(search_config)
42
+
43
+ puts Rainbow("Generating #{name} search index to #{index.path}").cyan
44
+ index.write_to @config.source
45
+
46
+ puts Rainbow("\nDone ✔").green
47
+ end
48
+
49
+ #
50
+ #
51
+ def generate_derivatives(name, type)
52
+ collection = @config.find_collection name
53
+ raise WaxTasks::Error::InvalidCollection if collection.nil?
54
+ raise WaxTasks::Error::InvalidConfig unless %w[iiif simple].include? type
55
+
56
+ output_dir = Utils.safe_join @config.source, IMAGE_DERIVATIVE_DIRECTORY, type
57
+ records = case type
58
+ when 'iiif'
59
+ collection.write_iiif_derivatives output_dir
60
+ when 'simple'
61
+ collection.write_simple_derivatives output_dir
62
+ end
63
+
64
+ collection.update_metadata records
65
+ puts Rainbow("\nDone ✔").green
66
+ end
67
+ end
68
+ 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}." 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,35 +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.root_path(*args)
79
- ['.'].concat(args).compact.reject(&:empty?).join('/').gsub(%r{/+}, '/')
80
- end
81
-
82
81
  # Removes YAML front matter from a string
83
82
  # @return [String]
84
83
  def self.remove_yaml(str)
85
84
  str.to_s.gsub!(/\A---(.|\n)*?---/, '')
86
85
  end
87
86
 
88
- def self.rm_liquid(str)
89
- str.gsub(/{{.*}}/, '')
90
- end
91
-
92
- # Cleans YAML front matter + markdown pages for lunr indexing
87
+ # Scrubs yaml, liquid, html, and etc from content strings
93
88
  # @return [String]
94
- def self.html_strip(str)
89
+ def self.content_clean(str)
95
90
  str.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
96
91
  str.gsub!(/{%(.*)%}/, '') # remove functional liquid
92
+ str.gsub!(/{{.*}}/, '') # remove referential liquid
97
93
  str.gsub!(%r{<\/?[^>]*>}, '') # remove html
98
94
  str.gsub!('\\n', '') # remove newlines
99
95
  str.gsub!(/\s+/, ' ') # remove extra space
@@ -106,95 +102,50 @@ module WaxTasks
106
102
  def self.remove_diacritics(str)
107
103
  to_replace = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž'
108
104
  replaced_by = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz'
109
- str.to_s.tr(to_replace, replaced_by)
105
+ str.to_s.tr to_replace, replaced_by
110
106
  end
111
107
 
112
108
  # Converts string to snake case and swaps out special chars
113
109
  # @return [String]
114
110
  def self.slug(str)
115
- str.to_s.downcase.tr(' ', '_').gsub(/[^\w-]/, '')
111
+ Utils.remove_diacritics(str).to_s.downcase.tr(' ', '_').gsub(/[^\w-]/, '')
116
112
  end
117
- end
118
- end
119
-
120
- # Monkey-patched String class
121
- class String
122
- # Normalizes string without diacritics for lunr indexing
123
- # @return [String]
124
- def lunr_normalize
125
- WaxTasks::Utils.remove_diacritics(self)
126
- end
127
-
128
- # Colorizes console output to magenta (errors)
129
- # @return [String]
130
- def magenta
131
- "\e[35m#{self}\e[0m"
132
- end
133
-
134
- # Colorizes console output to cyan (messages)
135
- # @return [String]
136
- def cyan
137
- "\e[36m#{self}\e[0m"
138
- end
139
-
140
- # Colorizes console output to orange (warnings)
141
- # @return [String]
142
- def orange
143
- "\e[33m#{self}\e[0m"
144
- end
145
- end
146
113
 
147
- # Monkey-patched Array class
148
- class Array
149
- # Normalizes an array as a string or array of hashes
150
- # without diacritics for lunr indexing
151
- # @return [Hash || String] description
152
- def lunr_normalize
153
- if self.first.is_a? Hash
154
- self
155
- else
156
- WaxTasks::Utils.remove_diacritics(self.join(', '))
114
+ #
115
+ #
116
+ def self.safe_join(*args)
117
+ File.join(args.compact)
157
118
  end
158
- end
159
119
 
160
- def except(value)
161
- self - value
162
- end
163
- end
164
-
165
- # Monkey-patched Hash class
166
- class Hash
167
- # Normalizes hash as itself for lunr indexing
168
- # @return [Hash]
169
- def lunr_normalize
170
- self
171
- 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
172
127
 
173
- # Converts hash keys to symbols
174
- # @return [Hash]
175
- def symbolize_keys
176
- hash = self
177
- hash.clone.each_key do |key|
178
- 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
179
138
  end
180
- hash
181
- end
182
- end
183
139
 
184
- # Monkey-patched Integer class
185
- class Integer
186
- # Normalizes integer as a string for lunr indexing
187
- # @return [String]
188
- def lunr_normalize
189
- self.to_s
190
- end
191
- 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
192
144
 
193
- # Monkey-patched Nil class
194
- class NilClass
195
- # Normalizes integer as a string for lunr indexing
196
- # @return [String]
197
- def lunr_normalize
198
- self.to_s
145
+ File.open(file, 'w') do |f|
146
+ f.puts front_matter
147
+ f.puts filestring
148
+ end
149
+ end
199
150
  end
200
151
  end
data/spec/setup.rb CHANGED
@@ -28,7 +28,7 @@ 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)
data/spec/spec_helper.rb CHANGED
@@ -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) { "#{BUILD}/js/lunr-index.json" }
22
- let(:ui_path) { "#{BUILD }/js/lunr-ui.js" }
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,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wax_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta
4
+ version: 1.0.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-11 00:00:00.000000000 Z
11
+ date: 2019-06-04 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.9'
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.9'
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.8'
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.8'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,33 +53,39 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '12.3'
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.1.0
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.1.0
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.1.1
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '0.2'
79
+ type: :runtime
77
80
  prerelease: false
78
81
  version_requirements: !ruby/object:Gem::Requirement
79
82
  requirements:
80
- - - "~>"
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 0.1.1
86
+ - - "<"
81
87
  - !ruby/object:Gem::Version
82
- version: '1'
88
+ version: '0.2'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: rspec
85
91
  requirement: !ruby/object:Gem::Requirement
@@ -104,31 +110,27 @@ files:
104
110
  - Gemfile
105
111
  - lib/tasks/derivatives_iiif.rake
106
112
  - lib/tasks/derivatives_simple.rake
107
- - lib/tasks/jspackage.rake
108
- - lib/tasks/lunr.rake
109
- - lib/tasks/pagemaster.rake
110
- - lib/tasks/push.rake
111
- - lib/tasks/test.rake
113
+ - lib/tasks/pages.rake
114
+ - lib/tasks/search.rake
112
115
  - lib/wax_tasks.rb
113
- - lib/wax_tasks/branch.rb
116
+ - lib/wax_tasks/asset.rb
114
117
  - lib/wax_tasks/collection.rb
118
+ - lib/wax_tasks/collection/images.rb
119
+ - lib/wax_tasks/collection/metadata.rb
120
+ - lib/wax_tasks/config.rb
115
121
  - lib/wax_tasks/error.rb
116
- - lib/wax_tasks/iiif/derivatives.rb
117
- - lib/wax_tasks/iiif/manifest.rb
118
- - lib/wax_tasks/image_collection.rb
119
- - lib/wax_tasks/local_branch.rb
120
- - lib/wax_tasks/lunr/index.rb
121
- - lib/wax_tasks/lunr/page_set.rb
122
- - lib/wax_tasks/pagemaster_collection.rb
123
- - lib/wax_tasks/task_runner.rb
124
- - lib/wax_tasks/travis_branch.rb
122
+ - lib/wax_tasks/index.rb
123
+ - lib/wax_tasks/item.rb
124
+ - lib/wax_tasks/record.rb
125
+ - lib/wax_tasks/site.rb
125
126
  - lib/wax_tasks/utils.rb
126
127
  - spec/setup.rb
127
128
  - spec/spec_helper.rb
128
129
  homepage: https://github.com/minicomp/wax_tasks
129
130
  licenses:
130
131
  - MIT
131
- metadata: {}
132
+ metadata:
133
+ yard.run: yri
132
134
  post_install_message:
133
135
  rdoc_options: []
134
136
  require_paths:
@@ -137,12 +139,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
139
  requirements:
138
140
  - - ">="
139
141
  - !ruby/object:Gem::Version
140
- version: '0'
142
+ version: '2.4'
141
143
  required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  requirements:
143
- - - ">"
145
+ - - ">="
144
146
  - !ruby/object:Gem::Version
145
- version: 1.3.1
147
+ version: '0'
146
148
  requirements:
147
149
  - imagemagick
148
150
  - ghostscript