sew 0.0.0 → 0.0.1
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/bin/sew +42 -0
- data/lib/sew.rb +86 -1
- data/sew.gemspec +3 -0
- metadata +22 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: bbd38e4fef9c18d3d7887846e2bb9b4416ca8b04
         | 
| 4 | 
            +
              data.tar.gz: '08565ff4fc5003f45b38bfdc9ded55d09b092d0a'
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c4a358f2be9afac9d2b1129990b1d30f92272606f21a1ee402928cee4918f80c315ab36d619b21052b95c202fac96bedb1a45bbb64e5ad020286897cc6e1bd63
         | 
| 7 | 
            +
              data.tar.gz: 0b545a11def3fb7aae3933c1374b111e1741fb66ba31a461a0c667b5a586d59c8a388fce782cfdf89bd3524294a4d13c72784e4057dd7cb6bc3e95929d580e1b
         | 
    
        data/bin/sew
    ADDED
    
    | @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            help = <<-EOS
         | 
| 4 | 
            +
            SEW(1)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            NAME
         | 
| 7 | 
            +
                  sew -- Static, Elegant Websites
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            SYNOPSIS
         | 
| 10 | 
            +
                  sew COMMAND
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            DESCRIPTION
         | 
| 13 | 
            +
                  Use this command line tool to build static websites. The
         | 
| 14 | 
            +
                  following commands are available:
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  build
         | 
| 17 | 
            +
                      build the site, placing in the './build' directory.
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  clean
         | 
| 20 | 
            +
                      remove the './build' directory.
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  serve
         | 
| 23 | 
            +
                      serve the './build' directory after a fresh build. 
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            AUTHOR
         | 
| 26 | 
            +
                  Philip Poots
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            SEE ALSO
         | 
| 29 | 
            +
                  https://github.com/pootsbook/sew
         | 
| 30 | 
            +
            EOS
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            require "sew"
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            COMMANDS = %w(build clean serve)
         | 
| 35 | 
            +
            command = ARGV.shift
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            unless COMMANDS.include?(arg)
         | 
| 38 | 
            +
              puts help
         | 
| 39 | 
            +
              exit
         | 
| 40 | 
            +
            end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            Sew.send(arg)
         | 
    
        data/lib/sew.rb
    CHANGED
    
    | @@ -1,3 +1,88 @@ | |
| 1 | 
            +
            require "fileutils"
         | 
| 2 | 
            +
            require "ostruct"
         | 
| 3 | 
            +
            require "webrick"
         | 
| 4 | 
            +
            require "json"
         | 
| 5 | 
            +
            require "mote"
         | 
| 6 | 
            +
            require "yaml"
         | 
| 7 | 
            +
             | 
| 1 8 | 
             
            class Sew
         | 
| 2 | 
            -
              VERSION = "0.0. | 
| 9 | 
            +
              VERSION = "0.0.1"
         | 
| 10 | 
            +
              BUILD_DIR = "build"
         | 
| 11 | 
            +
              FILE_REGEX = /\A---\n(.+?)\n---\n(.*)/m
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def self.version
         | 
| 14 | 
            +
                puts VERSION
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def self.build
         | 
| 18 | 
            +
                clean
         | 
| 19 | 
            +
                pages = Dir["[^_]*.mote"].map do |template|
         | 
| 20 | 
            +
                  Hash.new.tap do |page|
         | 
| 21 | 
            +
                    page[:id], page[:locale] = File.basename(template, ".mote").split(".")
         | 
| 22 | 
            +
                    frontmatter, page[:body] = File.read(template).match(FILE_REGEX)[1..2]
         | 
| 23 | 
            +
                    page.merge!(YAML.load(frontmatter))
         | 
| 24 | 
            +
                    page[:path] = "%s.html" % (page["path"]&.tr(".", "/") || page[:id])
         | 
| 25 | 
            +
                    page[:destination] = "./%s/%s/%s" % [BUILD_DIR, page[:locale], page[:path]]
         | 
| 26 | 
            +
                    page[:destination_dir] = page[:destination].split("/")[0..-2].join("/") # build this up gradually using existing info
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
                data = Hash.new.tap do |dat|
         | 
| 30 | 
            +
                  Dir["*.yml"].map do |file|
         | 
| 31 | 
            +
                    dat[File.basename(file, ".yml")] = YAML.load_file(file)
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
                site = OpenStruct.new(JSON.parse({ pages: pages, data: data }.to_json, object_class: OpenStruct))
         | 
