munge 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/lib/munge.rb +32 -31
  3. data/lib/munge/application.rb +7 -7
  4. data/lib/munge/bootloader.rb +0 -11
  5. data/lib/munge/cli.rb +3 -3
  6. data/lib/munge/cli/commands/build.rb +17 -21
  7. data/lib/munge/cli/commands/clean.rb +28 -33
  8. data/lib/munge/cli/commands/init.rb +1 -1
  9. data/lib/munge/cli/commands/server.rb +3 -3
  10. data/lib/munge/cli/dispatch.rb +56 -13
  11. data/lib/munge/config.rb +2 -2
  12. data/lib/munge/{system.rb → conglomerate.rb} +21 -14
  13. data/lib/munge/{system → conglomerate}/collection.rb +5 -26
  14. data/lib/munge/{system → conglomerate}/item_factory.rb +1 -1
  15. data/lib/munge/{system → conglomerate}/item_factory/content_parser.rb +1 -1
  16. data/lib/munge/{system → conglomerate}/item_factory/item_identifier.rb +1 -1
  17. data/lib/munge/conglomerate/processor.rb +138 -0
  18. data/lib/munge/conglomerate/reader.rb +33 -0
  19. data/lib/munge/{system → conglomerate}/router.rb +3 -3
  20. data/lib/munge/{system → conglomerate}/router/itemish.rb +1 -1
  21. data/lib/munge/{errors.rb → error.rb} +1 -25
  22. data/lib/munge/{extras → extra}/livereload.rb +5 -5
  23. data/lib/munge/{extras → extra}/livereload/messaging.rb +1 -1
  24. data/lib/munge/{extras → extra}/livereload/server.rb +1 -1
  25. data/lib/munge/{extras → extra}/livereload/update_client.rb +1 -1
  26. data/lib/munge/{extras → extra}/livereload/update_server.rb +1 -1
  27. data/lib/munge/{extras → extra}/livereload/vendor/livereload.js +0 -0
  28. data/lib/munge/{formatters → formatter}/default.rb +1 -1
  29. data/lib/munge/{formatters → formatter}/dots.rb +1 -1
  30. data/lib/munge/{formatters → formatter}/silent.rb +1 -1
  31. data/lib/munge/function/clean.rb +18 -0
  32. data/lib/munge/function/write.rb +68 -0
  33. data/lib/munge/go/sass.rb +5 -5
  34. data/lib/munge/go/sass/asset_urls.rb +2 -2
  35. data/lib/munge/{helpers → helper}/asset_paths.rb +1 -1
  36. data/lib/munge/{helpers → helper}/asset_tags.rb +1 -1
  37. data/lib/munge/{helpers → helper}/capture.rb +1 -1
  38. data/lib/munge/helper/data.rb +21 -0
  39. data/lib/munge/helper/define_module.rb +13 -0
  40. data/lib/munge/{helpers → helper}/find.rb +3 -3
  41. data/lib/munge/{helpers → helper}/link.rb +3 -3
  42. data/lib/munge/{helpers → helper}/livereload.rb +1 -1
  43. data/lib/munge/helper/rendering.rb +51 -0
  44. data/lib/munge/{helpers → helper}/tag.rb +4 -8
  45. data/lib/munge/item.rb +4 -5
  46. data/lib/munge/load.rb +60 -0
  47. data/lib/munge/pre_init.rb +10 -7
  48. data/lib/munge/{routers → router}/add_directory_index.rb +1 -1
  49. data/lib/munge/{routers → router}/auto_add_extension.rb +1 -1
  50. data/lib/munge/{routers → router}/fingerprint.rb +1 -1
  51. data/lib/munge/{routers → router}/remove_index_basename.rb +1 -1
  52. data/lib/munge/version.rb +1 -1
  53. data/lib/munge/vfs/dry_run.rb +28 -0
  54. data/lib/munge/vfs/filesystem.rb +44 -0
  55. data/lib/munge/vfs/memory.rb +33 -0
  56. data/lib/munge/write_manager/all.rb +11 -11
  57. data/lib/munge/write_manager/only_needed.rb +9 -9
  58. data/munge.gemspec +25 -17
  59. data/seeds/boot.rb +21 -0
  60. data/seeds/boot.yml +10 -0
  61. data/seeds/config.rb +7 -0
  62. data/seeds/layouts/blog_archives.html.erb +1 -1
  63. data/seeds/layouts/blog_index.html.erb +1 -1
  64. data/seeds/layouts/default.html.erb +1 -1
  65. data/seeds/lib/routing.rb +8 -8
  66. data/seeds/lib/sass.rb +1 -1
  67. data/seeds/lib/view_helpers.rb +3 -11
  68. data/seeds/rules.rb +1 -1
  69. data/seeds/src/home/index.html.erb +1 -1
  70. metadata +64 -46
  71. data/lib/munge/cleaner.rb +0 -31
  72. data/lib/munge/helpers/rendering.rb +0 -100
  73. data/lib/munge/init.rb +0 -45
  74. data/lib/munge/io/dry_run.rb +0 -31
  75. data/lib/munge/io/filesystem.rb +0 -38
  76. data/lib/munge/io/noop.rb +0 -27
  77. data/lib/munge/runner.rb +0 -68
  78. data/lib/munge/system/processor.rb +0 -52
  79. data/lib/munge/system/readers/filesystem.rb +0 -52
  80. data/lib/munge/transformers/tilt_transformer.rb +0 -40
  81. data/lib/munge/util/import.rb +0 -15
  82. data/seeds/setup.rb +0 -3
