wax_tasks 0.0.46 → 0.0.47
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 +4 -4
- data/lib/modules/iiif.rb +49 -0
- data/lib/modules/lunr.rb +107 -0
- data/lib/modules/pagemaster.rb +68 -0
- data/lib/tasks/iiif.rake +4 -48
- data/lib/tasks/jspackage.rake +4 -4
- data/lib/tasks/lunr.rake +2 -21
- data/lib/tasks/pagemaster.rake +5 -9
- data/lib/tasks/push_gh.rake +7 -4
- data/lib/tasks/push_s3.rake +3 -3
- data/lib/wax_tasks.rb +46 -3
- data/spec/spec_helper.rb +70 -1
- metadata +25 -27
- data/lib/wax_tasks/collection.rb +0 -81
- data/lib/wax_tasks/helpers.rb +0 -38
- data/lib/wax_tasks/lunr.rb +0 -74
- data/spec/test_tasks.rb +0 -44
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2eb86783ae6e09758e23af201aad5907f68d0f7ee0034d46bd168830264d9a74
         | 
| 4 | 
            +
              data.tar.gz: a1261162881c112780ff5d342cc265389b2bffdc121952d123b1176f36dc31ac
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c6c7e4e7874f80c9073b51865ab46f1c39d01cc3993531df218d17f87badb2d242a36aa9346a7a7e237c664ccf9bfb6b95f180fd92f0ee230486eafc7e6058d4
         | 
| 7 | 
            +
              data.tar.gz: ce6b90ea4d1cbf605e162a797c62d2aee01d15eeffdc980989661f9c68f746d1fe35064abd00c3fe70649520391630d41a8ae76a90899be66bdc0e1cd40ef375
         | 
    
        data/lib/modules/iiif.rb
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
            require 'wax_iiif'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # module for generating IIIF derivatives + json from local images
         | 
| 5 | 
            +
            module Iiif
         | 
| 6 | 
            +
              include FileUtils
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def self.ingest_collections(args, site_config)
         | 
| 9 | 
            +
                mkdir_p('./iiif', :verbose => false)
         | 
| 10 | 
            +
                all_records = []
         | 
| 11 | 
            +
                id_counter = 0
         | 
| 12 | 
            +
                build_opts = Iiif.build_options(site_config)
         | 
| 13 | 
            +
                args.each do |a|
         | 
| 14 | 
            +
                  id_counter += 1
         | 
| 15 | 
            +
                  inpath = './_data/iiif/' + a
         | 
| 16 | 
            +
                  abort "Source path '#{inpath}' does not exist. Exiting.".magenta unless Dir.exist?(inpath)
         | 
| 17 | 
            +
                  collection_records = make_records(a, inpath)
         | 
| 18 | 
            +
                  all_records.concat collection_records
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
                builder = IiifS3::Builder.new(build_opts)
         | 
| 21 | 
            +
                builder.load(all_records)
         | 
| 22 | 
            +
                builder.process_data
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def self.build_options(site_config)
         | 
| 26 | 
            +
                {
         | 
| 27 | 
            +
                  :base_url => site_config['baseurl'] + '/iiif',
         | 
| 28 | 
            +
                  :output_dir => './iiif',
         | 
| 29 | 
            +
                  :verbose => true
         | 
| 30 | 
            +
                }
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def self.make_records(arg, inpath)
         | 
| 34 | 
            +
                counter = 1
         | 
| 35 | 
            +
                records = []
         | 
| 36 | 
            +
                imagefiles = Dir[inpath + '/*'].sort!
         | 
| 37 | 
            +
                imagefiles.each do |imagefile|
         | 
| 38 | 
            +
                  basename = File.basename(imagefile, '.*').to_s
         | 
| 39 | 
            +
                  record_opts = {
         | 
| 40 | 
            +
                    :id => arg + '-' + basename,
         | 
| 41 | 
            +
                    :path => imagefile,
         | 
| 42 | 
            +
                    :label => arg + ' - ' + basename
         | 
| 43 | 
            +
                  }
         | 
| 44 | 
            +
                  counter += 1
         | 
| 45 | 
            +
                  records << IiifS3::ImageRecord.new(record_opts)
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
                records
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
            end
         | 
    
        data/lib/modules/lunr.rb
    ADDED
    
    | @@ -0,0 +1,107 @@ | |
| 1 | 
            +
            include FileUtils
         | 
| 2 | 
            +
            require 'json'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # module for generating elasticlunr index and default jquery ui
         | 
| 5 | 
            +
            module Lunr
         | 
| 6 | 
            +
              def self.total_fields(collections)
         | 
| 7 | 
            +
                total_fields = ['pid']
         | 
| 8 | 
            +
                collections.each do |c|
         | 
| 9 | 
            +
                  total_fields = total_fields.concat(c[1]['lunr_index']['fields'])
         | 
| 10 | 
            +
                  total_fields << 'content' if c[1]['lunr_index']['content']
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                total_fields.uniq
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def self.collections(site_config)
         | 
| 16 | 
            +
                site_config['collections'].find_all { |c| c[1].key?('lunr_index') && c[1]['lunr_index'].key?('fields') }
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def self.index(cdir, collections)
         | 
| 20 | 
            +
                index = []
         | 
| 21 | 
            +
                count = 0
         | 
| 22 | 
            +
                abort 'There are no valid collections to index.'.magenta if collections.nil?
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                collections.each do |c|
         | 
| 25 | 
            +
                  dir = cdir + '_' + c[0]
         | 
| 26 | 
            +
                  fields = c[1]['lunr_index']['fields'].uniq
         | 
| 27 | 
            +
                  pages = Dir.glob(dir + '/*.md')
         | 
| 28 | 
            +
                  get_content = c[1]['lunr_index']['content']
         | 
| 29 | 
            +
                  # catch
         | 
| 30 | 
            +
                  abort "There are no markdown pages in directory '#{dir}'".magenta if pages.empty?
         | 
| 31 | 
            +
                  abort "There are no fields specified for #{c[0]}.".magenta if fields.empty?
         | 
| 32 | 
            +
                  puts "Loading #{pages.length} pages from #{dir}"
         | 
| 33 | 
            +
                  # index each page in collection
         | 
| 34 | 
            +
                  pages.each do |page|
         | 
| 35 | 
            +
                    index << page_hash(page, fields, get_content, count)
         | 
| 36 | 
            +
                    count += 1
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
                JSON.pretty_generate(index)
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              def self.page_hash(page, fields, get_content, count)
         | 
| 43 | 
            +
                yaml = YAML.load_file(page)
         | 
| 44 | 
            +
                hash = {
         | 
| 45 | 
            +
                  'lunr_id' => count,
         | 
| 46 | 
            +
                  'link' => "{{'" + yaml.fetch('permalink') + "' | relative_url }}"
         | 
| 47 | 
            +
                }
         | 
| 48 | 
            +
                fields.each { |f| hash[f] = rm_diacritics(thing2string(yaml[f])) }
         | 
