munge 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/munge.rb +32 -31
- data/lib/munge/application.rb +7 -7
- data/lib/munge/bootloader.rb +0 -11
- data/lib/munge/cli.rb +3 -3
- data/lib/munge/cli/commands/build.rb +17 -21
- data/lib/munge/cli/commands/clean.rb +28 -33
- data/lib/munge/cli/commands/init.rb +1 -1
- data/lib/munge/cli/commands/server.rb +3 -3
- data/lib/munge/cli/dispatch.rb +56 -13
- data/lib/munge/config.rb +2 -2
- data/lib/munge/{system.rb → conglomerate.rb} +21 -14
- data/lib/munge/{system → conglomerate}/collection.rb +5 -26
- data/lib/munge/{system → conglomerate}/item_factory.rb +1 -1
- data/lib/munge/{system → conglomerate}/item_factory/content_parser.rb +1 -1
- data/lib/munge/{system → conglomerate}/item_factory/item_identifier.rb +1 -1
- data/lib/munge/conglomerate/processor.rb +138 -0
- data/lib/munge/conglomerate/reader.rb +33 -0
- data/lib/munge/{system → conglomerate}/router.rb +3 -3
- data/lib/munge/{system → conglomerate}/router/itemish.rb +1 -1
- data/lib/munge/{errors.rb → error.rb} +1 -25
- data/lib/munge/{extras → extra}/livereload.rb +5 -5
- data/lib/munge/{extras → extra}/livereload/messaging.rb +1 -1
- data/lib/munge/{extras → extra}/livereload/server.rb +1 -1
- data/lib/munge/{extras → extra}/livereload/update_client.rb +1 -1
- data/lib/munge/{extras → extra}/livereload/update_server.rb +1 -1
- data/lib/munge/{extras → extra}/livereload/vendor/livereload.js +0 -0
- data/lib/munge/{formatters → formatter}/default.rb +1 -1
- data/lib/munge/{formatters → formatter}/dots.rb +1 -1
- data/lib/munge/{formatters → formatter}/silent.rb +1 -1
- data/lib/munge/function/clean.rb +18 -0
- data/lib/munge/function/write.rb +68 -0
- data/lib/munge/go/sass.rb +5 -5
- data/lib/munge/go/sass/asset_urls.rb +2 -2
- data/lib/munge/{helpers → helper}/asset_paths.rb +1 -1
- data/lib/munge/{helpers → helper}/asset_tags.rb +1 -1
- data/lib/munge/{helpers → helper}/capture.rb +1 -1
- data/lib/munge/helper/data.rb +21 -0
- data/lib/munge/helper/define_module.rb +13 -0
- data/lib/munge/{helpers → helper}/find.rb +3 -3
- data/lib/munge/{helpers → helper}/link.rb +3 -3
- data/lib/munge/{helpers → helper}/livereload.rb +1 -1
- data/lib/munge/helper/rendering.rb +51 -0
- data/lib/munge/{helpers → helper}/tag.rb +4 -8
- data/lib/munge/item.rb +4 -5
- data/lib/munge/load.rb +60 -0
- data/lib/munge/pre_init.rb +10 -7
- data/lib/munge/{routers → router}/add_directory_index.rb +1 -1
- data/lib/munge/{routers → router}/auto_add_extension.rb +1 -1
- data/lib/munge/{routers → router}/fingerprint.rb +1 -1
- data/lib/munge/{routers → router}/remove_index_basename.rb +1 -1
- data/lib/munge/version.rb +1 -1
- data/lib/munge/vfs/dry_run.rb +28 -0
- data/lib/munge/vfs/filesystem.rb +44 -0
- data/lib/munge/vfs/memory.rb +33 -0
- data/lib/munge/write_manager/all.rb +11 -11
- data/lib/munge/write_manager/only_needed.rb +9 -9
- data/munge.gemspec +25 -17
- data/seeds/boot.rb +21 -0
- data/seeds/boot.yml +10 -0
- data/seeds/config.rb +7 -0
- data/seeds/layouts/blog_archives.html.erb +1 -1
- data/seeds/layouts/blog_index.html.erb +1 -1
- data/seeds/layouts/default.html.erb +1 -1
- data/seeds/lib/routing.rb +8 -8
- data/seeds/lib/sass.rb +1 -1
- data/seeds/lib/view_helpers.rb +3 -11
- data/seeds/rules.rb +1 -1
- data/seeds/src/home/index.html.erb +1 -1
- metadata +64 -46
- data/lib/munge/cleaner.rb +0 -31
- data/lib/munge/helpers/rendering.rb +0 -100
- data/lib/munge/init.rb +0 -45
- data/lib/munge/io/dry_run.rb +0 -31
- data/lib/munge/io/filesystem.rb +0 -38
- data/lib/munge/io/noop.rb +0 -27
- data/lib/munge/runner.rb +0 -68
- data/lib/munge/system/processor.rb +0 -52
- data/lib/munge/system/readers/filesystem.rb +0 -52
- data/lib/munge/transformers/tilt_transformer.rb +0 -40
- data/lib/munge/util/import.rb +0 -15
- data/seeds/setup.rb +0 -3
data/lib/munge/config.rb
CHANGED
@@ -10,7 +10,7 @@ module Munge
|
|
10
10
|
if @configs.key?(sym_key)
|
11
11
|
@configs[sym_key]
|
12
12
|
else
|
13
|
-
raise
|
13
|
+
raise Error::ConfigKeyNotFound, sym_key
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -28,7 +28,7 @@ module Munge
|
|
28
28
|
elsif key?(method_name)
|
29
29
|
self[method_name]
|
30
30
|
else
|
31
|
-
raise
|
31
|
+
raise Error::ConfigKeyNotFound, method_name
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Munge
|
2
|
-
class
|
2
|
+
class Conglomerate
|
3
3
|
def initialize(root_path, config)
|
4
4
|
@root_path = root_path
|
5
5
|
@config = config
|
@@ -17,28 +17,32 @@ module Munge
|
|
17
17
|
return @items if @items
|
18
18
|
|
19
19
|
source_path = File.expand_path(@config[:source_path], @root_path)
|
20
|
+
vfs = Vfs::Filesystem.new(source_path)
|
20
21
|
|
21
22
|
@items =
|
22
23
|
Collection.new(
|
23
|
-
|
24
|
-
items: Readers::Filesystem.new(source_path)
|
24
|
+
items: Reader.new(vfs, item_factory)
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
28
28
|
def layouts
|
29
|
-
|
29
|
+
if @layouts.nil?
|
30
|
+
layouts_path = File.expand_path(@config[:layouts_path], @root_path)
|
31
|
+
vfs = Vfs::Filesystem.new(layouts_path)
|
30
32
|
|
31
|
-
|
33
|
+
@layouts =
|
34
|
+
Collection.new(
|
35
|
+
items: Reader.new(vfs, item_factory)
|
36
|
+
)
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
)
|
38
|
+
@layouts.each(&:transform)
|
39
|
+
end
|
40
|
+
|
41
|
+
@layouts
|
38
42
|
end
|
39
43
|
|
40
44
|
def processor
|
41
|
-
@processor ||= Processor.new
|
45
|
+
@processor ||= Processor.new(self)
|
42
46
|
end
|
43
47
|
|
44
48
|
def router
|
@@ -49,10 +53,13 @@ module Munge
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def global_data
|
52
|
-
|
56
|
+
if @global_data.nil?
|
57
|
+
data_path = File.expand_path(@config[:data_path], @root_path)
|
58
|
+
loaded_file = YAML.load_file(data_path) || {}
|
59
|
+
@global_data = Munge::Util::SymbolHash.deep_convert(loaded_file)
|
60
|
+
end
|
53
61
|
|
54
|
-
|
55
|
-
@global_data = YAML.load_file(data_path) || {}
|
62
|
+
@global_data
|
56
63
|
end
|
57
64
|
|
58
65
|
attr_reader :config
|
@@ -1,39 +1,18 @@
|
|
1
1
|
module Munge
|
2
|
-
class
|
2
|
+
class Conglomerate
|
3
3
|
# This class is effectively an Array of Items
|
4
4
|
class Collection
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
# @param [
|
7
|
+
# @param [Conglomerate::ItemFactory] item_factory
|
8
8
|
# @param [Array<Hash>] items
|
9
|
-
def initialize(
|
10
|
-
items:)
|
11
|
-
@item_factory = item_factory
|
12
|
-
|
9
|
+
def initialize(items:)
|
13
10
|
@items =
|
14
11
|
items
|
15
|
-
.map { |item| parse(**item) }
|
16
12
|
.map { |item| [item.id, item] }
|
17
13
|
.to_h
|
18
14
|
end
|
19
15
|
|
20
|
-
# @see System::ItemFactory#build
|
21
|
-
# @param relpath [String]
|
22
|
-
# @param content [String]
|
23
|
-
# @param frontmatter [Hash]
|
24
|
-
# @param stat [File::Stat]
|
25
|
-
def build(**args)
|
26
|
-
@item_factory.build(**args)
|
27
|
-
end
|
28
|
-
|
29
|
-
# @see System::ItemFactory#parse
|
30
|
-
# @param relpath [String]
|
31
|
-
# @param content [String]
|
32
|
-
# @param stat [File::Stat]
|
33
|
-
def parse(**args)
|
34
|
-
@item_factory.parse(**args)
|
35
|
-
end
|
36
|
-
|
37
16
|
# @yield [Item]
|
38
17
|
# @return [Enumerator]
|
39
18
|
def each
|
@@ -48,7 +27,7 @@ module Munge
|
|
48
27
|
# @return [void]
|
49
28
|
def push(item)
|
50
29
|
if @items.key?(item.id)
|
51
|
-
raise
|
30
|
+
raise Error::DuplicateItemError, item.id
|
52
31
|
else
|
53
32
|
@items[item.id] = item
|
54
33
|
end
|
@@ -60,7 +39,7 @@ module Munge
|
|
60
39
|
if @items.key?(id)
|
61
40
|
@items[id]
|
62
41
|
else
|
63
|
-
raise
|
42
|
+
raise Error::ItemNotFoundError, id
|
64
43
|
end
|
65
44
|
end
|
66
45
|
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module Munge
|
2
|
+
class Conglomerate
|
3
|
+
class Processor
|
4
|
+
def initialize(conglomerate)
|
5
|
+
@conglomerate = conglomerate
|
6
|
+
|
7
|
+
@fixer_upper = FixerUpper.new
|
8
|
+
@scope_modules = [
|
9
|
+
Munge::Helper::Capture,
|
10
|
+
Munge::Helper::Find,
|
11
|
+
Munge::Helper::Link,
|
12
|
+
Munge::Helper::Rendering,
|
13
|
+
Munge::Helper::Tag,
|
14
|
+
Munge::Helper::AssetPaths,
|
15
|
+
Munge::Helper::AssetTags,
|
16
|
+
Munge::Helper::Livereload,
|
17
|
+
Munge::Helper::Data,
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def register(*names, to:, with_options: {})
|
22
|
+
@fixer_upper.register(*names, engine: to)
|
23
|
+
end
|
24
|
+
|
25
|
+
def register_tilt(*names, to:, with_options: {})
|
26
|
+
@fixer_upper.register_tilt(*names, engine: to, options: with_options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def include(mod)
|
30
|
+
@scope_modules.push(mod)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Transforms the given item's content
|
34
|
+
#
|
35
|
+
# @param item [Item]
|
36
|
+
def transform(item)
|
37
|
+
view_scope = new_view_scope
|
38
|
+
|
39
|
+
view_scope.data_stack.push(item.frontmatter)
|
40
|
+
|
41
|
+
if item.layout
|
42
|
+
layout_item = @conglomerate.layouts[item.layout]
|
43
|
+
|
44
|
+
transform_layout(layout_item, view_scope) do
|
45
|
+
transform_item(item, view_scope)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
transform_item(item, view_scope)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def transform_item(item, view_scope)
|
53
|
+
renderer =
|
54
|
+
@fixer_upper.renderer(
|
55
|
+
filename: item.relpath,
|
56
|
+
content: item.content,
|
57
|
+
view_scope: view_scope,
|
58
|
+
engines: engines_for(item)
|
59
|
+
)
|
60
|
+
|
61
|
+
renderer.call
|
62
|
+
end
|
63
|
+
|
64
|
+
def transform_layout(layout_item, view_scope, &block)
|
65
|
+
renderer =
|
66
|
+
@fixer_upper.renderer(
|
67
|
+
filename: "(layout) #{layout_item.relpath}",
|
68
|
+
content: layout_item.content,
|
69
|
+
view_scope: view_scope,
|
70
|
+
engines: engines_for(layout_item),
|
71
|
+
block: block
|
72
|
+
)
|
73
|
+
|
74
|
+
renderer.call
|
75
|
+
end
|
76
|
+
|
77
|
+
# everything below should be considered private API
|
78
|
+
|
79
|
+
def private_transform(filename:, content:, view_scope:, engines:, block: nil)
|
80
|
+
renderer =
|
81
|
+
@fixer_upper.renderer(
|
82
|
+
filename: filename,
|
83
|
+
content: content,
|
84
|
+
view_scope: view_scope,
|
85
|
+
engines: resolved_engines(engines, resolve_extensions(filename)),
|
86
|
+
block: block
|
87
|
+
)
|
88
|
+
|
89
|
+
renderer.call
|
90
|
+
end
|
91
|
+
|
92
|
+
def engines_for(item, engine_overrides = [])
|
93
|
+
transforms = resolved_engines(item.transforms, item.extensions)
|
94
|
+
overrides = resolved_engines(engine_overrides, item.extensions)
|
95
|
+
|
96
|
+
if overrides.empty?
|
97
|
+
transforms
|
98
|
+
else
|
99
|
+
overrides
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def new_view_scope
|
106
|
+
scope =
|
107
|
+
@scope_modules.reduce(Object.new) do |scope, mod|
|
108
|
+
scope.extend(mod)
|
109
|
+
scope
|
110
|
+
end
|
111
|
+
|
112
|
+
scope.extend(Munge::Helper::DefineModule.new(:conglomerate, @conglomerate))
|
113
|
+
scope.extend(Munge::Helper::DefineModule.new(:current_view_scope, scope))
|
114
|
+
|
115
|
+
scope.data_stack.push(@conglomerate.global_data)
|
116
|
+
|
117
|
+
scope
|
118
|
+
end
|
119
|
+
|
120
|
+
def resolved_engines(engines, extensions)
|
121
|
+
safe_engines = [engines].flatten.compact
|
122
|
+
|
123
|
+
safe_engines.flat_map do |engine|
|
124
|
+
if engine == :use_extensions
|
125
|
+
extensions.reverse
|
126
|
+
else
|
127
|
+
engine
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def resolve_extensions(filename)
|
133
|
+
basename = File.basename(filename)
|
134
|
+
basename.split(".")[1..-1]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Munge
|
2
|
+
class Conglomerate
|
3
|
+
# Enumerable list of {Munge::Item}s
|
4
|
+
class Reader
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
# @param source_path [String]
|
8
|
+
def initialize(vfs, item_factory)
|
9
|
+
@vfs = vfs
|
10
|
+
@item_factory = item_factory
|
11
|
+
end
|
12
|
+
|
13
|
+
# @yield [Item]
|
14
|
+
# @return [Enumerator]
|
15
|
+
def each
|
16
|
+
return enum_for(:each) unless block_given?
|
17
|
+
|
18
|
+
filepaths = @vfs.tree
|
19
|
+
|
20
|
+
filepaths.each do |relpath|
|
21
|
+
item =
|
22
|
+
@item_factory.parse(
|
23
|
+
relpath: relpath,
|
24
|
+
content: @vfs.read(relpath),
|
25
|
+
stat: @vfs.stat(relpath)
|
26
|
+
)
|
27
|
+
|
28
|
+
yield item
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Munge
|
2
|
-
class
|
2
|
+
class Conglomerate
|
3
3
|
class Router
|
4
4
|
def initialize(processor:)
|
5
5
|
@registries = { route: [], filepath: [] }
|
@@ -13,7 +13,7 @@ module Munge
|
|
13
13
|
when :filepath
|
14
14
|
@registries[:filepath].push(router)
|
15
15
|
else
|
16
|
-
raise
|
16
|
+
raise Error::InvalidRouterError, router.type
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -32,7 +32,7 @@ module Munge
|
|
32
32
|
|
33
33
|
def route_mapper(item, method_name, initial_route = nil)
|
34
34
|
if !item.route && !initial_route
|
35
|
-
raise
|
35
|
+
raise Error::ItemHasNoRouteError, item.relpath
|
36
36
|
end
|
37
37
|
|
38
38
|
itemish = Itemish.new(item, @processor)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Munge
|
2
|
-
module
|
2
|
+
module Error
|
3
3
|
class Base < StandardError
|
4
4
|
end
|
5
5
|
|
@@ -41,30 +41,6 @@ module Munge
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
class DuplicateTransformerError < Base
|
45
|
-
include ErrorWithIdentifier
|
46
|
-
|
47
|
-
def message
|
48
|
-
"already registered transformer `#{@identifier}`"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class TransformerNotFoundError < Base
|
53
|
-
include ErrorWithIdentifier
|
54
|
-
|
55
|
-
def message
|
56
|
-
"transformer `#{@identifier}` is not installed"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class InvalidRouterError < Base
|
61
|
-
include ErrorWithIdentifier
|
62
|
-
|
63
|
-
def message
|
64
|
-
"invalid router with type #{@identifier}"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
44
|
class ConfigRbNotFound < Base
|
69
45
|
include ErrorWithIdentifier
|
70
46
|
|
@@ -2,14 +2,14 @@ if Gem.loaded_specs.key?("reel")
|
|
2
2
|
require "celluloid/current"
|
3
3
|
require "reel"
|
4
4
|
|
5
|
-
require "munge/
|
6
|
-
require "munge/
|
7
|
-
require "munge/
|
8
|
-
require "munge/
|
5
|
+
require "munge/extra/livereload/update_server"
|
6
|
+
require "munge/extra/livereload/update_client"
|
7
|
+
require "munge/extra/livereload/messaging"
|
8
|
+
require "munge/extra/livereload/server"
|
9
9
|
end
|
10
10
|
|
11
11
|
module Munge
|
12
|
-
module
|
12
|
+
module Extra
|
13
13
|
module Livereload
|
14
14
|
class Main
|
15
15
|
def initialize(activated)
|