munge 0.4.0 → 0.5.0.beta1
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/.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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0ea780f903de0afaf329d50a2e81a69e14b8e4e
|
4
|
+
data.tar.gz: 53d5d6025748b56dbc3394b5080afa7ec107a954
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec154947682821e309c2d781bf7de1692e86c78bbb6f9236d3b46264ee49fcfbd94ea84ce214f6bb09754c81e9507a570265a22212f2e3f637c97433ffbb5914
|
7
|
+
data.tar.gz: 98d471dcfae5960316b92ac17cd4aa9e078d984a74091cfc687b3c4c435ee561f51e1f641efb1e8f6380d8374eb59cb65c84fb5806206580ba99cf830c1a4451
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -13,6 +13,10 @@ Metrics/MethodLength:
|
|
13
13
|
Exclude:
|
14
14
|
- test/**/*
|
15
15
|
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Exclude:
|
18
|
+
- test/**/*
|
19
|
+
|
16
20
|
Style/AlignParameters:
|
17
21
|
Enabled: false
|
18
22
|
|
@@ -22,8 +26,14 @@ Style/Documentation:
|
|
22
26
|
Style/ClassAndModuleChildren:
|
23
27
|
Enabled: false
|
24
28
|
|
29
|
+
Style/GuardClause:
|
30
|
+
Enabled: false
|
31
|
+
|
25
32
|
Style/IfUnlessModifier:
|
26
33
|
Enabled: false
|
27
34
|
|
35
|
+
Style/MultilineOperationIndentation:
|
36
|
+
EnforcedStyle: indented
|
37
|
+
|
28
38
|
Style/StringLiterals:
|
29
39
|
EnforcedStyle: double_quotes
|
data/Makefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
.PHONY: all test testc openc release
|
2
|
+
|
3
|
+
all:
|
4
|
+
@echo "usage:"
|
5
|
+
@echo
|
6
|
+
@echo "make test runs tests"
|
7
|
+
@echo "make testc runs tests and logs coverage"
|
8
|
+
@echo "make openc starts webserver in coverage directory"
|
9
|
+
@echo "make release releases gem (dangerous)"
|
10
|
+
|
11
|
+
test:
|
12
|
+
script/test
|
13
|
+
|
14
|
+
testc:
|
15
|
+
COVERAGE=1 script/test
|
16
|
+
|
17
|
+
openc:
|
18
|
+
cd coverage && adsf
|
19
|
+
|
20
|
+
release:
|
21
|
+
bundle exec rake release
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ After installing your gem, you can start a project using the command line client
|
|
50
50
|
munge init path/to/project # create a barebones project
|
51
51
|
cd path/to/project
|
52
52
|
munge build # compiles your project
|
53
|
-
munge view # open http://localhost:
|
53
|
+
munge view # open http://localhost:7000/ to see output
|
54
54
|
```
|
55
55
|
|
56
56
|
The three main files of your application are `config.yml`, `data.yml`, and `rules.rb`.
|
data/exe/munge
CHANGED
data/lib/munge/application.rb
CHANGED
@@ -1,77 +1,35 @@
|
|
1
1
|
module Munge
|
2
2
|
class Application
|
3
|
-
|
4
|
-
|
5
|
-
config = Core::Config.new(config_path)
|
6
|
-
|
7
|
-
root_path = File.dirname(File.expand_path(config_path))
|
8
|
-
source_path = File.expand_path(config[:source], root_path)
|
9
|
-
layouts_path = File.expand_path(config[:layouts], root_path)
|
10
|
-
output_path = File.expand_path(config[:output], root_path)
|
11
|
-
data_path = File.expand_path(config[:data], root_path)
|
12
|
-
|
13
|
-
@global_data = YAML.load_file(data_path) || {}
|
14
|
-
|
15
|
-
@item_factory =
|
16
|
-
Core::ItemFactory.new(
|
17
|
-
text_extensions: config[:text_extensions],
|
18
|
-
ignored_basenames: config[:ignored_basenames]
|
19
|
-
)
|
20
|
-
|
21
|
-
@source =
|
22
|
-
Core::Collection.new(
|
23
|
-
item_factory: @item_factory,
|
24
|
-
items: Reader::Filesystem.new(source_path)
|
25
|
-
)
|
26
|
-
|
27
|
-
@layouts =
|
28
|
-
Core::Collection.new(
|
29
|
-
item_factory: @item_factory,
|
30
|
-
items: Reader::Filesystem.new(layouts_path)
|
31
|
-
)
|
32
|
-
|
33
|
-
@router =
|
34
|
-
Core::Router.new(
|
35
|
-
index: config[:index],
|
36
|
-
keep_extensions: config[:keep_extensions]
|
37
|
-
)
|
38
|
-
|
39
|
-
@alterant =
|
40
|
-
Core::Alterant.new(scope: self)
|
41
|
-
|
42
|
-
@writer =
|
43
|
-
Core::Write.new(
|
44
|
-
output: output_path
|
45
|
-
)
|
46
|
-
|
47
|
-
@alterant.register(Transformer::Tilt.new(self))
|
3
|
+
def initialize(system)
|
4
|
+
@system = system
|
48
5
|
end
|
49
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
50
6
|
|
51
|
-
|
7
|
+
def source
|
8
|
+
@system.source
|
9
|
+
end
|
52
10
|
|
53
11
|
def write(&block)
|
54
|
-
@source
|
12
|
+
@system.source
|
55
13
|
.reject { |item| item.route.nil? }
|
56
14
|
.each { |item| render_and_write(item, &block) }
|
57
15
|
end
|
58
16
|
|
59
17
|
def build_virtual_item(*args)
|
60
|
-
@source.build(*args)
|
18
|
+
@system.source.build(*args)
|
61
19
|
end
|
62
20
|
|
63
|
-
def create(*args
|
21
|
+
def create(*args)
|
64
22
|
item = build_virtual_item(*args)
|
65
23
|
yield item if block_given?
|
66
|
-
@source.push(item)
|
24
|
+
@system.source.push(item)
|
67
25
|
end
|
68
26
|
|
69
27
|
private
|
70
28
|
|
71
29
|
def render_and_write(item, &block)
|
72
|
-
relpath = @router.filepath(item)
|
30
|
+
relpath = @system.router.filepath(item)
|
73
31
|
|
74
|
-
write_status = @writer.write(relpath, @alterant.transform(item))
|
32
|
+
write_status = @system.writer.write(relpath, @system.alterant.transform(item))
|
75
33
|
|
76
34
|
if block_given?
|
77
35
|
block.call(item, write_status)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Munge
|
2
|
+
class Bootstrap
|
3
|
+
class << self
|
4
|
+
def new_from_dir(root_path:)
|
5
|
+
new_from_fs(
|
6
|
+
root_path: root_path,
|
7
|
+
config_path: config_path(root_path),
|
8
|
+
setup_path: setup_path(root_path),
|
9
|
+
rules_path: rules_path(root_path)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_from_fs(root_path:,
|
14
|
+
config_path:,
|
15
|
+
setup_path:,
|
16
|
+
rules_path:)
|
17
|
+
new(
|
18
|
+
root_path: root_path,
|
19
|
+
config: read_config(config_path),
|
20
|
+
setup_string: File.read(setup_path),
|
21
|
+
setup_path: setup_path,
|
22
|
+
rules_string: File.read(rules_path),
|
23
|
+
rules_path: rules_path
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def read_config(config_path)
|
30
|
+
Munge::Util::Config.read(config_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def config_path(root_path)
|
34
|
+
File.join(root_path, "config.yml")
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup_path(root_path)
|
38
|
+
File.join(root_path, "setup.rb")
|
39
|
+
end
|
40
|
+
|
41
|
+
def rules_path(root_path)
|
42
|
+
File.join(root_path, "rules.rb")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize(root_path:,
|
47
|
+
config:,
|
48
|
+
setup_string:,
|
49
|
+
rules_string:,
|
50
|
+
setup_path:,
|
51
|
+
rules_path:)
|
52
|
+
system = Munge::System.new(root_path, config)
|
53
|
+
|
54
|
+
binding.eval(setup_string, setup_path)
|
55
|
+
|
56
|
+
@app = Munge::Application.new(system)
|
57
|
+
|
58
|
+
binding.eval(rules_string, rules_path)
|
59
|
+
end
|
60
|
+
|
61
|
+
attr_reader :app
|
62
|
+
end
|
63
|
+
end
|
data/lib/munge/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "thor"
|
2
2
|
|
3
|
+
require_relative "commands/view"
|
4
|
+
|
3
5
|
module Munge
|
4
6
|
class CLI < Thor
|
5
7
|
include Thor::Actions
|
@@ -15,28 +17,14 @@ module Munge
|
|
15
17
|
|
16
18
|
desc "build", "Build in current directory"
|
17
19
|
def build
|
18
|
-
Munge::Runner.write(
|
20
|
+
Munge::Runner.write(destination_root)
|
19
21
|
end
|
20
22
|
|
21
23
|
desc "view", "View built files"
|
22
|
-
method_option :port, aliases: "-p", desc: "Set port", default:
|
24
|
+
method_option :port, aliases: "-p", desc: "Set port", default: 7000, type: :numeric
|
23
25
|
method_option :host, aliases: "-h", desc: "Set host", default: "0.0.0.0", type: :string
|
24
26
|
def view
|
25
|
-
|
26
|
-
handler = Rack::Handler::WEBrick
|
27
|
-
rack_opts = { Host: options[:host], Port: options[:port] }
|
28
|
-
|
29
|
-
app =
|
30
|
-
Rack::Builder.new do
|
31
|
-
use Rack::CommonLogger
|
32
|
-
use Rack::ShowExceptions
|
33
|
-
use Rack::Lint
|
34
|
-
use Rack::Head
|
35
|
-
use Adsf::Rack::IndexFileFinder, root: config[:output]
|
36
|
-
run Rack::File.new(config[:output])
|
37
|
-
end
|
38
|
-
|
39
|
-
Rack::Handler::WEBrick.run(app, rack_opts)
|
27
|
+
Munge::Commands::View.new(options, config_path)
|
40
28
|
end
|
41
29
|
|
42
30
|
desc "version", "Print version"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (c) 2007-2015 Denis Defreyne and contributors
|
2
|
+
# Copyright (c) 2015 Zach Ahn
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
#
|
22
|
+
# https://github.com/nanoc/nanoc/blob/fdf8b28/lib/nanoc/cli/commands/view.rb#L17-L53
|
23
|
+
|
24
|
+
require "adsf"
|
25
|
+
require "rack"
|
26
|
+
|
27
|
+
module Munge
|
28
|
+
class Commands
|
29
|
+
class View
|
30
|
+
def initialize(options, config_path)
|
31
|
+
config = Munge::Util::Config.read(config_path)
|
32
|
+
rack_opts = { Host: options[:host], Port: options[:port] }
|
33
|
+
|
34
|
+
app =
|
35
|
+
Rack::Builder.new do
|
36
|
+
use Rack::ShowExceptions
|
37
|
+
use Rack::Head
|
38
|
+
use Adsf::Rack::IndexFileFinder, root: config[:output]
|
39
|
+
run Rack::File.new(config[:output])
|
40
|
+
end
|
41
|
+
|
42
|
+
Rack::Handler::WEBrick.run(app, rack_opts)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/munge/core/alterant.rb
CHANGED
@@ -12,7 +12,7 @@ module Munge
|
|
12
12
|
|
13
13
|
# name should be snake_case Symbol
|
14
14
|
def register_manually(name, transformer)
|
15
|
-
if @registry.
|
15
|
+
if @registry.key?(name)
|
16
16
|
fail "already registered transformer `#{name}`"
|
17
17
|
else
|
18
18
|
@registry[name] = transformer
|
@@ -32,7 +32,7 @@ module Munge
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def get_transformer(name)
|
35
|
-
if @registry.
|
35
|
+
if @registry.key?(name)
|
36
36
|
@registry[name]
|
37
37
|
else
|
38
38
|
fail "transformer `#{name}` is not installed"
|
@@ -29,11 +29,14 @@ module Munge
|
|
29
29
|
|
30
30
|
parsed_frontmatter = YAML.load(matchdata[1])
|
31
31
|
|
32
|
-
|
33
|
-
parsed_frontmatter
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
frontmatter_hash =
|
33
|
+
if parsed_frontmatter.is_a?(Hash)
|
34
|
+
parsed_frontmatter
|
35
|
+
else
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
|
39
|
+
Munge::Util::SymbolHash.deep_convert(frontmatter_hash)
|
37
40
|
end
|
38
41
|
|
39
42
|
def self.parse_content(matchdata, string)
|
@@ -44,15 +47,8 @@ module Munge
|
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
|
-
def initialize(string
|
50
|
+
def initialize(string)
|
48
51
|
@frontmatter, @content = self.class.parse(string)
|
49
|
-
|
50
|
-
if frontmatter
|
51
|
-
@frontmatter = @frontmatter.merge(frontmatter)
|
52
|
-
end
|
53
|
-
rescue ArgumentError
|
54
|
-
@frontmatter = frontmatter || {}
|
55
|
-
@content = string
|
56
52
|
end
|
57
53
|
|
58
54
|
attr_accessor :frontmatter, :content
|
@@ -58,18 +58,6 @@ module Munge
|
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
-
def compute_content_and_frontmatter(abspath)
|
62
|
-
case @location
|
63
|
-
when :fs_memory
|
64
|
-
content = Munge::Attribute::Content.new(File.read(abspath))
|
65
|
-
[content.content, content.frontmatter]
|
66
|
-
when :fs, :virtual
|
67
|
-
["", {}]
|
68
|
-
else
|
69
|
-
fail "invalid @location `#{@location}`"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
61
|
def file_extensions(filepath)
|
74
62
|
extensions = File.basename(filepath).split(".")[1..-1]
|
75
63
|
Set.new(extensions)
|
@@ -85,17 +73,6 @@ module Munge
|
|
85
73
|
end
|
86
74
|
end
|
87
75
|
|
88
|
-
def compute_relpath(abspath)
|
89
|
-
folder = Pathname.new(@source_path)
|
90
|
-
file = Pathname.new(abspath)
|
91
|
-
|
92
|
-
file.relative_path_from(folder).to_s
|
93
|
-
end
|
94
|
-
|
95
|
-
def compute_stat(abspath)
|
96
|
-
File.stat(abspath)
|
97
|
-
end
|
98
|
-
|
99
76
|
def compute_id(relpath)
|
100
77
|
dirname = compute_dirname(relpath)
|
101
78
|
basename = compute_basename(relpath)
|
@@ -114,7 +91,7 @@ module Munge
|
|
114
91
|
end
|
115
92
|
|
116
93
|
def compute_dirname(relpath)
|
117
|
-
|
94
|
+
File.dirname(relpath)
|
118
95
|
end
|
119
96
|
|
120
97
|
def compute_basename(relpath)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Munge
|
2
|
+
module Core
|
3
|
+
class Router
|
4
|
+
class Itemish
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def initialize(item, alterant)
|
8
|
+
@item = item
|
9
|
+
@alterant = alterant
|
10
|
+
end
|
11
|
+
|
12
|
+
def compiled_content
|
13
|
+
@compiled_content ||= @alterant.transform(@item)
|
14
|
+
end
|
15
|
+
|
16
|
+
def_delegators :@item, *%i(type relpath id frontmatter stat layout)
|
17
|
+
def_delegators :@item, *%i(dirname filename basename extensions)
|
18
|
+
def_delegators :@item, *%i(relpath? route?)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/munge/core/router.rb
CHANGED
@@ -1,62 +1,53 @@
|
|
1
|
+
require_relative "router/itemish"
|
2
|
+
|
1
3
|
module Munge
|
2
4
|
module Core
|
3
5
|
class Router
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
@
|
6
|
+
def initialize(alterant:)
|
7
|
+
@registries = { route: [], filepath: [] }
|
8
|
+
@alterant = alterant
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def register(router)
|
12
|
+
case router.type
|
13
|
+
when :route
|
14
|
+
@registries[:route].push(router)
|
15
|
+
when :filepath
|
16
|
+
@registries[:filepath].push(router)
|
14
17
|
else
|
15
|
-
|
18
|
+
fail "invalid router"
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
path =
|
25
|
-
if route_has_extension?(item)
|
26
|
-
"#{relroute}"
|
27
|
-
elsif keep_extension?(item)
|
28
|
-
"#{relroute}.#{main_extension(item)}"
|
29
|
-
else
|
30
|
-
"#{relroute}/#{@index}"
|
31
|
-
end
|
22
|
+
def route(item)
|
23
|
+
path = route_mapper(item, :route)
|
24
|
+
Util::Path.ensure_abspath(path)
|
25
|
+
end
|
32
26
|
|
33
|
-
|
27
|
+
def filepath(item)
|
28
|
+
initial_route = route(item)
|
29
|
+
path = route_mapper(item, :filepath, initial_route)
|
30
|
+
Util::Path.ensure_relpath(path)
|
34
31
|
end
|
35
32
|
|
36
33
|
private
|
37
34
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
35
|
+
def route_mapper(item, method_name, initial_route = nil)
|
36
|
+
if !item.route && !initial_route
|
37
|
+
fail "item has no route"
|
41
38
|
end
|
42
39
|
|
43
|
-
|
44
|
-
end
|
40
|
+
itemish = Itemish.new(item, @alterant)
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
item.extensions.first
|
56
|
-
end
|
57
|
-
|
58
|
-
def route_basename(item)
|
59
|
-
File.basename(item.route)
|
42
|
+
@registries[method_name]
|
43
|
+
.select { |router| router.type == method_name }
|
44
|
+
.inject(initial_route || item.route) do |route, router|
|
45
|
+
if router.match?(route, itemish)
|
46
|
+
router.call(route, itemish)
|
47
|
+
else
|
48
|
+
route
|
49
|
+
end
|
50
|
+
end
|
60
51
|
end
|
61
52
|
end
|
62
53
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Munge
|
2
|
+
module Helper
|
3
|
+
module Capture
|
4
|
+
def capture(&block)
|
5
|
+
original_erbout = block.binding.local_variable_get(:_erbout)
|
6
|
+
block.binding.local_variable_set(:_erbout, "")
|
7
|
+
|
8
|
+
captured_text = block.call
|
9
|
+
|
10
|
+
block.binding.local_variable_set(:_erbout, original_erbout)
|
11
|
+
|
12
|
+
captured_text
|
13
|
+
end
|
14
|
+
|
15
|
+
def append_to_erbout(block_binding, text)
|
16
|
+
original_erbout = block_binding.local_variable_get(:_erbout)
|
17
|
+
|
18
|
+
updated_erbout = original_erbout + text
|
19
|
+
|
20
|
+
block_binding.local_variable_set(:_erbout, updated_erbout)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/munge/helper/find.rb
CHANGED
data/lib/munge/helper/link.rb
CHANGED
@@ -5,9 +5,14 @@ module Munge
|
|
5
5
|
@router.route(item)
|
6
6
|
end
|
7
7
|
|
8
|
-
def link_to(item, text = nil,
|
8
|
+
def link_to(item, text = nil, opts = {})
|
9
9
|
link = url_for(item)
|
10
10
|
|
11
|
+
if text.is_a?(Hash)
|
12
|
+
opts = text
|
13
|
+
text = nil
|
14
|
+
end
|
15
|
+
|
11
16
|
optstr = opts.map { |key, val| %(#{key}="#{val}") }
|
12
17
|
|
13
18
|
parts =
|
data/lib/munge/item.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Munge
|
2
|
+
module Router
|
3
|
+
class AddIndexHtml
|
4
|
+
def initialize(html_extensions:, index:)
|
5
|
+
@html_extensions = html_extensions
|
6
|
+
@index = index
|
7
|
+
end
|
8
|
+
|
9
|
+
def type
|
10
|
+
:filepath
|
11
|
+
end
|
12
|
+
|
13
|
+
def match?(initial_route, item)
|
14
|
+
item_is_html?(item) && route_needs_extension?(initial_route)
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(initial_route, _item)
|
18
|
+
File.join(initial_route, @index)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def item_is_html?(item)
|
24
|
+
intersection = item.extensions & @html_extensions
|
25
|
+
|
26
|
+
intersection.length > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def route_needs_extension?(route)
|
30
|
+
basename = File.basename(route)
|
31
|
+
|
32
|
+
!basename.include?(".")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|