| 49 | 
            +
                hash['content'] = rm_diacritics(clean(File.read(page))) if get_content
         | 
| 50 | 
            +
                hash
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              def self.ui(total_fields)
         | 
| 54 | 
            +
                # set up index
         | 
| 55 | 
            +
                ui_string = "$.getJSON(\"{{ site.baseurl }}/js/lunr-index.json\", function(index_json) {\nwindow.index = new elasticlunr.Index;\nwindow.store = index_json;\nindex.saveDocument(false);\nindex.setRef('lunr_id');"
         | 
| 56 | 
            +
                # add fields to index
         | 
| 57 | 
            +
                total_fields.each { |field| ui_string += "\nindex.addField('#{field}');" }
         | 
| 58 | 
            +
                # add docs
         | 
| 59 | 
            +
                ui_string += "\n// add docs\nfor (i in store){index.addDoc(store[i]);}"
         | 
| 60 | 
            +
                # gui
         | 
| 61 | 
            +
                ui_string += "\n$('input#search').on('keyup', function() {\nvar results_div = $('#results');\nvar query = $(this).val();\nvar results = index.search(query, { boolean: 'AND', expand: true });\nresults_div.empty();\nif (results.length > 10) {\nresults_div.prepend(\"<p><small>Displaying 10 of \" + results.length + \" results.</small></p>\");\n}\nfor (var r in results.slice(0, 9)) {\nvar ref = results[r].ref;\nvar item = store[ref];"
         | 
| 62 | 
            +
                # add fields as display vars
         | 
| 63 | 
            +
                total_fields.each { |field| ui_string += "var #{field} = item.#{field};\n" }
         | 
| 64 | 
            +
                ui_string += "var result = '<div class=\"result\"><b><a href=\"' + item.link + '\">' + title + '</a></b></p></div>';\nresults_div.append(result);\n}\n});\n});"
         | 
| 65 | 
            +
                ui_string
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              def self.write_index(index)
         | 
| 69 | 
            +
                mkdir_p('js')
         | 
| 70 | 
            +
                index = "---\nlayout: none\n---\n" + index
         | 
| 71 | 
            +
                path = 'js/lunr-index.json'
         | 
| 72 | 
            +
                File.open(path, 'w') { |file| file.write(index) }
         | 
| 73 | 
            +
                puts "Writing lunr index to #{path}".cyan
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              def self.write_ui(ui)
         | 
| 77 | 
            +
                ui = "---\nlayout: none\n---\n" + ui
         | 
| 78 | 
            +
                path = 'js/lunr-ui.js'
         | 
| 79 | 
            +
                if File.exist?(path)
         | 
| 80 | 
            +
                  puts "Lunr UI already exists at #{path}. Skipping".cyan
         | 
| 81 | 
            +
                else
         | 
| 82 | 
            +
                  File.open(path, 'w') { |file| file.write(ui) }
         | 
| 83 | 
            +
                  puts "Writing lunr ui to #{path}".cyan
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              def self.clean(str)
         | 
| 88 | 
            +
                str.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
         | 
| 89 | 
            +
                str.gsub!(/{%(.*)%}/, '') # remove functional liquid
         | 
| 90 | 
            +
                str.gsub!(/<\/?[^>]*>/, '') # remove html
         | 
| 91 | 
            +
                str.gsub!('\\n', '') # remove newlines
         | 
| 92 | 
            +
                str.gsub!(/\s+/, ' ') # remove extra space
         | 
| 93 | 
            +
                str.tr!('"', "'") # replace double quotes with single
         | 
| 94 | 
            +
                str
         | 
| 95 | 
            +
              end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
              def self.rm_diacritics(str)
         | 
| 98 | 
            +
                to_replace  = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž'
         | 
| 99 | 
            +
                replaced_by = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz'
         | 
| 100 | 
            +
                str.tr(to_replace, replaced_by)
         | 
| 101 | 
            +
              end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
              def self.thing2string(thing)
         | 
| 104 | 
            +
                thing = thing.join(' || ') if thing.is_a?(Array)
         | 
| 105 | 
            +
                thing.to_s
         | 
| 106 | 
            +
              end
         | 
| 107 | 
            +
            end
         | 
| @@ -0,0 +1,68 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
            require 'yaml'
         | 
| 3 | 
            +
            require 'csv'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            # module for generating markdown collection pages from csv/json/yaml records
         | 
| 6 | 
            +
            module Pagemaster
         | 
| 7 | 
            +
              include FileUtils
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def self.valid_config(name, site_config)
         | 
| 10 | 
            +
                abort "Cannot find #{name} in _config.yml. Exiting.".magenta unless site_config['collections'].key?(name)
         | 
| 11 | 
            +
                collection_config = site_config['collections'][name]
         | 
| 12 | 
            +
                abort "Cannot find source for '#{name}'. Exiting.".magenta unless collection_config['source']
         | 
| 13 | 
            +
                abort "Cannot find layout for '#{name}'. Exiting.".magenta unless collection_config['layout']
         | 
| 14 | 
            +
                abort "Cannot find the file _data/#{collection_config['source']}.".magenta unless File.file?('_data/' + collection_config['source'])
         | 
| 15 | 
            +
                collection_config
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def self.ingest(src)
         | 
| 19 | 
            +
                src = "_data/#{src}"
         | 
| 20 | 
            +
                case File.extname(src)
         | 
| 21 | 
            +
                when '.csv' then data = CSV.read(src, :headers => true, :encoding => 'utf-8').map(&:to_hash)
         | 
| 22 | 
            +
                when '.json' then data = JSON.parse(File.read(src))
         | 
| 23 | 
            +
                when '.yml' then data = YAML.load_file(src)
         | 
| 24 | 
            +
                else abort "File type for #{src} must be .csv, .json, or .yml. Please fix and rerun."
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
                puts "Processing #{src}...."
         | 
| 27 | 
            +
                detect_duplicates(data)
         | 
| 28 | 
            +
                data
         | 
| 29 | 
            +
              rescue StandardError
         | 
| 30 | 
            +
                puts "Cannot load #{src}. check for typos and rebuild.".magenta
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def self.generate_pages(data, name, layout, cdir, order, perma)
         | 
| 34 | 
            +
                dir = cdir + '_' + name
         | 
| 35 | 
            +
                mkdir_p(dir)
         | 
| 36 | 
            +
                completed = 0
         | 
| 37 | 
            +
                skipped = 0
         | 
| 38 | 
            +
                data.each_with_index do |item, index|
         | 
| 39 | 
            +
                  pagename = WaxTasks.slug(item.fetch('pid'))
         | 
| 40 | 
            +
                  pagepath = dir + '/' + pagename + '.md'
         | 
| 41 | 
            +
                  if File.exist?(pagepath)
         | 
| 42 | 
            +
                    puts "#{pagename}.md already exits. Skipping."
         | 
