munge 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90a523f13c830272c0fb00314bff78658c2967c4
4
+ data.tar.gz: c7875ddc140b85157f5e248920d1d1a951f3a1d4
5
+ SHA512:
6
+ metadata.gz: 67093ea7b88f0a9fcf36970a1e29d268008d0958010c6fd9716183ec0480ab8e098a0426e8a7c5b0229293b29f768e03c791417bf27bb29e861a34cb62783d89
7
+ data.tar.gz: 138f51ff91d5cb37c9d805b0bc622654e4b66f06f4b54d3edc046e2a841298a7f65f2e41f62202a5e43be8c405dfb83e6dcd112bc408c3441d48e95109442ded
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/bundle/**/*
4
+ - Gemfile
5
+ - Rakefile
6
+
7
+ Style/AlignParameters:
8
+ Enabled: false
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/ClassAndModuleChildren:
14
+ Enabled: false
15
+
16
+ Style/IfUnlessModifier:
17
+ Enabled: false
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in munge.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Zach Ahn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Munge
2
+
3
+ Munge is a static site generator aiming to simplify complex build rules.
4
+
5
+ SemVer will be followed once 1.0.0 is released.
6
+ Until then,
7
+ the API should be considered experimental.
8
+
9
+
10
+ ## Usage
11
+
12
+ **Directory structure**
13
+
14
+ ```
15
+ dest/
16
+ src/
17
+ layouts/
18
+ layout.html
19
+ index.html
20
+ application.rb
21
+ config.yml
22
+ Gemfile
23
+ ```
24
+
25
+ **`application.rb`**
26
+
27
+ ```ruby
28
+ require "munge"
29
+
30
+ app = Munge::Application.new("./config.yml")
31
+
32
+ app.source
33
+ .reject { |item| item.path.relative =~ %r(^layouts/) }
34
+ .each { |item| item.route = item.path.dirname }
35
+ .map { |item| item.path.dirname }
36
+
37
+ app.write
38
+ ```
39
+
40
+ **`config.yml`**
41
+
42
+ ```yaml
43
+ ---
44
+ source: src
45
+ dest: dest
46
+ binary_extensions:
47
+ - jpg
48
+ - jpeg
49
+ - png
50
+ - gif
51
+ - ico
52
+ index: index.html
53
+ ```
54
+
55
+
56
+ ## Installation
57
+
58
+ Add this line to your application's Gemfile:
59
+
60
+ ```ruby
61
+ gem 'munge'
62
+ ```
63
+
64
+ And then execute:
65
+
66
+ $ bundle
67
+
68
+ Or install it yourself as:
69
+
70
+ $ gem install munge
71
+
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zachahn/munge.
76
+
77
+ Please open an issue before creating a pull request to discuss whether any new feature should be included as part of the core library or as an external plugin.
78
+
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/lib/munge.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "fileutils"
2
+ require "pathname"
3
+ require "yaml"
4
+
5
+ require "tilt"
6
+
7
+ require "munge/version"
8
+ require "munge/source"
9
+ require "munge/attribute/content"
10
+ require "munge/attribute/metadata"
11
+ require "munge/attribute/path"
12
+ require "munge/item"
13
+ require "munge/application"
14
+
15
+ module Munge
16
+ # Your code goes here...
17
+ end
@@ -0,0 +1,34 @@
1
+ module Munge
2
+ class Application
3
+ def initialize(config_path)
4
+ @config = YAML.load_file(File.expand_path(config_path))
5
+ @root = File.dirname(File.expand_path(config_path))
6
+
7
+ @source_dir = File.expand_path(@config["source"], @root)
8
+ @dest_dir = File.expand_path(@config["dest"], @root)
9
+
10
+ @source = Source.new(@source_dir)
11
+ end
12
+
13
+ attr_reader :source
14
+
15
+ def write
16
+ @source
17
+ .reject { |item| item.route.nil? }
18
+ .map { |item| [item, resolve_write_path(item)] }
19
+ .each { |_, dest_path| FileUtils.mkdir_p(File.dirname(dest_path)) }
20
+ .map { |item, dest_path| [item.rendered_output, dest_path] }
21
+ .each { |content, dest_path| File.write(dest_path, content) }
22
+ end
23
+
24
+ private
25
+
26
+ def resolve_write_path(item)
27
+ if item.route[-1] == "/"
28
+ File.join(@dest_dir, item.route, @config["index"])
29
+ else
30
+ File.join(@dest_dir, item.route)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ module Munge
2
+ module Attribute
3
+ class Content
4
+ def self.match(string)
5
+ string.match(/
6
+ # Start of string
7
+ \A
8
+ # Begin frontmatter
9
+ (?:^---\s*[\n\r]+)
10
+ # Capture frontmatter
11
+ (.*)
12
+ # End frontmatter
13
+ (?:^---\s*[\n\r]+)
14
+ /mx)
15
+ end
16
+
17
+ def self.parse(string)
18
+ matchdata = match(string)
19
+
20
+ [
21
+ parse_frontmatter(matchdata),
22
+ parse_content(matchdata, string)
23
+ ]
24
+ end
25
+
26
+ def self.parse_frontmatter(matchdata)
27
+ return {} if matchdata.nil?
28
+
29
+ parsed_frontmatter = YAML.load(matchdata[1])
30
+
31
+ if parsed_frontmatter
32
+ parsed_frontmatter
33
+ else
34
+ {}
35
+ end
36
+ end
37
+
38
+ def self.parse_content(matchdata, string)
39
+ if matchdata
40
+ matchdata.post_match
41
+ else
42
+ string
43
+ end
44
+ end
45
+
46
+ def initialize(string)
47
+ @frontmatter, @content = self.class.parse(string)
48
+ end
49
+
50
+ attr_accessor :frontmatter, :content
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,12 @@
1
+ module Munge
2
+ module Attribute
3
+ class Metadata
4
+ def initialize(abspath)
5
+ @abspath = abspath
6
+ @stat = File::Stat.new(abspath)
7
+ end
8
+
9
+ attr_reader :stat
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,44 @@
1
+ module Munge
2
+ module Attribute
3
+ class Path
4
+ def initialize(source_path, file_path)
5
+ @relative = resolve_relative(source_path, file_path).freeze
6
+ @absolute = file_path.dup.freeze
7
+ @basename = resolve_basename(file_path).freeze
8
+ @extnames = resolve_extnames(file_path).freeze
9
+ @dirname = resolve_dirname(@relative).freeze
10
+ end
11
+
12
+ attr_reader :relative, :absolute, :basename, :extnames, :dirname
13
+
14
+ private
15
+
16
+ def resolve_relative(source_path, file_path)
17
+ folder = Pathname.new(source_path)
18
+ file = Pathname.new(file_path)
19
+
20
+ file.relative_path_from(folder).to_s
21
+ end
22
+
23
+ def resolve_basename(file_path)
24
+ file_name = File.basename(file_path)
25
+ file_name_parts = file_name.split(".")
26
+
27
+ file_name_parts.first
28
+ end
29
+
30
+ def resolve_extnames(file_path)
31
+ file_name = File.basename(file_path)
32
+ file_name_parts = file_name.split(".")
33
+
34
+ file_name_parts[1..-1]
35
+ end
36
+
37
+ def resolve_dirname(relpath)
38
+ relpath_with_prefix_slash = File.join("/", relpath)
39
+ dirname = File.dirname(relpath_with_prefix_slash)
40
+ File.join(dirname[1..-1], "/")
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/munge/item.rb ADDED
@@ -0,0 +1,47 @@
1
+ module Munge
2
+ class Item
3
+ def self.create(source_abspath, file_abspath)
4
+ path = Munge::Attribute::Path.new(source_abspath, file_abspath)
5
+ content = Munge::Attribute::Content.new(File.read(file_abspath))
6
+ metadata = Munge::Attribute::Metadata.new(file_abspath)
7
+
8
+ new(path, content, metadata)
9
+ end
10
+
11
+ def initialize(path, content, metadata)
12
+ @path = path
13
+ @content = content
14
+ @metadata = metadata
15
+ @route = nil
16
+ @layout = nil
17
+ end
18
+
19
+ attr_reader :path, :metadata
20
+ attr_accessor :route, :layout
21
+
22
+ def content
23
+ @content.content
24
+ end
25
+
26
+ def content=(new_content)
27
+ @content.content = new_content
28
+ end
29
+
30
+ def info
31
+ @content.frontmatter
32
+ end
33
+
34
+ def rendered_content
35
+ Tilt
36
+ .templates_for(@path.relative)
37
+ .inject(content) do |content, engine|
38
+ renderer = engine.new { content }
39
+ renderer.render(nil, info)
40
+ end
41
+ end
42
+
43
+ def rendered_output
44
+ rendered_content
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,22 @@
1
+ module Munge
2
+ class Source
3
+ include Enumerable
4
+
5
+ def initialize(source_abspath)
6
+ @source_abspath = source_abspath
7
+ @pattern = File.join(source_abspath, "**", "*")
8
+
9
+ @items = Dir[@pattern]
10
+ .reject { |item_path| File.directory?(item_path) }
11
+ .map { |item_path| Item.create(source_abspath, item_path) }
12
+ end
13
+
14
+ def each
15
+ return enum_for(:each) unless block_given?
16
+
17
+ @items.each do |item|
18
+ yield item
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Munge
2
+ VERSION = "0.1.0"
3
+ end
data/munge.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "munge/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "munge"
8
+ spec.version = Munge::VERSION
9
+ spec.authors = ["Zach Ahn"]
10
+ spec.email = ["zach.ahn@gmail.com"]
11
+
12
+ spec.summary = "A piping-inspired static site generator"
13
+ spec.homepage = "https://github.com/zachahn/munge"
14
+ spec.license = "MIT"
15
+
16
+ spec.files =
17
+ `git ls-files -z`
18
+ .split("\x0")
19
+ .reject { |f| f.match(%r{^(test|spec|features|script)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.8"
27
+ spec.add_development_dependency "rubocop", "~> 0.32"
28
+
29
+ spec.add_runtime_dependency "tilt", "~> 2.0"
30
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: munge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zach Ahn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.32'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.32'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tilt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description:
84
+ email:
85
+ - zach.ahn@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/munge.rb
99
+ - lib/munge/application.rb
100
+ - lib/munge/attribute/content.rb
101
+ - lib/munge/attribute/metadata.rb
102
+ - lib/munge/attribute/path.rb
103
+ - lib/munge/item.rb
104
+ - lib/munge/source.rb
105
+ - lib/munge/version.rb
106
+ - munge.gemspec
107
+ homepage: https://github.com/zachahn/munge
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A piping-inspired static site generator
131
+ test_files: []