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,5 +1,5 @@
1
1
  module Munge
2
- module Extras
2
+ module Extra
3
3
  module Livereload
4
4
  class UpdateClient
5
5
  include Celluloid
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Extras
2
+ module Extra
3
3
  module Livereload
4
4
  class UpdateServer
5
5
  include Celluloid
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Formatters
2
+ module Formatter
3
3
  class Default
4
4
  def initialize
5
5
  @new_count = 0
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Formatters
2
+ module Formatter
3
3
  class Dots
4
4
  def initialize
5
5
  @counts = Hash.new { 0 }
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Formatters
2
+ module Formatter
3
3
  class Silent
4
4
  def call(_item, _relpath, _write_status, _should_print)
5
5
  end
@@ -0,0 +1,18 @@
1
+ module Munge
2
+ module Function
3
+ class Clean
4
+ def initialize(memory:, destination:)
5
+ @memory = memory
6
+ @destination = destination
7
+ end
8
+
9
+ def call
10
+ orphans = @destination.tree - @memory.tree
11
+
12
+ orphans.each do |orphan|
13
+ @destination.rm(orphan)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,68 @@
1
+ module Munge
2
+ module Function
3
+ class Write
4
+ def initialize(conglomerate:, reporter:, manager:, destination:)
5
+ @items = conglomerate.items
6
+ @router = conglomerate.router
7
+ @processor = conglomerate.processor
8
+ @reporter = reporter
9
+ @manager = manager
10
+ @vfs = destination
11
+ @written_paths = []
12
+ end
13
+
14
+ def call
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
+ route = @router.route(item)
31
+ content = @processor.transform(item)
32
+
33
+ write_status = status(relpath, content)
34
+
35
+ case write_status
36
+ when :new
37
+ @manager.on_new(route, relpath, content)
38
+ when :changed
39
+ @manager.on_changed(route, relpath, content)
40
+ when :identical
41
+ @manager.on_identical(route, relpath, content)
42
+ when :double_write_error
43
+ raise Error::DoubleWriteError, item.route
44
+ end
45
+
46
+ @reporter.call(item, relpath, write_status)
47
+ end
48
+
49
+ def status(path, content)
50
+ if @written_paths.include?(path)
51
+ return :double_write_error
52
+ end
53
+
54
+ @written_paths.push(path)
55
+
56
+ if !@vfs.exist?(path)
57
+ return :new
58
+ end
59
+
60
+ if @vfs.read(path) == content
61
+ return :identical
62
+ end
63
+
64
+ :changed
65
+ end
66
+ end
67
+ end
68
+ end
@@ -14,13 +14,13 @@ module Munge
14
14
  Sass.load_paths << File.join(*paths)
15
15
  end
16
16
 
17
- # Sets {Munge::System} for use with plugins
17
+ # Sets {Munge::Conglomerate} for use with plugins
18
18
  #
19
- # @param system [Munge::System]
19
+ # @param conglomerate [Munge::Conglomerate]
20
20
  # @return [void]
21
- def set_sass_system!(system)
22
- Sass::Script::Functions.send(:define_method, :system) do
23
- system
21
+ def set_sass_conglomerate!(conglomerate)
22
+ Sass::Script::Functions.send(:define_method, :conglomerate) do
23
+ conglomerate
24
24
  end
25
25
  end
26
26
 
@@ -34,8 +34,8 @@ module Sass::Script::Functions
34
34
  def asset_route_helper(root, basename)
35
35
  basename_string = stringify_string(basename)
36
36
 
37
- item = system.items["#{root}/#{basename_string}"]
38
- r = system.router.route(item)
37
+ item = conglomerate.items["#{root}/#{basename_string}"]
38
+ r = conglomerate.router.route(item)
39
39
 
40
40
  quoted_string(r)
41
41
  end
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Helpers
2
+ module Helper
3
3
  module AssetPaths
4
4
  def image_path(basename)
5
5
  item = items["#{images_root}/#{basename}"]
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Helpers
2
+ module Helper
3
3
  module AssetTags
4
4
  def stylesheet_tag(basename, options = {})