| 43 | 
            +
                    skipped += 1
         | 
| 44 | 
            +
                  else
         | 
| 45 | 
            +
                    item['permalink'] = '/' + name + '/' + pagename + perma
         | 
| 46 | 
            +
                    item['layout'] = layout
         | 
| 47 | 
            +
                    item['order'] = padded_int(index, data.length) if order
         | 
| 48 | 
            +
                    File.open(pagepath, 'w') { |f| f.write(item.to_yaml.to_s + '---') }
         | 
| 49 | 
            +
                    completed += 1
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
                puts "\n#{completed} pages were generated to #{dir} directory.".cyan
         | 
| 53 | 
            +
                puts "\n#{skipped} pre-existing items were skipped.".cyan
         | 
| 54 | 
            +
              rescue StandardError
         | 
| 55 | 
            +
                abort "#{completed} pages were generated before failure, most likely a record is missing a valid 'pid' value.".magenta
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              def self.detect_duplicates(data)
         | 
| 59 | 
            +
                pids = []
         | 
| 60 | 
            +
                data.each { |d| pids << d['pid'] }
         | 
| 61 | 
            +
                duplicates = pids.detect { |p| pids.count(p) > 1 } || []
         | 
| 62 | 
            +
                abort "\nYour collection has the following duplicate pids: \n#{duplicates}".magenta unless duplicates.empty?
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              def self.padded_int(index, max_idx)
         | 
| 66 | 
            +
                index.to_s.rjust(Math.log10(max_idx).to_i + 1, '0')
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
    
        data/lib/tasks/iiif.rake
    CHANGED
    
    | @@ -4,53 +4,9 @@ require 'wax_iiif' | |
| 4 4 |  | 
| 5 5 | 
             
            namespace :wax do
         | 
| 6 6 | 
             
              task :iiif do
         | 
| 7 | 
            -
                 | 
| 8 | 
            -
                 | 
| 9 | 
            -
             | 
| 10 | 
            -
                 | 
| 11 | 
            -
             | 
| 12 | 
            -
                mkdir_p('./iiif')
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                all_records = []
         | 
| 15 | 
            -
                id_counter = 0
         | 
| 16 | 
            -
                build_opts = build_options(config)
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                argv.each do |a|
         | 
| 19 | 
            -
                  id_counter += 1
         | 
| 20 | 
            -
                  inpath = './_data/iiif/' + a
         | 
| 21 | 
            -
                  abort "Source path '#{inpath}' does not exist. Exiting.".magenta unless Dir.exist?(inpath)
         | 
| 22 | 
            -
                  paged = config['collections'][a]['iiif_paged'] == true
         | 
| 23 | 
            -
                  collection_records = make_records(a, inpath, paged, config)
         | 
| 24 | 
            -
                  all_records.concat collection_records
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
                builder = IiifS3::Builder.new(build_opts)
         | 
| 27 | 
            -
                builder.load(all_records)
         | 
| 28 | 
            -
                builder.process_data
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
            end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
            def build_options(config)
         | 
| 33 | 
            -
              {
         | 
| 34 | 
            -
                :base_url => config['baseurl'] + '/iiif',
         | 
| 35 | 
            -
                :output_dir => './iiif',
         | 
| 36 | 
            -
                :verbose => true
         | 
| 37 | 
            -
              }
         | 
| 38 | 
            -
            end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
            def make_records(collection_name, inpath, paged, config)
         | 
| 41 | 
            -
              counter = 1
         | 
| 42 | 
            -
              collection_records = []
         | 
| 43 | 
            -
              imagefiles = Dir[inpath + '/*'].sort!
         | 
| 44 | 
            -
              imagefiles.each do |imagefile|
         | 
| 45 | 
            -
                basename = File.basename(imagefile, '.*').to_s
         | 
| 46 | 
            -
                record_opts = {
         | 
| 47 | 
            -
                  :id => collection_name + '-' + basename,
         | 
| 48 | 
            -
                  :is_document => paged,
         | 
| 49 | 
            -
                  :path => imagefile,
         | 
| 50 | 
            -
                  :label => config['title'] + ' - ' + collection_name + ' - ' + basename
         | 
| 51 | 
            -
                }
         | 
| 52 | 
            -
                counter += 1
         | 
| 53 | 
            -
                collection_records << IiifS3::ImageRecord.new(record_opts)
         | 
| 7 | 
            +
                args = ARGV.drop(1).each { |a| task a.to_sym }
         | 
| 8 | 
            +
                site_config = WaxTasks.config
         | 
| 9 | 
            +
                abort "You must specify a collections after 'bundle exec rake wax:iiif'.".magenta if args.empty?
         | 
| 10 | 
            +
                WaxTasks.iiif(args, site_config)
         | 
| 54 11 | 
             
              end
         | 
| 55 | 
            -
              collection_records
         | 
| 56 12 | 
             
            end
         | 
    
        data/lib/tasks/jspackage.rake
    CHANGED
    
    | @@ -4,15 +4,15 @@ require 'json' | |
| 4 4 | 
             
            namespace :wax do
         | 
| 5 5 | 
             
              desc 'write a simple package.json'
         | 
| 6 6 | 
             
              task :jspackage do
         | 
| 7 | 
            -
                 | 
| 7 | 
            +
                site_config = WaxTasks.config
         | 
| 8 8 | 
             
                package = {
         | 
| 9 | 
            -
                  'name'          =>  | 
| 9 | 
            +
                  'name'          => site_config['title'],
         | 
| 10 10 | 
             
                  'version'       => '1.0.0',
         | 
| 11 | 
            -
                  'description'   =>  | 
| 11 | 
            +
                  'description'   => site_config['description'],
         | 
| 12 12 | 
             
                  'dependencies'  => {}
         | 
| 13 13 | 
             
                }
         | 
| 14 14 | 
             
                names = []
         | 
| 15 | 
            -
                 | 
| 15 | 
            +
                site_config['js'].each do |dependency|
         | 
| 16 16 | 
             
                  name = dependency[0]
         | 
| 17 17 | 
             
                  names << name
         | 
| 18 18 | 
             
                  version = dependency[1]['version']
         | 
    
        data/lib/tasks/lunr.rake
    CHANGED
    
    | @@ -1,28 +1,9 @@ | |
| 1 1 | 
             
            require 'wax_tasks'
         | 
| 2 | 
            -
            require 'json'
         | 
| 3 2 |  | 
| 4 3 | 
             
            namespace :wax do
         | 
| 5 4 | 
             
              desc 'build lunr search index'
         | 
| 6 5 | 
             
              task :lunr do
         | 
| 7 | 
            -
                 | 
| 8 | 
            -
                 | 
| 9 | 
            -
                yaml = "---\nlayout: none\n---\n"
         | 
| 10 | 
            -
                lunr = Lunr.new(config)
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                # write index to json file
         | 
| 13 | 
            -
                idx = yaml + lunr.index
         | 
