wax_tasks 1.1.2 → 1.1.4

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.

Potentially problematic release.


This version of wax_tasks might be problematic. Click here for more details.

@@ -1,151 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WaxTasks
4
- # Utility helper methods
5
- module Utils
6
- #
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
22
- end
23
-
24
- # Checks and asserts presence of `pid` value for each item
25
- #
26
- # @param data [Array] array of hashes each representing a collection item
27
- # @return [Array] same data unless a an item is missing the key `pid`
28
- # @raise WaxTasks::Error::MissingPid
29
- def self.assert_pids(data)
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
- data
32
- end
33
-
34
- # Checks and asserts uniqueness of `pid` value for each item
35
- #
36
- # @param data [Array] array of hashes each representing a collection item
37
- # @return [Array] same data unless an item has non-unique value for `pid`
38
- # @raise WaxTasks::Error::NonUniquePid
39
- def self.assert_unique(data)
40
- pids = data.map { |d| d['pid'] }
41
- not_unique = pids.select { |p| pids.count(p) > 1 }.uniq! || []
42
- raise Error::NonUniquePid, "#{@name} has the following nonunique pids:\n#{not_unique}" unless not_unique.empty?
43
-
44
- data
45
- end
46
-
47
- # Checks that a CSV file is valid
48
- #
49
- # @param source [String] path to CSV file
50
- # @return [Array] validated CSV data as an Array of Hashes
51
- # @raise WaxTasks::Error::InvalidCSV
52
- def self.validate_csv(source)
53
- CSV.read(source, headers: true).map(&:to_hash)
54
- rescue StandardError => e
55
- raise Error::InvalidCSV, " #{e}"
56
- end
57
-
58
- # Checks that a JSON file is valid
59
- #
60
- # @param source [String] path to JSON file
61
- # @return [Array] validated JSON data as an Array of Hashes
62
- # @raise WaxTasks::Error::InvalidJSON
63
- def self.validate_json(source)
64
- file = File.read source
65
- JSON.parse file
66
- rescue StandardError => e
67
- raise Error::InvalidJSON, " #{e}"
68
- end
69
-
70
- # Checks that a YAML file is valid
71
- #
72
- # @param source [String] path to YAML file
73
- # @return [Array] validated YAML data as an Array of Hashes
74
- # @raise WaxTasks::Error::InvalidYAML
75
- def self.validate_yaml(source)
76
- SafeYAML.load_file source
77
- rescue StandardError => e
78
- raise WaxTasks::Error::InvalidYAML, " #{e}"
79
- end
80
-
81
- # Removes YAML front matter from a string
82
- # @return [String]
83
- def self.remove_yaml(str)
84
- str.to_s.gsub!(/\A---(.|\n)*?---/, '')
85
- end
86
-
87
- # Scrubs yaml, liquid, html, and etc from content strings
88
- # @return [String]
89
- def self.content_clean(str)
90
- str.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
91
- str.gsub!(/{%(.*)%}/, '') # remove functional liquid
92
- str.gsub!(/{{.*}}/, '') # remove referential liquid
93
- str.gsub!(%r{</?[^>]*>}, '') # remove html
94
- str.gsub!('\\n', '') # remove newlines
95
- str.gsub!(/\s+/, ' ') # remove extra space
96
- str.tr!('"', "'") # replace double quotes with single
97
- str
98
- end
99
-
100
- # Normalizes accent marks/diacritics for Lunr indexing
101
- # @return [String]
102
- def self.remove_diacritics(str)
103
- to_replace = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž'
104
- replaced_by = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz'
105
- str.to_s.tr to_replace, replaced_by
106
- end
107
-
108
- # Converts string to snake case and swaps out special chars
109
- # @return [String]
110
- def self.slug(str)
111
- Utils.remove_diacritics(str).to_s.downcase.tr(' ', '_').gsub(/[^\w-]/, '')
112
- end
113
-
114
- #
115
- #
116
- def self.safe_join(*args)
117
- File.join(args.compact).sub %r{^/}, ''
118
- end
119
-
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
127
-
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
138
- end
139
-
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
144
-
145
- File.open(file, 'w') do |f|
146
- f.puts front_matter
147
- f.puts filestring
148
- end
149
- end
150
- end
151
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WaxTasks
4
- VERSION = '1.1.2'
5
- end
data/wax_tasks.gemspec DELETED
@@ -1,33 +0,0 @@
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