| 35 | 
            +
                context = Context.new(site)
         | 
| 36 | 
            +
                site.pages.map(&:destination_dir).uniq.each(&FileUtils.method(:mkpath))
         | 
| 37 | 
            +
                site.pages.each do |page|
         | 
| 38 | 
            +
                  File.open(page.destination, "w") do |file|
         | 
| 39 | 
            +
                    file.write context.render(page)
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              def self.clean
         | 
| 45 | 
            +
                FileUtils.rm_rf(BUILD_DIR)
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              def self.serve
         | 
| 49 | 
            +
                build
         | 
| 50 | 
            +
                root = File.expand_path(BUILD_DIR)
         | 
| 51 | 
            +
                server = WEBrick::HTTPServer.new(:Port => 4567, :DocumentRoot => root)
         | 
| 52 | 
            +
                trap('INT') { server.shutdown }
         | 
| 53 | 
            +
                server.start
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              class Context
         | 
| 57 | 
            +
                attr_reader :site
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def initialize(site)
         | 
| 60 | 
            +
                  if File.exist?(file = File.join(Dir.pwd, 'helper.rb'))
         | 
| 61 | 
            +
                    require file
         | 
| 62 | 
            +
                    extend Sew::Helper
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  @site= site
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                def render(page)
         | 
| 69 | 
            +
                  @site.page = page
         | 
| 70 | 
            +
                  @site.content = mote(page.body)
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  partial("_layout")
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                def mote(content)
         | 
| 76 | 
            +
                  Mote.parse(content, self, site.each_pair.map(&:first))[site]
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                def partial(template)
         | 
| 80 | 
            +
                  localized = sprintf("%s.%s.mote", template, site.page.locale)
         | 
| 81 | 
            +
                  if File.exist?(localized)
         | 
| 82 | 
            +
                    mote(File.read(localized))
         | 
| 83 | 
            +
                  else
         | 
| 84 | 
            +
                    mote(File.read(sprintf("%s.mote", template)))
         | 
| 85 | 
            +
                  end
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
              end
         | 
| 3 88 | 
             
            end
         | 
    
        data/sew.gemspec
    CHANGED
    
    | @@ -8,9 +8,12 @@ Gem::Specification.new do |s| | |
| 8 8 | 
             
              s.authors     = ["Philip Poots"]
         | 
| 9 9 | 
             
              s.email       = ["philip.poots@gmail.com"]
         | 
| 10 10 | 
             
              s.homepage    = "http://github.com/pootsbook/sew"
         | 
| 11 | 
            +
              s.license     = "MIT"
         | 
| 11 12 | 
             
              s.files = Dir[
         | 
| 12 13 | 
             
                "LICENSE",
         | 
| 13 14 | 
             
                "lib/**/*.rb",
         | 
| 14 15 | 
             
                "*.gemspec"
         | 
| 15 16 | 
             
              ]
         | 
| 17 | 
            +
              s.executables.push("sew")
         | 
| 18 | 
            +
              s.add_dependency "mote", "1.2.0"
         | 
| 16 19 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,27 +1,44 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sew
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Philip Poots
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 12 | 
            -
            dependencies: | 
| 11 | 
            +
            date: 2017-07-29 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: mote
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - '='
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 1.2.0
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - '='
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 1.2.0
         | 
| 13 27 | 
             
            description: Sew stitches together static sites
         | 
| 14 28 | 
             
            email:
         | 
| 15 29 | 
             
            - philip.poots@gmail.com
         | 
| 16 | 
            -
            executables: | 
| 30 | 
            +
            executables:
         | 
| 31 | 
            +
            - sew
         | 
| 17 32 | 
             
            extensions: []
         | 
| 18 33 | 
             
            extra_rdoc_files: []
         | 
| 19 34 | 
             
            files:
         | 
| 20 35 | 
             
            - LICENSE
         | 
| 36 | 
            +
            - bin/sew
         | 
| 21 37 | 
             
            - lib/sew.rb
         | 
| 22 38 | 
             
            - sew.gemspec
         | 
| 23 39 | 
             
            homepage: http://github.com/pootsbook/sew
         | 
| 24 | 
            -
            licenses: | 
| 40 | 
            +
            licenses:
         | 
| 41 | 
            +
            - MIT
         | 
| 25 42 | 
             
            metadata: {}
         | 
| 26 43 | 
             
            post_install_message: 
         | 
| 27 44 | 
             
            rdoc_options: []
         |