| 14 | 
            -
                idx_path = 'js/lunr-index.json'
         | 
| 15 | 
            -
                File.open(idx_path, 'w') { |file| file.write(idx) }
         | 
| 16 | 
            -
                puts "Writing lunr index to #{idx_path}".cyan
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                # write index.ui to js file
         | 
| 19 | 
            -
                ui = yaml + lunr.ui
         | 
| 20 | 
            -
                ui_path = 'js/lunr-ui.js'
         | 
| 21 | 
            -
                if File.exist?(ui_path)
         | 
| 22 | 
            -
                  puts "Lunr UI already exists at #{ui_path}. Skipping".cyan
         | 
| 23 | 
            -
                else
         | 
| 24 | 
            -
                  File.open(ui_path, 'w') { |file| file.write(ui) }
         | 
| 25 | 
            -
                  puts "Writing lunr index to #{ui_path}".cyan
         | 
| 26 | 
            -
                end
         | 
| 6 | 
            +
                site_config = WaxTasks.config
         | 
| 7 | 
            +
                WaxTasks.lunr(site_config)
         | 
| 27 8 | 
             
              end
         | 
| 28 9 | 
             
            end
         | 
    
        data/lib/tasks/pagemaster.rake
    CHANGED
    
    | @@ -3,16 +3,12 @@ require 'wax_tasks' | |
| 3 3 | 
             
            namespace :wax do
         | 
| 4 4 | 
             
              desc 'generate collection md pages from yaml or csv data source'
         | 
| 5 5 | 
             
              task :pagemaster do
         | 
| 6 | 
            -
                 | 
| 7 | 
            -
                 | 
| 8 | 
            -
                if  | 
| 9 | 
            -
                   | 
| 10 | 
            -
                  exit 1
         | 
| 6 | 
            +
                args = ARGV.drop(1).each { |a| task a.to_sym }
         | 
| 7 | 
            +
                site_config = WaxTasks.config
         | 
| 8 | 
            +
                if args.empty?
         | 
| 9 | 
            +
                  abort "You must specify one or more collections after 'rake wax:pagemaster' to generate.".magenta
         | 
| 11 10 | 
             
                else
         | 
| 12 | 
            -
                   | 
| 13 | 
            -
                    collection = Collection.new(config, name)
         | 
| 14 | 
            -
                    collection.pagemaster
         | 
| 15 | 
            -
                  end
         | 
| 11 | 
            +
                  args.each { |a| WaxTasks.pagemaster(a, site_config) }
         | 
| 16 12 | 
             
                end
         | 
| 17 13 | 
             
              end
         | 
| 18 14 | 
             
            end
         | 
    
        data/lib/tasks/push_gh.rake
    CHANGED
    
    | @@ -8,7 +8,8 @@ namespace :wax do | |
| 8 8 | 
             
                task :gh do
         | 
| 9 9 | 
             
                  if ENV['CI']
         | 
| 10 10 | 
             
                    REPO_SLUG = ENV['TRAVIS_REPO_SLUG']
         | 
