munge 0.4.0 → 0.5.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +10 -0
- data/Makefile +21 -0
- data/README.md +1 -1
- data/exe/munge +6 -0
- data/lib/munge/application.rb +11 -53
- data/lib/munge/bootstrap.rb +63 -0
- data/lib/munge/cli.rb +5 -17
- data/lib/munge/commands/view.rb +46 -0
- data/lib/munge/core/alterant.rb +2 -2
- data/lib/munge/core/collection.rb +1 -1
- data/lib/munge/core/item_factory/content_parser.rb +9 -13
- data/lib/munge/core/item_factory.rb +1 -24
- data/lib/munge/core/router/itemish.rb +22 -0
- data/lib/munge/core/router.rb +33 -42
- data/lib/munge/helper/capture.rb +24 -0
- data/lib/munge/helper/find.rb +4 -0
- data/lib/munge/helper/link.rb +6 -1
- data/lib/munge/helper/rendering.rb +0 -2
- data/lib/munge/item.rb +2 -2
- data/lib/munge/routers/add_index_html.rb +36 -0
- data/lib/munge/routers/auto_add_extension.rb +44 -0
- data/lib/munge/routers/fingerprint.rb +60 -0
- data/lib/munge/routers/remove_index_basename.rb +35 -0
- data/lib/munge/runner.rb +10 -6
- data/lib/munge/system.rb +54 -0
- data/lib/munge/transformer/tilt.rb +7 -3
- data/lib/munge/util/config.rb +28 -0
- data/lib/munge/util/path.rb +58 -0
- data/lib/munge/util/symbol_hash.rb +35 -0
- data/lib/munge/version.rb +1 -1
- data/lib/munge.rb +11 -4
- data/munge.gemspec +1 -0
- data/seeds/config.yml +1 -0
- data/seeds/data.yml +1 -0
- data/seeds/layouts/default.html.erb +5 -2
- data/seeds/layouts/sitemap.html.erb +6 -0
- data/seeds/rules.rb +19 -2
- data/seeds/setup.rb +15 -0
- data/seeds/src/_vars.scss +6 -0
- data/seeds/src/about.html.erb +11 -0
- data/seeds/src/basic.css.scss +41 -0
- data/seeds/src/index.html.erb +34 -0
- metadata +37 -7
- data/lib/munge/core/config.rb +0 -23
- data/lib/munge/helper.rb +0 -4
@@ -0,0 +1,44 @@
|
|
1
|
+
module Munge
|
2
|
+
module Router
|
3
|
+
class AutoAddExtension
|
4
|
+
def initialize(keep_extensions:)
|
5
|
+
@keep_extensions = keep_extensions
|
6
|
+
end
|
7
|
+
|
8
|
+
def type
|
9
|
+
:route
|
10
|
+
end
|
11
|
+
|
12
|
+
def match?(initial_route, item)
|
13
|
+
item_should_have_extension?(item) && route_doesnt_have_extension?(initial_route)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(initial_route, item)
|
17
|
+
add_extension(initial_route, item)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def add_extension(initial_route, item)
|
23
|
+
intersection = item.extensions & @keep_extensions
|
24
|
+
extension = intersection[0]
|
25
|
+
|
26
|
+
"#{initial_route}.#{extension}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def item_should_have_extension?(item)
|
30
|
+
intersection = item.extensions & @keep_extensions
|
31
|
+
|
32
|
+
intersection.length > 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def route_doesnt_have_extension?(initial_route)
|
36
|
+
initial_route_extensions = initial_route.split(".")[1..-1]
|
37
|
+
|
38
|
+
intersection = initial_route_extensions & @keep_extensions
|
39
|
+
|
40
|
+
intersection.length == 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Munge
|
2
|
+
module Router
|
3
|
+
class Fingerprint
|
4
|
+
def initialize(extensions:,
|
5
|
+
separator:)
|
6
|
+
@extensions = extensions
|
7
|
+
@separator = separator
|
8
|
+
end
|
9
|
+
|
10
|
+
def type
|
11
|
+
:route
|
12
|
+
end
|
13
|
+
|
14
|
+
def match?(_initial_route, item)
|
15
|
+
if item.frontmatter.key?(:fingerprint_asset)
|
16
|
+
return item.frontmatter[:fingerprint_asset]
|
17
|
+
end
|
18
|
+
|
19
|
+
intersection = item.extensions & @extensions
|
20
|
+
|
21
|
+
if intersection.size == 0
|
22
|
+
false
|
23
|
+
else
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(initial_route, item)
|
29
|
+
generate_link(initial_route, item.compiled_content)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def generate_link(initial_route, content)
|
35
|
+
pre, extension = disassemble(initial_route)
|
36
|
+
asset_hash = hash(content)
|
37
|
+
|
38
|
+
if extension == ""
|
39
|
+
"#{pre}#{@separator}#{asset_hash}"
|
40
|
+
else
|
41
|
+
"#{pre}#{@separator}#{asset_hash}.#{extension}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def hash(content)
|
46
|
+
Digest::MD5.hexdigest(content)
|
47
|
+
end
|
48
|
+
|
49
|
+
def disassemble(path)
|
50
|
+
extension = Util::Path.extname(path)
|
51
|
+
path_without_extension = Util::Path.path_no_extension(path)
|
52
|
+
|
53
|
+
[
|
54
|
+
path_without_extension,
|
55
|
+
extension
|
56
|
+
]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Munge
|
2
|
+
module Router
|
3
|
+
class RemoveIndexBasename
|
4
|
+
def initialize(html_extensions:, index:)
|
5
|
+
@html_extensions = html_extensions
|
6
|
+
@index = index
|
7
|
+
@index_basename = Munge::Util::Path.basename_no_extension(@index)
|
8
|
+
end
|
9
|
+
|
10
|
+
def type
|
11
|
+
:route
|
12
|
+
end
|
13
|
+
|
14
|
+
def match?(initial_route, item)
|
15
|
+
item_is_html?(item) && basename_is_index?(initial_route)
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(initial_route, _item)
|
19
|
+
Munge::Util::Path.dirname(initial_route)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def item_is_html?(item)
|
25
|
+
intersection = item.extensions & @html_extensions
|
26
|
+
|
27
|
+
intersection.length > 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def basename_is_index?(route)
|
31
|
+
File.basename(route) == @index_basename
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/munge/runner.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Munge
|
2
2
|
class Runner
|
3
3
|
class << self
|
4
|
-
def method_missing(method,
|
5
|
-
runner = new(
|
4
|
+
def method_missing(method, root_path, *args)
|
5
|
+
runner = new(application(root_path))
|
6
6
|
runner.public_send(method, *args)
|
7
7
|
end
|
8
8
|
|
@@ -13,12 +13,16 @@ module Munge
|
|
13
13
|
super
|
14
14
|
end
|
15
15
|
end
|
16
|
-
end
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
def application(root_path)
|
18
|
+
bootstrap = Munge::Bootstrap.new_from_dir(root_path: root_path)
|
19
|
+
|
20
|
+
bootstrap.app
|
21
|
+
end
|
22
|
+
end
|
20
23
|
|
21
|
-
|
24
|
+
def initialize(application)
|
25
|
+
@app = application
|
22
26
|
end
|
23
27
|
|
24
28
|
def write
|
data/lib/munge/system.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Munge
|
2
|
+
class System
|
3
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
4
|
+
def initialize(root_path, config)
|
5
|
+
source_path = File.expand_path(config[:source], root_path)
|
6
|
+
layouts_path = File.expand_path(config[:layouts], root_path)
|
7
|
+
output_path = File.expand_path(config[:output], root_path)
|
8
|
+
data_path = File.expand_path(config[:data], root_path)
|
9
|
+
|
10
|
+
@global_data = YAML.load_file(data_path) || {}
|
11
|
+
|
12
|
+
@config = config
|
13
|
+
|
14
|
+
@item_factory =
|
15
|
+
Core::ItemFactory.new(
|
16
|
+
text_extensions: config[:text_extensions],
|
17
|
+
ignored_basenames: config[:ignored_basenames]
|
18
|
+
)
|
19
|
+
|
20
|
+
@source =
|
21
|
+
Core::Collection.new(
|
22
|
+
item_factory: @item_factory,
|
23
|
+
items: Reader::Filesystem.new(source_path)
|
24
|
+
)
|
25
|
+
|
26
|
+
@layouts =
|
27
|
+
Core::Collection.new(
|
28
|
+
item_factory: @item_factory,
|
29
|
+
items: Reader::Filesystem.new(layouts_path)
|
30
|
+
)
|
31
|
+
|
32
|
+
@alterant =
|
33
|
+
Core::Alterant.new(scope: self)
|
34
|
+
|
35
|
+
@router =
|
36
|
+
Core::Router.new(
|
37
|
+
alterant: @alterant
|
38
|
+
)
|
39
|
+
|
40
|
+
@writer =
|
41
|
+
Core::Write.new(
|
42
|
+
output: output_path
|
43
|
+
)
|
44
|
+
end
|
45
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
46
|
+
|
47
|
+
attr_accessor :alterant
|
48
|
+
attr_accessor :config
|
49
|
+
attr_accessor :global_data
|
50
|
+
attr_accessor :router
|
51
|
+
attr_accessor :source
|
52
|
+
attr_accessor :writer
|
53
|
+
end
|
54
|
+
end
|
@@ -3,6 +3,7 @@ module Munge
|
|
3
3
|
class Tilt
|
4
4
|
def initialize(scope)
|
5
5
|
@pristine_scope = scope
|
6
|
+
@registry = []
|
6
7
|
end
|
7
8
|
|
8
9
|
def name
|
@@ -16,12 +17,15 @@ module Munge
|
|
16
17
|
dirty_scope.render_with_layout(item, content_engines: renderer, content_override: content)
|
17
18
|
end
|
18
19
|
|
20
|
+
def register(helper)
|
21
|
+
@registry.push(helper)
|
22
|
+
end
|
23
|
+
|
19
24
|
private
|
20
25
|
|
21
26
|
def extend_with_helpers(scope)
|
22
|
-
|
23
|
-
.
|
24
|
-
.inject(scope) { |scope, helper| scope.extend(helper) }
|
27
|
+
@registry
|
28
|
+
.inject(scope) { |a, e| a.extend(e) }
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Munge
|
2
|
+
module Util
|
3
|
+
class Config
|
4
|
+
class << self
|
5
|
+
def read(path)
|
6
|
+
abspath = File.expand_path(path)
|
7
|
+
|
8
|
+
yaml = read_yaml(abspath)
|
9
|
+
|
10
|
+
config =
|
11
|
+
if yaml.is_a?(Hash)
|
12
|
+
yaml
|
13
|
+
else
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
|
17
|
+
Munge::Util::SymbolHash.deep_convert(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def read_yaml(abspath)
|
23
|
+
YAML.load_file(abspath)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Munge
|
2
|
+
module Util
|
3
|
+
class Path
|
4
|
+
def self.dirname(path)
|
5
|
+
path_parts = path.split("/")
|
6
|
+
path_parts[0..-2].join("/")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.extname(path)
|
10
|
+
basename = File.basename(path)
|
11
|
+
basename_parts = basename.split(".")
|
12
|
+
|
13
|
+
if basename_parts.length > 1
|
14
|
+
basename_parts[-1]
|
15
|
+
else
|
16
|
+
""
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.basename_no_extension(path)
|
21
|
+
basename = File.basename(path)
|
22
|
+
basename_parts = basename.split(".")
|
23
|
+
|
24
|
+
basename_parts[0] || ""
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.path_no_extension(path)
|
28
|
+
extension = extname(path)
|
29
|
+
|
30
|
+
if extension == ""
|
31
|
+
path
|
32
|
+
else
|
33
|
+
path.sub(/\.#{extension}/, "")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.ensure_abspath(path)
|
38
|
+
correct = path.squeeze("/")
|
39
|
+
|
40
|
+
if correct[0] == "/"
|
41
|
+
correct
|
42
|
+
else
|
43
|
+
"/#{correct}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.ensure_relpath(path)
|
48
|
+
correct = path.squeeze("/")
|
49
|
+
|
50
|
+
if correct[0] == "/"
|
51
|
+
correct[1..-1]
|
52
|
+
else
|
53
|
+
correct
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Munge
|
2
|
+
module Util
|
3
|
+
class SymbolHash
|
4
|
+
class << self
|
5
|
+
def deep_convert(obj)
|
6
|
+
if obj.is_a?(Hash)
|
7
|
+
convert_hash(obj)
|
8
|
+
elsif obj.is_a?(Array)
|
9
|
+
obj.map do |i|
|
10
|
+
deep_convert(i)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
obj
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def convert_hash(obj)
|
20
|
+
converted_hash = {}
|
21
|
+
|
22
|
+
obj.each do |key, value|
|
23
|
+
if key.is_a?(String) || key.is_a?(Symbol)
|
24
|
+
converted_hash[key.to_sym] = deep_convert(value)
|
25
|
+
else
|
26
|
+
converted_hash[key] = value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
converted_hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/munge/version.rb
CHANGED
data/lib/munge.rb
CHANGED
@@ -1,25 +1,32 @@
|
|
1
1
|
require "fileutils"
|
2
|
+
require "forwardable"
|
2
3
|
require "pathname"
|
3
4
|
require "set"
|
4
5
|
require "yaml"
|
5
6
|
|
6
|
-
require "adsf"
|
7
|
-
require "rack"
|
8
7
|
require "tilt"
|
9
8
|
|
10
9
|
require "munge/version"
|
11
10
|
require "munge/item"
|
12
|
-
require "munge/
|
11
|
+
require "munge/util/path"
|
12
|
+
require "munge/util/symbol_hash"
|
13
|
+
require "munge/util/config"
|
14
|
+
require "munge/helper/capture"
|
13
15
|
require "munge/helper/find"
|
14
16
|
require "munge/helper/link"
|
15
17
|
require "munge/helper/rendering"
|
16
18
|
require "munge/transformer/tilt"
|
17
19
|
require "munge/readers/filesystem"
|
18
|
-
require "munge/
|
20
|
+
require "munge/routers/auto_add_extension"
|
21
|
+
require "munge/routers/fingerprint"
|
22
|
+
require "munge/routers/add_index_html"
|
23
|
+
require "munge/routers/remove_index_basename"
|
19
24
|
require "munge/core/router"
|
20
25
|
require "munge/core/item_factory"
|
21
26
|
require "munge/core/collection"
|
22
27
|
require "munge/core/write"
|
23
28
|
require "munge/core/alterant"
|
29
|
+
require "munge/system"
|
24
30
|
require "munge/application"
|
25
31
|
require "munge/runner"
|
32
|
+
require "munge/bootstrap"
|
data/munge.gemspec
CHANGED
data/seeds/config.yml
CHANGED
data/seeds/data.yml
CHANGED
@@ -2,9 +2,12 @@
|
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
4
|
<meta charset="UTF-8">
|
5
|
-
<title
|
5
|
+
<title><%= site_name %></title>
|
6
|
+
<link rel="stylesheet" href="<%= url_for(items["basic.css.scss"]) %>" media="screen" charset="utf-8">
|
6
7
|
</head>
|
7
8
|
<body>
|
8
|
-
|
9
|
+
<div class="layout">
|
10
|
+
<%= yield %>
|
11
|
+
</div>
|
9
12
|
</body>
|
10
13
|
</html>
|
data/seeds/rules.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
|
+
# HTML rules
|
1
2
|
app.source
|
2
|
-
.select { |item| item.
|
3
|
-
.each { |item| item.route =
|
3
|
+
.select { |item| item.extensions.include?("html") }
|
4
|
+
.each { |item| item.route = item.id }
|
4
5
|
.each { |item| item.layout = "default" }
|
5
6
|
.each { |item| item.transform }
|
7
|
+
|
8
|
+
# CSS rules
|
9
|
+
app.source
|
10
|
+
.select { |item| item.extensions.include?("scss") }
|
11
|
+
.reject { |item| item.basename[0] == "_" }
|
12
|
+
.each { |item| item.route = "/styles/#{item.basename}.css" }
|
13
|
+
.each { |item| item.transform }
|
14
|
+
|
15
|
+
# Sitemap
|
16
|
+
html_pages =
|
17
|
+
app.source
|
18
|
+
.reject { |item| item.route.nil? }
|
19
|
+
.select { |item| item.extensions.include?("html") }
|
20
|
+
.sort_by { |item| item.route }
|
21
|
+
|
22
|
+
system.global_data[:sitemap_pages] = html_pages
|
data/seeds/setup.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "sass"
|
2
|
+
Sass.load_paths << File.expand_path(system.config[:source], File.dirname(__FILE__))
|
3
|
+
|
4
|
+
tilt_transformer = Transformer::Tilt.new(system)
|
5
|
+
tilt_transformer.register(Munge::Helper::Capture)
|
6
|
+
tilt_transformer.register(Munge::Helper::Find)
|
7
|
+
tilt_transformer.register(Munge::Helper::Link)
|
8
|
+
tilt_transformer.register(Munge::Helper::Rendering)
|
9
|
+
|
10
|
+
system.alterant.register(tilt_transformer)
|
11
|
+
|
12
|
+
system.router.register(Router::Fingerprint.new(extensions: system.config[:keep_extensions], separator: system.config[:fingeprint_separator]))
|
13
|
+
system.router.register(Router::RemoveIndexBasename.new(html_extensions: system.config[:text_extensions], index: system.config[:index]))
|
14
|
+
system.router.register(Router::AddIndexHtml.new(html_extensions: system.config[:text_extensions], index: system.config[:index]))
|
15
|
+
system.router.register(Router::AutoAddExtension.new(keep_extensions: system.config[:keep_extensions]))
|
@@ -0,0 +1,41 @@
|
|
1
|
+
@import "vars";
|
2
|
+
|
3
|
+
body {
|
4
|
+
background-color: $color-bg;
|
5
|
+
color: $color-fg;
|
6
|
+
font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
|
7
|
+
font-size: 16px;
|
8
|
+
line-height: $golden * 1em;
|
9
|
+
margin: $golden * 1em;
|
10
|
+
}
|
11
|
+
|
12
|
+
h1 {
|
13
|
+
font-size: $golden * $golden * 1em;
|
14
|
+
font-weight: normal;
|
15
|
+
line-height: $golden * 1em;
|
16
|
+
margin: 0;
|
17
|
+
}
|
18
|
+
|
19
|
+
h2 {
|
20
|
+
font-size: $golden * 1em;
|
21
|
+
font-weight: normal;
|
22
|
+
line-height: $golden;
|
23
|
+
margin: 0;
|
24
|
+
}
|
25
|
+
|
26
|
+
p {
|
27
|
+
margin: $golden * 0.5em 0;
|
28
|
+
}
|
29
|
+
|
30
|
+
code {
|
31
|
+
font-family: "Courier New", Courier, monospace;
|
32
|
+
}
|
33
|
+
|
34
|
+
ul {
|
35
|
+
margin: $golden * 0.5em 0;
|
36
|
+
}
|
37
|
+
|
38
|
+
.layout {
|
39
|
+
width: $layout-width;
|
40
|
+
margin: 0 auto;
|
41
|
+
}
|
data/seeds/src/index.html.erb
CHANGED
@@ -3,3 +3,37 @@ title: Welcome
|
|
3
3
|
---
|
4
4
|
|
5
5
|
<h1><%= title %></h1>
|
6
|
+
|
7
|
+
<h2>Getting started</h2>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<strong><code>rules.rb</code>:</strong>
|
11
|
+
The routing rules are defined in this file.
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<p>
|
15
|
+
<strong><code>setup.rb</code>:</strong>
|
16
|
+
Plugins, gems, etc can be configured in this file.
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p>
|
20
|
+
<strong><code>data.yml</code>:</strong>
|
21
|
+
The keys defined in this file are accessible in every file that you author.
|
22
|
+
</p>
|
23
|
+
|
24
|
+
<p>
|
25
|
+
<strong><code>config.yml</code>:</strong>
|
26
|
+
The keys defined here are used to change the behavior of the app.
|
27
|
+
Many of the keys are passed directly into the initializers in
|
28
|
+
<code>setup.rb</code>.
|
29
|
+
</p>
|
30
|
+
|
31
|
+
<h2>Links</h2>
|
32
|
+
|
33
|
+
<ul>
|
34
|
+
<li><a href="https://github.com/zachahn/munge">Munge homepage</a></li>
|
35
|
+
<li><a href="https://github.com/zachahn/munge/issues">Munge issues</a></li>
|
36
|
+
<li><a href="https://rubygems.org/gems/munge">Gem homepage</a></li>
|
37
|
+
</ul>
|
38
|
+
|
39
|
+
<%= render(layouts["sitemap"]) %>
|