@@ -1,31 +0,0 @@
1
- module Munge
2
- class Cleaner
3
- def initialize(path_to_clean:, paths_to_write:, io:)
4
- @path_to_clean = path_to_clean
5
- @paths_to_write = paths_to_write
6
- @io = io
7
- end
8
-
9
- def orphans
10
- existing_files - @paths_to_write
11
- end
12
-
13
- def delete
14
- orphans.each { |orphan| @io.rm(orphan) }
15
-
16
- Dir.glob(File.join(@path_to_clean, "**", "*")).reverse_each do |dir|
17
- if !File.directory?(dir)
18
- next
19
- end
20
-
21
- @io.rmdir(dir)
22
- end
23
- end
24
-
25
- private
26
-
27
- def existing_files
28
- Dir.glob(File.join(@path_to_clean, "**", "*")).select { |path| File.file?(path) }
29
- end
30
- end
31
- end
@@ -1,100 +0,0 @@
1
- module Munge
2
- module Helpers
3
- module Rendering
4
- def render(item, engines: nil, data: {}, content_override: nil)
5
- content = content_override || item.content
6
- renderers = tilt_renderer_list(item, engines)
7
- mdata = merged_data(item.frontmatter, data, self_item: item)
8
- item_path = item.relpath
9
-
10
- render_string(content, data: mdata, engines: renderers, template_name: item_path)
11
- end
12
-
13
- def layout(item_or_string, data: {}, &block)
14
- layout_item = resolve_layout(item_or_string)
15
- renderers = tilt_renderer_list(layout_item, nil)
16
- mdata = merged_data(layout_item.frontmatter, data, self_layout: layout_item)
17
- layout_path = "(layout) #{layout_item.relpath}"
18
-
19
- render_string(layout_item.content, data: mdata, engines: renderers, template_name: layout_path, &block)
20
- end
21
-
22
- def render_string(content, data: {}, engines: [], template_name: nil, &block)
23
- inner =
24
- if block_given?
25
- capture(&block)
26
- end
27
-
28
- output =
29
- engines
30
- .reduce(content) do |memoized_content, engine|
31
- options = tilt_options[engine]
32
- template = engine.new(template_name, options) { memoized_content }
33
-
34
- template.render(self, data) { inner }
35
- end
36
-
37
- if block_given?
38
- append_to_erbout(block.binding, output)
39
- end
40
-
41
- output
42
- end
43
-
44
- def render_with_layout(item, content_engines: nil, data: {}, content_override: nil)
45
- inner = render(item, engines: content_engines, data: data, content_override: content_override)
46
- mdata = merged_data(item.frontmatter, data, self_item: item)
47
-
48
- if item.layout
49
- layout(item.layout, data: mdata) do
50
- inner
51
- end
52
- else
53
- inner
54
- end
55
- end
56
-
57
- private
58
-
59
- def merged_data(*data)
60
- hash_with_string_and_symbol_keys =
61
- data.reduce(system.global_data) do |merged, datum|
62
- merged.merge(datum)
63
- end
64
-
65
- Munge::Util::SymbolHash.deep_convert(hash_with_string_and_symbol_keys)
66
- end
67
-
68
- def resolve_layout(item_or_string)
69
- if item_or_string.is_a?(String)
70
- system.layouts[item_or_string]
71
- else
72
- item_or_string
73
- end
74
- end
75
-
76
- def tilt_renderer_list(item, preferred_engine)
77
- if preferred_engine
78
- tilt_renderers_from_preferred(preferred_engine)
79
- else
80
- tilt_renderers_from_path(item.relpath)
81
- end
82
- end
83
-
84
- def tilt_renderers_from_path(path)
85
- ::Tilt.templates_for(path)
86
- end
87
-
88
- def tilt_renderers_from_preferred(preferred_engines)
89
- preferred =
90
- if preferred_engines.is_a?(Array)
91
- preferred_engines.flatten.join(".")
92
- else
93
- preferred_engines
94
- end
95
-
96
- ::Tilt.templates_for(preferred)
97
- end
98
- end
99
- end
100
- end
@@ -1,45 +0,0 @@
1
- module Munge
2
- # This class loads the user rules, as well as provides some useful methods
3
- # for setup.
4
- class Init
5
- include Munge::Util::Import
6
-
7
- # Initializing loads up the user's `setup.rb` and `rules.rb`.
8
- def initialize(root_path:,
9
- config:,
10
- setup_path:,
11
- rules_path:)
12
- @root_path = root_path
13
- @setup_path = setup_path
14
- @rules_path = rules_path
15
- @binding = binding
16
-
17
- system = Munge::System.new(root_path, config)
18
-
19
- import(setup_path)
20
-
21
- @app = Munge::Application.new(system)
22
-
23
- import(rules_path)
24
-
25
- @app.items.each(&:freeze)
26
- @app.items.freeze
27
- end
28
-
29
- # @return [String] path to user's `lib/` directory
30
- def lib_path
31
- File.join(root_path, "lib")
32
- end
33
-
34
- # Loads file into current scope. Similar to `load "filename.rb"`
35
- #
36
- # @return [void]
37
- def import(file_path)
38
- absolute_file_path = File.expand_path(file_path, root_path)
39
- import_to_context(absolute_file_path, @binding)
40
- end
41
-
42
- attr_reader :app
43
- attr_reader :root_path
44
- end
45
- end
@@ -1,31 +0,0 @@
1
- module Munge
2
- module Io
3
- # NoOp driver for writing files. This is used to compute dry-runs.
4
- class DryRun
5
- def initialize(driver)
6
- @driver = driver
7
- end
8
-
9
- # Pretends to write, but actually does nothing
10
- #
11
- # @param _abspath [String]
12
- # @param _content [String]
13
- def write(_abspath, _content)
14
- end
15
-
16
- def exist?(path)
17
- @driver.exist?(path)
18
- end
19
-
20
- def read(path)
21
- @driver.read(path)
22
- end
23
-
24
- def rm(_path)
25
- end
26
-
27
- def rmdir(_path)
28
- end
29
- end
30
- end
31
- end
@@ -1,38 +0,0 @@
1
- module Munge
2
- module Io
3
- # Filesystem driver for writing files. These drivers can be defined however
4
- # you wish, as long as the `#write` method accepts an abspath and content.
5
- class Filesystem
6
- # Writes content to abspath. Nonexistent directories will be created
7
- # automatically.
8
- #
9
- # @param abspath [String]
10
- # @param content [String]
11
- def write(abspath, content)
12
- FileUtils.mkdir_p(File.dirname(abspath))
13
-
14
- File.write(abspath, content)
15
- end
16
-
17
- def exist?(path)
18
- File.exist?(path)
19
- end
20
-
21
- def read(path)
22
- File.read(path)
23
- end
24
-
25
- def rm(path)
26
- File.delete(path)
27
- end
28
-
29
- def rmdir(path)
30
- contents = Dir.entries(path) - %w(. ..)
31
-
32
- if contents.empty?
33
- Dir.rmdir(path)
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,27 +0,0 @@
1
- module Munge
2
- module Io
3
- # NoOp driver for writing files. This is used to compute dry-runs.
4
- class Noop
5
- # Pretends to write, but actually does nothing
6
- #
7
- # @param _abspath [String]
8
- # @param _content [String]
9
- def write(_abspath, _content)
10
- end
11
-
12
- def exist?(_path)
13
- false
14
- end
15
-
16
- def read(_path)
17
- ""
18
- end
19
-
20
- def rm(_path)
21
- end
22
-
23
- def rmdir(_path)
24
- end
25
- end
26
- end
27
- end
@@ -1,68 +0,0 @@
1
- module Munge
2
- class Runner
3
- def initialize(items:, router:, processor:, io:, reporter:, destination:, manager:)
4
- @items = items
5
- @router = router
6
- @processor = processor
7
- @io = io
8
- @reporter = reporter
9
- @destination = destination
10
- @manager = manager
11
- @written_paths = []
12
- end
13
-
14
- def write
15
- @reporter.start
16
-
17
- @items
18
- .reject { |item| item.route.nil? }
19
- .each { |item| render_and_write(item) }
20
-
21
- @reporter.done
22
-
23
- @manager.written_routes
24
- end
25
-
26
- private
27
-
28
- def render_and_write(item)
29
- relpath = @router.filepath(item)
30
- abspath = File.join(@destination, relpath)
31
- route = @router.route(item)
32
- content = @processor.transform(item)
33
-
34
- write_status = status(abspath, content)
35
-
36
- case write_status
37
- when :new
38
- @manager.on_new(route, abspath, content)
39
- when :changed
40
- @manager.on_changed(route, abspath, content)
41
- when :identical
42
- @manager.on_identical(route, abspath, content)
43
- when :double_write_error
44
- raise Errors::DoubleWriteError, item.route
45
- end
46
-
47
- @reporter.call(item, relpath, write_status)
48
- end
49
-
50
- def status(path, content)
51
- if @written_paths.include?(path)
52
- return :double_write_error
53
- end
54
-
55
- @written_paths.push(path)
56
-
57
- if !@io.exist?(path)
58
- return :new
59
- end
60
-
61
- if @io.read(path) == content
62
- return :identical
63
- end
64
-
65
- :changed
66
- end
67
- end
68
- end
@@ -1,52 +0,0 @@
1
- module Munge
2
- class System
3
- class Processor
4
- def initialize
5
- @registry = {}
6
- end
7
-
8
- # Register tranformer
9
- #
10
- # @see Munge::Transformers::Tilt
11
- def register(transformer)
12
- register_manually(transformer.name, transformer)
13
- end
14
-
15
- # Register transformer manually
16
- #
17
- # @see Munge::Transformers::Tilt
18
- # @param name [Symbol] Snake case name
19
- # @param transformer [#call]
20
- def register_manually(name, transformer)
21
- if @registry.key?(name)
22
- raise Errors::DuplicateTransformerError, name
23
- else
24
- @registry[name] = transformer
25
- end
26
- end
27
-
28
- # Transforms the given item's content
29
- #
30
- # @param item [Item]
31
- def transform(item)
32
- item.transforms
33
- .map { |name, args| [get_transformer(name), args] }
34
- .reduce(item.content) do |content, params|
35
- transformer, args = params
36
-
37
- transformer.call(item, content, *args)
38
- end
39
- end
40
-
41
- private
42
-
43
- def get_transformer(name)
44
- if @registry.key?(name)
45
- @registry[name]
46
- else
47
- raise Errors::TransformerNotFoundError, name
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,52 +0,0 @@
1
- module Munge
2
- class System
3
- module Readers
4
- # Enumerable list of {Munge::Item}s
5
- class Filesystem
6
- include Enumerable
7
-
8
- # @param source_path [String]
9
- def initialize(source_path)
10
- @source_path = source_path
11
- end
12
-
13
- # @yield [Item]
14
- # @return [Enumerator]
15
- def each
16
- return enum_for(:each) unless block_given?
17
-
18
- filepaths =
19
- Dir.glob(File.join(@source_path, "**", "*"))
20
- .select { |path| File.file?(path) }
21
-
22
- filepaths.each do |abspath|
23
- filehash = Hash[
24
- relpath: compute_relpath(abspath),
25
- content: compute_content(abspath),
26
- stat: compute_stat(abspath)
27
- ]
28
-
29
- yield filehash
30
- end
31
- end
32
-
33
- private
34
-
35
- def compute_stat(abspath)
36
- File.stat(abspath)
37
- end
38
-
39
- def compute_relpath(abspath)
40
- folder = Pathname.new(@source_path)
41
- file = Pathname.new(abspath)
42
-
43
- file.relative_path_from(folder).to_s
44
- end
45
-
46
- def compute_content(abspath)
47
- File.read(abspath)
48
- end
49
- end
50
- end
51
- end
52
- end