| 11 | 
            -
                    USER = REPO_SLUG.split( | 
| 11 | 
            +
                    USER = REPO_SLUG.split('/')[0]
         | 
| 12 | 
            +
                    REPO_NAME = '1' + REPO_SLUG.split('/')[1]
         | 
| 12 13 | 
             
                    TOKEN = ENV['ACCESS_TOKEN']
         | 
| 13 14 | 
             
                    COMMIT_MSG = "Site updated via #{ENV['TRAVIS_COMMIT']}".freeze
         | 
| 14 15 | 
             
                    ORIGIN = "https://#{USER}:#{TOKEN}@github.com/#{REPO_SLUG}.git".freeze
         | 
| @@ -16,16 +17,18 @@ namespace :wax do | |
| 16 17 | 
             
                  else
         | 
| 17 18 | 
             
                    ORIGIN = `git config --get remote.origin.url`.freeze
         | 
| 18 19 | 
             
                    COMMIT_MSG = "Site updated at #{Time.now.utc}".freeze
         | 
| 19 | 
            -
                    puts  | 
| 20 | 
            +
                    puts 'Deploying to gh-pages branch from local task'
         | 
| 20 21 | 
             
                  end
         | 
| 21 22 | 
             
                  config = read_config
         | 
| 22 23 | 
             
                  rm_rf('_site')
         | 
| 23 24 |  | 
| 25 | 
            +
                  baseurl = config['gh-baseurl'] || REPO_NAME.to_s
         | 
| 26 | 
            +
             | 
| 24 27 | 
             
                  opts = {
         | 
| 25 28 | 
             
                    'source' => '.',
         | 
| 26 29 | 
             
                    'destination' => '_site',
         | 
| 27 30 | 
             
                    'config' => '_config.yml',
         | 
| 28 | 
            -
                    'baseurl' =>  | 
| 31 | 
            +
                    'baseurl' => baseurl
         | 
| 29 32 | 
             
                  }
         | 
| 30 33 |  | 
| 31 34 | 
             
                  Jekyll::Site.new(Jekyll.configuration(opts)).process
         | 
| @@ -34,7 +37,7 @@ namespace :wax do | |
| 34 37 | 
             
                    Dir.chdir tmp
         | 
| 35 38 | 
             
                    system 'git init'
         | 
| 36 39 | 
             
                    system "git add . && git commit -m '#{COMMIT_MSG}'"
         | 
| 37 | 
            -
                    system  | 
| 40 | 
            +
                    system "git remote add origin #{ORIGIN}"
         | 
| 38 41 | 
             
                    system 'git push origin master:refs/heads/gh-pages --force'
         | 
| 39 42 | 
             
                  end
         | 
| 40 43 | 
             
                end
         | 
    
        data/lib/tasks/push_s3.rake
    CHANGED
    
    | @@ -7,7 +7,7 @@ namespace :wax do | |
| 7 7 | 
             
                task :s3 do
         | 
| 8 8 | 
             
                  if ENV['CI']
         | 
| 9 9 | 
             
                    REPO_SLUG = ENV['TRAVIS_REPO_SLUG']
         | 
| 10 | 
            -
                    USER = REPO_SLUG.split( | 
| 10 | 
            +
                    USER = REPO_SLUG.split('/')[0]
         | 
| 11 11 | 
             
                    TOKEN = ENV['ACCESS_TOKEN']
         | 
| 12 12 | 
             
                    COMMIT_MSG = "Site updated via #{ENV['TRAVIS_COMMIT']}".freeze
         | 
| 13 13 | 
             
                    ORIGIN = "https://#{USER}:#{TOKEN}@github.com/#{REPO_SLUG}.git".freeze
         | 
| @@ -15,7 +15,7 @@ namespace :wax do | |
| 15 15 | 
             
                  else
         | 
| 16 16 | 
             
                    ORIGIN = `git config --get remote.origin.url`.freeze
         | 
| 17 17 | 
             
                    COMMIT_MSG = "Site updated at #{Time.now.utc}".freeze
         | 
| 18 | 
            -
                    puts  | 
| 18 | 
            +
                    puts 'Deploying to s3 branch from local task'
         | 
| 19 19 | 
             
                  end
         | 
| 20 20 |  | 
| 21 21 | 
             
                  Dir.mktmpdir do |tmp|
         | 
| @@ -23,7 +23,7 @@ namespace :wax do | |
| 23 23 | 
             
                    Dir.chdir tmp
         | 
| 24 24 | 
             
                    system 'git init'
         | 
| 25 25 | 
             
                    system "git add . && git commit -m '#{COMMIT_MSG}'"
         | 
| 26 | 
            -
                    system  | 
| 26 | 
            +
                    system "git remote add origin #{ORIGIN}"
         | 
| 27 27 | 
             
                    system 'git push origin master:refs/heads/s3 --force'
         | 
| 28 28 | 
             
                  end
         | 
| 29 29 | 
             
                end
         | 
    
        data/lib/wax_tasks.rb
    CHANGED
    
    | @@ -1,3 +1,46 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 1 | 
            +
            require_relative 'modules/iiif'
         | 
| 2 | 
            +
            require_relative 'modules/lunr'
         | 
| 3 | 
            +
            require_relative 'modules/pagemaster'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'yaml'
         | 
| 6 | 
            +
            require 'wax_iiif'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # umbrella module for registering task modules
         | 
| 9 | 
            +
            module WaxTasks
         | 
| 10 | 
            +
              def self.pagemaster(name, site_config)
         | 
| 11 | 
            +
                collection_config = Pagemaster.valid_config(name, site_config)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                src     = collection_config['source']
         | 
| 14 | 
            +
                data    = Pagemaster.ingest(src)
         | 
| 15 | 
            +
                layout  = collection_config.fetch('layout').to_s
         | 
| 16 | 
            +
                perma   = config['permalink'] == 'pretty' ? '/' : '.html'
         | 
| 17 | 
            +
                cdir    = site_config['collections_dir'].to_s
         | 
| 18 | 
            +
                order   = collection_config.key?('keep_order') ? collection_config.fetch('keep_order') : false
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                Pagemaster.generate_pages(data, name, layout, cdir, order, perma)
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def self.lunr(site_config)
         | 
| 24 | 
            +
                cdir          = site_config['collections_dir'].to_s
         | 
| 25 | 
            +
                collections   = Lunr.collections(site_config)
         | 
| 26 | 
            +
                total_fields  = Lunr.total_fields(collections)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                index         = Lunr.index(cdir, collections)
         | 
| 29 | 
            +
                ui            = Lunr.ui(total_fields)
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                Lunr.write_index(index)
         | 
| 32 | 
            +
                Lunr.write_ui(ui)
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              def self.iiif(args, site_config)
         | 
| 36 | 
            +
                Iiif.ingest_collections(args, site_config)
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              def self.config
         | 
| 40 | 
            +
                YAML.load_file('_config.yml')
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              def self.slug(str)
         | 
| 44 | 
            +
                str.downcase.tr(' ', '_').gsub(/[^:\w-]/, '')
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1 +1,70 @@ | |
| 1 | 
            -
            require ' | 
| 1 | 
            +
            require 'fileutils'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative 'fake/data'
         | 
| 4 | 
            +
            require_relative 'fake/site'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
         | 
| 7 | 
            +
            require 'wax_tasks'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Fake.site
         | 
| 10 | 
            +
            Fake.data
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            describe 'wax:pagemaster' do
         | 
| 13 | 
            +
              config = WaxTasks.config
         | 
| 14 | 
            +
              args = config['collections'].map { |c| c[0] }
         | 
| 15 | 
            +
              system("bundle exec rake wax:pagemaster #{args.join(' ')} > /dev/null")
         | 
| 16 | 
            +
              it 'generates directories' do
         | 
| 17 | 
            +
                args.each { |a| expect(Dir.exist?('_' + a)) }
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
              it 'generates pages' do
         | 
| 20 | 
            +
                args.each { |a| expect(Dir.glob("_#{a}/*.md")) }
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            describe 'wax:lunr' do
         | 
| 25 | 
            +
              system('bundle exec rake wax:lunr > /dev/null')
         | 
| 26 | 
            +
              it 'generates a lunr index' do
         | 
| 27 | 
            +
                index = File.open('js/lunr-index.json', 'r').read
         | 
| 28 | 
            +
                expect(index.length > 1000)
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              it 'generates a lunr ui' do
         | 
| 32 | 
            +
                ui = File.open('js/lunr-ui.js', 'r').read
         | 
| 33 | 
            +
                expect(ui.length > 100)
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            describe 'wax:iiif' do
         | 
| 38 | 
            +
              site_config = WaxTasks.config
         | 
| 39 | 
            +
              args = site_config['collections'].map { |c| c[0] }
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              it 'generates iiif tiles and data' do
         | 
| 42 | 
            +
                images = Dir.glob('./_data/iiif/*.jpg')
         | 
| 43 | 
            +
                site_config['collections'].each do |c|
         | 
| 44 | 
            +
                  new_dir = './_data/iiif/' + c[0]
         | 
| 45 | 
            +
                  mkdir_p(new_dir)
         | 
| 46 | 
            +
                  images.each { |f| cp(File.expand_path(f), new_dir) }
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
                rm_r(images)
         | 
| 49 | 
            +
                system("bundle exec rake wax:iiif #{args.first} > /dev/null")
         | 
| 50 | 
            +
                args.each { |a| expect(Dir.exist?('iiif/images' + a)) }
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
            end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            describe 'jekyll' do
         | 
| 55 | 
            +
              it 'builds successfully' do
         | 
| 56 | 
            +
                Bundler.with_clean_env { system('bundle exec jekyll build > /dev/null') }
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
            end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            describe 'wax:jspackage' do
         | 
| 61 | 
            +
              system('bundle exec rake wax:jspackage > /dev/null')
         | 
| 62 | 
            +
              it 'writes a package.json file' do
         | 
| 63 | 
            +
                package = File.open('package.json', 'r').read
         | 
| 64 | 
            +
                expect(package.length > 90)
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
            end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            describe 'wax:test' do
         | 
| 69 | 
            +
              it 'passes html-proofer' do system('bundle exec rake wax:test > /dev/null') end
         | 
| 70 | 
            +
            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: 0.0. | 
| 4 | 
            +
              version: 0.0.47
         | 
| 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-03- | 
| 11 | 
            +
            date: 2018-03-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: colorize
         | 
| @@ -30,112 +30,112 @@ dependencies: | |
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: '3 | 
| 33 | 
            +
                    version: '3'
         | 
| 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'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: jekyll
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 45 | 
             
                - - "~>"
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: '3 | 
| 47 | 
            +
                    version: '3'
         | 
| 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: '3 | 
| 54 | 
            +
                    version: '3'
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: rake
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 59 | 
             
                - - "~>"
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            -
                    version: '12 | 
| 61 | 
            +
                    version: '12'
         | 
| 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: '12 | 
| 68 | 
            +
                    version: '12'
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: wax_iiif
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                requirements:
         | 
| 73 | 
            -
                - - " | 
| 73 | 
            +
                - - ">="
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version: 0 | 
| 75 | 
            +
                    version: '0'
         | 
| 76 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: 0 | 
| 82 | 
            +
                    version: '0'
         | 
| 83 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 84 | 
             
              name: bundler
         | 
| 85 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
                requirements:
         | 
| 87 87 | 
             
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version: '1 | 
| 89 | 
            +
                    version: '1'
         | 
| 90 90 | 
             
              type: :development
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 94 | 
             
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version: '1 | 
| 96 | 
            +
                    version: '1'
         | 
| 97 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 98 | 
             
              name: faker
         | 
| 99 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 100 | 
             
                requirements:
         | 
| 101 101 | 
             
                - - "~>"
         | 
| 102 102 | 
             
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            -
                    version: '1 | 
| 103 | 
            +
                    version: '1'
         | 
| 104 104 | 
             
              type: :development
         | 
| 105 105 | 
             
              prerelease: false
         | 
| 106 106 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 107 | 
             
                requirements:
         | 
| 108 108 | 
             
                - - "~>"
         | 
| 109 109 | 
             
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            -
                    version: '1 | 
| 110 | 
            +
                    version: '1'
         | 
| 111 111 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 112 112 | 
             
              name: rspec
         | 
| 113 113 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 114 | 
             
                requirements:
         | 
| 115 115 | 
             
                - - "~>"
         | 
| 116 116 | 
             
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            -
                    version: '3 | 
| 117 | 
            +
                    version: '3'
         | 
| 118 118 | 
             
              type: :development
         | 
| 119 119 | 
             
              prerelease: false
         | 
| 120 120 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 121 | 
             
                requirements:
         | 
| 122 122 | 
             
                - - "~>"
         | 
| 123 123 | 
             
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            -
                    version: '3 | 
| 124 | 
            +
                    version: '3'
         | 
| 125 125 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 126 126 | 
             
              name: rubocop
         | 
| 127 127 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 128 | 
             
                requirements:
         | 
| 129 | 
            -
                - - " | 
| 129 | 
            +
                - - ">="
         | 
| 130 130 | 
             
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            -
                    version: '0. | 
| 131 | 
            +
                    version: '0.5'
         | 
| 132 132 | 
             
              type: :development
         | 
| 133 133 | 
             
              prerelease: false
         | 
| 134 134 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 135 | 
             
                requirements:
         | 
| 136 | 
            -
                - - " | 
| 136 | 
            +
                - - ">="
         | 
| 137 137 | 
             
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            -
                    version: '0. | 
| 138 | 
            +
                    version: '0.5'
         | 
| 139 139 | 
             
            description: Rake tasks for minimal iiif exhibition sites with Jekyll.
         | 
| 140 140 | 
             
            email:
         | 
| 141 141 | 
             
            - m.nyrop@columbia.edu
         | 
| @@ -144,6 +144,9 @@ extensions: [] | |
| 144 144 | 
             
            extra_rdoc_files: []
         | 
| 145 145 | 
             
            files:
         | 
| 146 146 | 
             
            - Gemfile
         | 
| 147 | 
            +
            - lib/modules/iiif.rb
         | 
| 148 | 
            +
            - lib/modules/lunr.rb
         | 
| 149 | 
            +
            - lib/modules/pagemaster.rb
         | 
| 147 150 | 
             
            - lib/tasks/iiif.rake
         | 
| 148 151 | 
             
            - lib/tasks/jspackage.rake
         | 
| 149 152 | 
             
            - lib/tasks/lunr.rake
         | 
| @@ -152,11 +155,7 @@ files: | |
| 152 155 | 
             
            - lib/tasks/push_s3.rake
         | 
| 153 156 | 
             
            - lib/tasks/test.rake
         | 
| 154 157 | 
             
            - lib/wax_tasks.rb
         | 
| 155 | 
            -
            - lib/wax_tasks/collection.rb
         | 
| 156 | 
            -
            - lib/wax_tasks/helpers.rb
         | 
| 157 | 
            -
            - lib/wax_tasks/lunr.rb
         | 
| 158 158 | 
             
            - spec/spec_helper.rb
         | 
| 159 | 
            -
            - spec/test_tasks.rb
         | 
| 160 159 | 
             
            homepage: https://github.com/mnyrop/wax_tasks
         | 
| 161 160 | 
             
            licenses:
         | 
| 162 161 | 
             
            - MIT
         | 
| @@ -183,4 +182,3 @@ specification_version: 4 | |
| 183 182 | 
             
            summary: Rake tasks for minimal exhibitions.
         | 
| 184 183 | 
             
            test_files:
         | 
| 185 184 | 
             
            - spec/spec_helper.rb
         | 
| 186 | 
            -
            - spec/test_tasks.rb
         | 
    
        data/lib/wax_tasks/collection.rb
    DELETED
    
    | @@ -1,81 +0,0 @@ | |
| 1 | 
            -
            include FileUtils
         | 
| 2 | 
            -
            require 'csv'
         | 
| 3 | 
            -
            require 'json'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            # initializes a wax collection for use with pagemaster,lunr,and iiif tasks
         | 
| 6 | 
            -
            class Collection
         | 
| 7 | 
            -
              def initialize(config, collection_name)
         | 
| 8 | 
            -
                @name   = collection_name
         | 
| 9 | 
            -
                @config = config
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                cdir = @config['collections_dir'].nil? ? '' : @config.fetch('collections_dir').to_s + '/'
         | 
| 12 | 
            -
                collection = valid_collection_config
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                @src    = '_data/' + collection.fetch('source')
         | 
| 15 | 
            -
                @layout = File.basename(collection.fetch('layout'), '.*')
         | 
| 16 | 
            -
                @dir    = cdir + '_' + @name
         | 
| 17 | 
            -
                @order  = collection.key?('keep_order') ? collection.fetch('keep_order') : false
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              def valid_collection_config
         | 
| 21 | 
            -
                c = @config['collections'][@name]
         | 
| 22 | 
            -
                abort "Cannot find the collection #{@name} in _config.yml. Exiting.".magenta if c.nil?
         | 
| 23 | 
            -
                abort "Cannot find 'source' for the collection '#{@name}' in _config.yml. Exiting.".magenta if c['source'].nil?
         | 
| 24 | 
            -
                abort "Cannot find 'layout' for the collection '#{@name}' in _config.yml. Exiting.".magenta if c['layout'].nil?
         | 
| 25 | 
            -
                abort "Cannot find the file '#{'_data/' + c['source']}'. Exiting.".magenta unless File.file?('_data/' + c['source'])
         | 
| 26 | 
            -
                c
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              def ingest(src)
         | 
| 30 | 
            -
                if File.extname(src) == '.csv'
         | 
| 31 | 
            -
                  data = CSV.read(src, :headers => true, :encoding => 'utf-8').map(&:to_hash)
         | 
| 32 | 
            -
                elsif File.extname(src) == '.json'
         | 
| 33 | 
            -
                  data = JSON.parse(File.read(@src).encode("UTF-8"))
         | 
| 34 | 
            -
                else
         | 
| 35 | 
            -
                  puts "File type for #{@src} must be .csv or .json. Please fix and rerun."
         | 
| 36 | 
            -
                  exit 1
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
                detect_duplicates(data)
         | 
| 39 | 
            -
                puts "Processing #{src}...."
         | 
| 40 | 
            -
                data
         | 
| 41 | 
            -
              rescue StandardError
         | 
| 42 | 
            -
                puts "Cannot load #{src}. check for typos and rebuild.".magenta
         | 
| 43 | 
            -
              end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
              def generate_pages(data)
         | 
| 46 | 
            -
                perma_ext = @config['permalink'] == 'pretty' ? '/' : '.html'
         | 
| 47 | 
            -
                completed = 0
         | 
| 48 | 
            -
                skipped = 0
         | 
| 49 | 
            -
                data.each_with_index do |item, index|
         | 
| 50 | 
            -
                  pagename = slug(item.fetch('pid'))
         | 
| 51 | 
            -
                  pagepath = @dir + '/' + pagename + '.md'
         | 
| 52 | 
            -
                  item['permalink'] = '/' + @name + '/' + pagename + perma_ext
         | 
| 53 | 
            -
                  item['layout'] = @layout
         | 
| 54 | 
            -
                  item['order'] = padded_int(index, data.length) if @order
         | 
| 55 | 
            -
                  if File.exist?(pagepath)
         | 
| 56 | 
            -
                    puts "#{pagename}.md already exits. Skipping."
         | 
| 57 | 
            -
                    skipped += 1
         | 
| 58 | 
            -
                  else
         | 
| 59 | 
            -
                    File.open(pagepath, 'w') { |file| file.write(item.to_yaml.to_s + '---') }
         | 
| 60 | 
            -
                    completed += 1
         | 
| 61 | 
            -
                  end
         | 
| 62 | 
            -
                end
         | 
| 63 | 
            -
                puts "\n#{completed} pages were generated to #{@dir} directory.".cyan
         | 
| 64 | 
            -
                puts "\n#{skipped} pre-existing items were skipped.".cyan
         | 
| 65 | 
            -
              rescue StandardError
         | 
| 66 | 
            -
                abort "#{completed} pages were generated before failure, most likely a record is missing a valid 'pid' value.".magenta
         | 
| 67 | 
            -
              end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
              def detect_duplicates(data)
         | 
| 70 | 
            -
                pids = []
         | 
| 71 | 
            -
                data.each { |d| pids << d['pid'] }
         | 
| 72 | 
            -
                duplicates = pids.detect { |p| pids.count(p) > 1 } || []
         | 
| 73 | 
            -
                raise "\nYour collection has the following duplicate ids. please fix and rerun.\n#{duplicates}".magenta unless duplicates.empty?
         | 
| 74 | 
            -
              end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
              def pagemaster
         | 
| 77 | 
            -
                mkdir_p(@dir)
         | 
| 78 | 
            -
                data = ingest(@src)
         | 
| 79 | 
            -
                generate_pages(data)
         | 
| 80 | 
            -
              end
         | 
| 81 | 
            -
            end
         | 
    
        data/lib/wax_tasks/helpers.rb
    DELETED
    
    | @@ -1,38 +0,0 @@ | |
| 1 | 
            -
            def clean(str)
         | 
| 2 | 
            -
              str.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
         | 
| 3 | 
            -
              str.gsub!(/{%(.*)%}/, '') # remove functional liquid
         | 
| 4 | 
            -
              str.gsub!(/<\/?[^>]*>/, '') # remove html
         | 
| 5 | 
            -
              str.gsub!('\\n', '') # remove newlines
         | 
| 6 | 
            -
              str.gsub!(/\s+/, ' ') # remove extra space
         | 
| 7 | 
            -
              str.tr!('"', "'") # replace double quotes with single
         | 
| 8 | 
            -
              str
         | 
| 9 | 
            -
            end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            def rm_diacritics(str)
         | 
| 12 | 
            -
              to_replace  = "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž"
         | 
| 13 | 
            -
              replaced_by = "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz"
         | 
| 14 | 
            -
              str.tr(to_replace, replaced_by)
         | 
| 15 | 
            -
            end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            def slug(str)
         | 
| 18 | 
            -
              str.downcase.tr(' ', '_').gsub(/[^:\w-]/, '')
         | 
| 19 | 
            -
            end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            def thing2string(thing)
         | 
| 22 | 
            -
              thing = thing.join(" || ") if thing.is_a?(Array)
         | 
| 23 | 
            -
              thing.to_s
         | 
| 24 | 
            -
            end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
            def read_config
         | 
| 27 | 
            -
              YAML.load_file('_config.yml')
         | 
| 28 | 
            -
            end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            def read_argv
         | 
| 31 | 
            -
              argv = ARGV.drop(1)
         | 
| 32 | 
            -
              argv.each { |a| task a.to_sym }
         | 
| 33 | 
            -
              argv
         | 
| 34 | 
            -
            end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
            def padded_int(index, max_idx)
         | 
| 37 | 
            -
              index.to_s.rjust(Math.log10(max_idx).to_i + 1, "0")
         | 
| 38 | 
            -
            end
         | 
    
        data/lib/wax_tasks/lunr.rb
    DELETED
    
    | @@ -1,74 +0,0 @@ | |
| 1 | 
            -
            include FileUtils
         | 
| 2 | 
            -
            require 'json'
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            # for generating Lunr Index and Lunr UI files
         | 
| 5 | 
            -
            class Lunr
         | 
| 6 | 
            -
              def initialize(config)
         | 
| 7 | 
            -
                @lunr_collections = collections_to_index(config['collections'])
         | 
| 8 | 
            -
                @total_fields     = total_fields(@lunr_collections)
         | 
| 9 | 
            -
                @lunr_language    = config['lunr_language']
         | 
| 10 | 
            -
                @collections_dir  = config['collections_dir'].nil? ? '' : config.fetch('collections_dir') + '/'
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              def collections_to_index(collections)
         | 
| 14 | 
            -
                collections.find_all { |c| c[1].key?('lunr_index') && c[1]['lunr_index'].key?('fields') }
         | 
| 15 | 
            -
              end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              def total_fields(collections)
         | 
| 18 | 
            -
                total_fields = ['pid']
         | 
| 19 | 
            -
                collections.each do |c|
         | 
| 20 | 
            -
                  total_fields = total_fields.concat(c[1]['lunr_index']['fields'])
         | 
| 21 | 
            -
                  total_fields << 'content' if c[1]['lunr_index']['content']
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
                total_fields.uniq
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              def page_hash(page, c_fields, collection, count)
         | 
| 27 | 
            -
                yaml = YAML.load_file(page)
         | 
| 28 | 
            -
                hash = {
         | 
| 29 | 
            -
                  'lunr_id' => count,
         | 
| 30 | 
            -
                  'link' => "{{'" + yaml.fetch('permalink') + "' | relative_url }}"
         | 
| 31 | 
            -
                }
         | 
| 32 | 
            -
                c_fields.each { |f| hash[f] = rm_diacritics(thing2string(yaml[f])) }
         | 
| 33 | 
            -
                hash['content'] = rm_diacritics(clean(File.read(page))) if collection[1]['lunr_index']['content']
         | 
| 34 | 
            -
                hash
         | 
| 35 | 
            -
              end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
              def index
         | 
| 38 | 
            -
                full_index = []
         | 
| 39 | 
            -
                count = 0
         | 
| 40 | 
            -
                # catch
         | 
| 41 | 
            -
                abort("There are no valid collections to index.".magenta) if @lunr_collections.nil?
         | 
| 42 | 
            -
                # index each lunr_collection
         | 
| 43 | 
            -
                @lunr_collections.each do |c|
         | 
| 44 | 
            -
                  c_dir = @collections_dir + '_' + c[0]
         | 
| 45 | 
            -
                  c_fields = c[1]['lunr_index']['fields'].uniq
         | 
| 46 | 
            -
                  c_pages = Dir.glob(c_dir + '/*.md')
         | 
| 47 | 
            -
                  # catch
         | 
| 48 | 
            -
                  abort "There are no markdown pages in directory '#{c_dir}'".magenta if c_pages.empty?
         | 
| 49 | 
            -
                  abort "There are no fields specified for #{c[0]}.".magenta if c_fields.empty?
         | 
| 50 | 
            -
                  puts "Loading #{c_pages.length} pages from #{c_dir}"
         | 
| 51 | 
            -
                  # index each page in collection
         | 
| 52 | 
            -
                  c_pages.each do |page|
         | 
| 53 | 
            -
                    full_index << page_hash(page, c_fields, c, count)
         | 
| 54 | 
            -
                    count += 1
         | 
| 55 | 
            -
                  end
         | 
| 56 | 
            -
                end
         | 
| 57 | 
            -
                JSON.pretty_generate(full_index)
         | 
| 58 | 
            -
              end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
              def ui
         | 
| 61 | 
            -
                # set up index
         | 
| 62 | 
            -
                ui_string = "$.getJSON(\"{{ site.baseurl }}/js/lunr-index.json\", function(index_json) {\nwindow.index = new elasticlunr.Index;\nwindow.store = index_json;\nindex.saveDocument(false);\nindex.setRef('lunr_id');"
         | 
| 63 | 
            -
                # add fields to index
         | 
| 64 | 
            -
                @total_fields.each { |field| ui_string += "\nindex.addField('#{field}');" }
         | 
| 65 | 
            -
                # add docs
         | 
| 66 | 
            -
                ui_string += "\n// add docs\nfor (i in store){index.addDoc(store[i]);}"
         | 
| 67 | 
            -
                # gui
         | 
| 68 | 
            -
                ui_string += "\n$('input#search').on('keyup', function() {\nvar results_div = $('#results');\nvar query = $(this).val();\nvar results = index.search(query, { boolean: 'AND', expand: true });\nresults_div.empty();\nif (results.length > 10) {\nresults_div.prepend(\"<p><small>Displaying 10 of \" + results.length + \" results.</small></p>\");\n}\nfor (var r in results.slice(0, 9)) {\nvar ref = results[r].ref;\nvar item = store[ref];"
         | 
| 69 | 
            -
                # add fields as display vars
         | 
| 70 | 
            -
                @total_fields.each { |field| ui_string += "var #{field} = item.#{field};\n" }
         | 
| 71 | 
            -
                ui_string += "var result = '<div class=\"result\"><b><a href=\"' + item.link + '\">' + title + '</a></b></p></div>';\nresults_div.append(result);\n}\n});\n});"
         | 
| 72 | 
            -
                ui_string
         | 
| 73 | 
            -
              end
         | 
| 74 | 
            -
            end
         | 
    
        data/spec/test_tasks.rb
    DELETED
    
    | @@ -1,44 +0,0 @@ | |
| 1 | 
            -
            require 'yaml'
         | 
| 2 | 
            -
            require 'fileutils'
         | 
| 3 | 
            -
            require 'fake/helpers'
         | 
| 4 | 
            -
            require 'fake/site'
         | 
| 5 | 
            -
            require 'fake/data'
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            # run + test wax:config
         | 
| 8 | 
            -
            describe 'wax_tasks' do
         | 
| 9 | 
            -
              Fake.site
         | 
| 10 | 
            -
              collection_data = Fake.data
         | 
| 11 | 
            -
              config = YAML.load_file('_config.yml')
         | 
| 12 | 
            -
              argv = collection_data.map { |col| col[0] }
         | 
| 13 | 
            -
              add_collections_to_config(argv, collection_data, config)
         | 
| 14 | 
            -
              add_lunr_data(config, collection_data)
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              it 'accesses _config.yml and argv' do
         | 
| 17 | 
            -
                expect(config.length)
         | 
| 18 | 
            -
                expect(argv.length)
         | 
| 19 | 
            -
              end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              it 'generates pages' do
         | 
| 22 | 
            -
                system("bundle exec rake wax:pagemaster #{argv.join(' ')}")
         | 
| 23 | 
            -
                argv.each { |a| expect(Dir.exist?('_' + a)) }
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              it 'generates a lunr index' do
         | 
| 27 | 
            -
                system("bundle exec rake wax:lunr")
         | 
| 28 | 
            -
                index = File.open('js/lunr-index.json', 'r').read
         | 
| 29 | 
            -
                ui = File.open('js/lunr-ui.js', 'r').read
         | 
| 30 | 
            -
                expect(index.length > 1000)
         | 
| 31 | 
            -
                expect(ui.length > 100)
         | 
| 32 | 
            -
              end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
              it 'generates iiif tiles and data' do
         | 
| 35 | 
            -
                images = Dir.glob('./_data/iiif/*.jpg')
         | 
| 36 | 
            -
                collection_data.each do |coll|
         | 
| 37 | 
            -
                  new_dir = './_data/iiif/' + coll[0]
         | 
| 38 | 
            -
                  mkdir_p(new_dir)
         | 
| 39 | 
            -
                  images.each { |f| cp(File.expand_path(f), new_dir) }
         | 
| 40 | 
            -
                end
         | 
| 41 | 
            -
                rm_r(images)
         | 
| 42 | 
            -
                system("bundle exec rake wax:iiif #{argv.first}")
         | 
| 43 | 
            -
              end
         | 
| 44 | 
            -
            end
         |