5
5
  options[:rel] ||= "stylesheet"
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Helpers
2
+ module Helper
3
3
  module Capture
4
4
  def capture(&block)
5
5
  if block.binding.local_variable_defined?(:_erbout)
@@ -0,0 +1,21 @@
1
+ module Munge
2
+ module Helper
3
+ module Data
4
+ def data_stack
5
+ @data_stack ||= []
6
+ end
7
+
8
+ def globals
9
+ data_stack[0]
10
+ end
11
+
12
+ def instance
13
+ data_stack[1]
14
+ end
15
+
16
+ def frontmatter
17
+ data_stack.last
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Munge
2
+ module Helper
3
+ module DefineModule
4
+ def self.new(name, value)
5
+ Module.new do
6
+ define_method(name) do
7
+ value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,12 +1,12 @@
1
1
  module Munge
2
- module Helpers
2
+ module Helper
3
3
  module Find
4
4
  def items
5
- system.items
5
+ conglomerate.items
6
6
  end
7
7
 
8
8
  def layouts
9
- system.layouts
9
+ conglomerate.layouts
10
10
  end
11
11
  end
12
12
  end
@@ -1,15 +1,15 @@
1
1
  module Munge
2
- module Helpers
2
+ module Helper
3
3
  module Link
4
4
  def path_to(itemish)
5
5
  item =
6
6
  if itemish.is_a?(String)
7
- system.items[itemish]
7
+ conglomerate.items[itemish]
8
8
  else
9
9
  itemish
10
10
  end
11
11
 
12
- system.router.route(item)
12
+ conglomerate.router.route(item)
13
13
  end
14
14
 
15
15
  def link_to(itemish, text = nil, opts = {})
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Helpers
2
+ module Helper
3
3
  module Livereload
4
4
  def livereload_script(force: false)
5
5
  should_show = ENV["MUNGE_ENV"] == "development" && Gem.loaded_specs.key?("reel")
@@ -0,0 +1,51 @@
1
+ module Munge
2
+ module Helper
3
+ module Rendering
4
+ def render(item, engines: :use_extensions, data: {})
5
+ merged_data = item.frontmatter.merge(data)
6
+ inner_view_scope = current_view_scope.clone
7
+ inner_view_scope.instance_variable_set(:@data_stack, data_stack.dup)
8
+ inner_view_scope.data_stack.push(merged_data)
9
+
10
+ conglomerate.processor.private_transform(
11
+ filename: item.relpath,
12
+ content: item.content,
13
+ view_scope: inner_view_scope,
14
+ engines: [engines].flatten.compact
15
+ )
16
+ end
17
+
18
+ def layout(item_or_string, data: {}, &block)
19
+ layout_item =
20
+ if item_or_string.is_a?(String)
21
+ conglomerate.layouts[item_or_string]
22
+ else
23
+ item_or_string
24
+ end
25
+
26
+ inner_as_block =
27
+ if block_given?
28
+ inner = capture(&block)
29
+ -> { inner }
30
+ else
31
+ nil
32
+ end
33
+
34
+ output =
35
+ conglomerate.processor.private_transform(
36
+ filename: "(layout) #{layout_item.relpath}",
37
+ content: layout_item.content,
38
+ view_scope: current_view_scope.clone,
39
+ engines: %i[use_extensions],
40
+ block: inner_as_block
41
+ )
42
+
43
+ if block_given?
44
+ append_to_erbout(block.binding, output)
45
+ end
46
+
47
+ output
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  module Munge
2
- module Helpers
2
+ module Helper
3
3
  module Tag
4
4
  def empty_tag(name, options = {})
5
5
  options_str = options.map { |k, v| %(#{k}="#{h(v)}") }.join(" ")
@@ -17,23 +17,19 @@ module Munge
17
17
  content = nil
18
18
  end
19
19
 
20
- options_str =
20
+ html_attributes =
21
21
  if options.any?
22
22
  " " + options.map { |k, v| %(#{k}="#{h(v)}") }.join(" ")
23
- else
24
- ""
25
23
  end
26
24
 
27
- content_str =
25
+ inner_html =
28
26
  if content
29
27
  content
30
28
  elsif block_given?
31
29
  capture(&block)
32
- else
33
- ""
34
30
  end
35
31
 
36
- "<#{name}#{options_str}>#{content_str}</#{name}>"
32
+ "<#{name}#{html_attributes}>#{inner_html}</#{name}>"
37
33
  end
38
34
 
39
35
  def h(string)
@@ -11,7 +11,7 @@ module Munge
11
11
  @relpath = relpath
12
12
  @id = id
13
13
  @content = content
14
- @frontmatter = frontmatter
14
+ @frontmatter = Munge::Util::SymbolHash.deep_convert(frontmatter)
15
15
  @stat = stat
16
16
 
17
17
  @route = nil
@@ -116,12 +116,11 @@ module Munge
116
116
  @layout = remove_surrounding_slashes(new_layout)
117
117
  end
118
118
 
119
- # @param transformer [Symbol] name of transformer to apply onto item when
119
+ # @param engine [Symbol] name of template engine to apply onto item when
120
120
  # building
121
- # @param *args
122
121
  # @return [void]
123
- def transform(transformer = :tilt, *args)
124
- @transforms.push([transformer, args])
122
+ def transform(engine = :use_extensions)
123
+ @transforms.push(engine)
125
124
  end
126
125
 
127
126
  # Deep freeze. Freezes all instance variables as well as itself.
@@ -0,0 +1,60 @@
1
+ module Munge
2
+ class Load
3
+ def initialize(root_path)
4
+ boot_config_path = File.join(root_path, "boot.yml")
5
+
6
+ @root_path = Pathname.new(root_path)
7
+ @boot_config = YAML.load(File.read(boot_config_path))
8
+ @config = Munge::Config.new
9
+ end
10
+
11
+ def app
12
+ Dir.chdir(@root_path) do
13
+ config_load
14
+
15
+ conglomerate = Munge::Conglomerate.new(@root_path.to_s, @config)
16
+ application = Munge::Application.new(conglomerate)
17
+
18
+ thread_variable_set_helper(@boot_config["conglomerate_key"], conglomerate) do
19
+ thread_variable_set_helper(@boot_config["application_key"], application) do
20
+ thread_variable_set_helper(@boot_config["config_key"], @config) do
21
+ thread_variable_set_helper(@boot_config["root_path_key"], @root_path) do
22
+ load_from_boot_config_key("boot_path")
23
+ load_from_boot_config_key("rules_path")
24
+
25
+ yield application, conglomerate
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def thread_variable_set_helper(key, value)
36
+ Thread.current.thread_variable_set(key, value)
37
+
38
+ result = yield
39
+
40
+ Thread.current.thread_variable_set(key, nil)
41
+
42
+ result
43
+ end
44
+
45
+ def load_from_boot_config_key(key)
46
+ abspath = @root_path.join(@boot_config[key])
47
+
48
+ load abspath
49
+ end
50
+
51
+ def config_load
52
+ return if @loaded_config
53
+ @loaded_config = true
54
+
55
+ thread_variable_set_helper(@boot_config["config_key"], @config) do
56
+ load_from_boot_config_key("config_path")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,10 +1,8 @@
1
1
  module Munge
2
2
  class PreInit
3
- include Munge::Util::Import
4
-
5
3
  def initialize(config_path)
6
4
  if !File.exist?(config_path)
7
- raise Munge::Errors::ConfigRbNotFound, config_path
5
+ raise Munge::Error::ConfigRbNotFound, config_path
8
6
  end
9
7
 
10
8
  @config_path = config_path
@@ -13,16 +11,21 @@ module Munge
13
11
  def config
14
12
  config = Munge::Config.new
15
13
 
16
- import_to_context(@config_path, binding)
14
+ thread_variable_set_helper("config", config) do
15
+ load @config_path
16
+ end
17
17
 
18
18
  config
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- def __end__
24
- contents = File.read(@config_path)
25
- contents.split(/^__END__$/, 2).last
23
+ def thread_variable_set_helper(key, value)
24
+ Thread.current.thread_variable_set(key, value)
25
+
26
+ yield
27
+
28
+ Thread.current.thread_variable_set(key, nil)
26
29
  end
27
30
  end
28
31
  end