benoit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/.gitignore +4 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +1 -0
  4. data/.rspec-turnip +1 -0
  5. data/.ruby-version +1 -0
  6. data/Assetfile +44 -0
  7. data/Gemfile +5 -0
  8. data/Gemfile.lock +110 -0
  9. data/Rakefile +9 -0
  10. data/benoit.gemspec +50 -0
  11. data/bin/benoit +121 -0
  12. data/bin/bundle-development +1 -0
  13. data/bin/bundle-sandbox +1 -0
  14. data/lib/benoit.rb +36 -0
  15. data/lib/benoit/cadenza.rb +11 -0
  16. data/lib/benoit/cadenza/output_filters.rb +21 -0
  17. data/lib/benoit/cleaner.rb +10 -0
  18. data/lib/benoit/compiler_error.rb +49 -0
  19. data/lib/benoit/configuration.rb +24 -0
  20. data/lib/benoit/current_site.rb +12 -0
  21. data/lib/benoit/file_wrapper_extensions.rb +13 -0
  22. data/lib/benoit/filters.rb +15 -0
  23. data/lib/benoit/filters/base_filter.rb +44 -0
  24. data/lib/benoit/filters/blacklist_filter.rb +18 -0
  25. data/lib/benoit/filters/cadenza_filter.rb +75 -0
  26. data/lib/benoit/filters/content_page_filter.rb +45 -0
  27. data/lib/benoit/filters/markdown_filter.rb +19 -0
  28. data/lib/benoit/filters/metadata_cleaner.rb +30 -0
  29. data/lib/benoit/filters/move_to_root_filter.rb +22 -0
  30. data/lib/benoit/filters/pagination_filter.rb +23 -0
  31. data/lib/benoit/filters/pass_thru_filter.rb +22 -0
  32. data/lib/benoit/filters/sass_filter.rb +74 -0
  33. data/lib/benoit/filters/set_metadata_filter.rb +15 -0
  34. data/lib/benoit/logger.rb +69 -0
  35. data/lib/benoit/page.rb +88 -0
  36. data/lib/benoit/page_metadata.rb +8 -0
  37. data/lib/benoit/page_metadata/container.rb +74 -0
  38. data/lib/benoit/page_metadata/json_converter.rb +28 -0
  39. data/lib/benoit/page_metadata/parser.rb +38 -0
  40. data/lib/benoit/page_metadata/store.rb +75 -0
  41. data/lib/benoit/pipeline.rb +1 -0
  42. data/lib/benoit/pipeline/dsl_extensions.rb +8 -0
  43. data/lib/benoit/pipeline/pagination_matcher.rb +53 -0
  44. data/lib/benoit/pipeline_project.rb +81 -0
  45. data/lib/benoit/site_context.rb +123 -0
  46. data/lib/benoit/utils/finds_layouts_for_template.rb +77 -0
  47. data/lib/benoit/utils/normalizes_path_to_template.rb +43 -0
  48. data/lib/benoit/utils/paginated_list.rb +102 -0
  49. data/lib/benoit/version.rb +3 -0
  50. data/lib/build_notifiers/file_built_notifier.rb +20 -0
  51. data/lib/build_notifiers/progress_notifier.rb +57 -0
  52. data/lib/cli.rb +39 -0
  53. data/spec/.rbenv-gemsets +1 -0
  54. data/spec/Gemfile +9 -0
  55. data/spec/Gemfile.lock +57 -0
  56. data/spec/bin/autospec +16 -0
  57. data/spec/bin/cucumber +16 -0
  58. data/spec/bin/htmldiff +16 -0
  59. data/spec/bin/ldiff +16 -0
  60. data/spec/bin/rspec +16 -0
  61. data/spec/features/build_command.feature +46 -0
  62. data/spec/features/frontmatter_metadata.feature +99 -0
  63. data/spec/features/javascript_files.feature +35 -0
  64. data/spec/features/output_filters.feature +20 -0
  65. data/spec/features/page_layouts.feature +72 -0
  66. data/spec/features/pagination.feature +58 -0
  67. data/spec/features/sass_files.feature +30 -0
  68. data/spec/features/version.feature +5 -0
  69. data/spec/lib/filters/base_filter_spec.rb +141 -0
  70. data/spec/lib/filters/markdown_filter_spec.rb +65 -0
  71. data/spec/lib/filters/sass_filter_spec.rb +73 -0
  72. data/spec/lib/metadata_json_converter_spec.rb +65 -0
  73. data/spec/lib/metadata_store_spec.rb +148 -0
  74. data/spec/lib/page_spec.rb +19 -0
  75. data/spec/lib/site_context_spec.rb +106 -0
  76. data/spec/spec_helper.rb +16 -0
  77. data/spec/steps/output_file_steps.rb +45 -0
  78. data/spec/steps/run_steps.rb +71 -0
  79. data/spec/steps/staticly_steps.rb +194 -0
  80. data/spec/support/aruba/rspec.rb +66 -0
  81. data/spec/support/files/img.png +0 -0
  82. data/spec/support/files/input.css.scss +7 -0
  83. data/spec/support/files/input.scss +7 -0
  84. data/spec/support/spec_helpers/file_helpers.rb +8 -0
  85. data/spec/support/spec_helpers/memory_file_wrapper.rb +43 -0
  86. data/spec/support/spec_helpers/memory_manifest.rb +19 -0
  87. data/spec/turnip_helper.rb +19 -0
  88. data/vendor/frontmatter/frontmatter.gemspec +24 -0
  89. data/vendor/frontmatter/lib/frontmatter.rb +92 -0
  90. data/vendor/frontmatter/lib/frontmatter/version.rb +3 -0
  91. data/vendor/rake-pipeline/.gitignore +18 -0
  92. data/vendor/rake-pipeline/.rspec +1 -0
  93. data/vendor/rake-pipeline/.travis.yml +12 -0
  94. data/vendor/rake-pipeline/.yardopts +2 -0
  95. data/vendor/rake-pipeline/GETTING_STARTED.md +268 -0
  96. data/vendor/rake-pipeline/Gemfile +14 -0
  97. data/vendor/rake-pipeline/LICENSE +20 -0
  98. data/vendor/rake-pipeline/README.markdown +11 -0
  99. data/vendor/rake-pipeline/README.yard +178 -0
  100. data/vendor/rake-pipeline/Rakefile +21 -0
  101. data/vendor/rake-pipeline/bin/rakep +4 -0
  102. data/vendor/rake-pipeline/examples/copying_files.md +12 -0
  103. data/vendor/rake-pipeline/examples/minifying_files.md +37 -0
  104. data/vendor/rake-pipeline/examples/modifying_pipelines.md +67 -0
  105. data/vendor/rake-pipeline/examples/multiple_pipelines.md +77 -0
  106. data/vendor/rake-pipeline/lib/generators/rake/pipeline/install/install_generator.rb +70 -0
  107. data/vendor/rake-pipeline/lib/rake-pipeline.rb +509 -0
  108. data/vendor/rake-pipeline/lib/rake-pipeline/cli.rb +57 -0
  109. data/vendor/rake-pipeline/lib/rake-pipeline/dsl.rb +9 -0
  110. data/vendor/rake-pipeline/lib/rake-pipeline/dsl/pipeline_dsl.rb +246 -0
  111. data/vendor/rake-pipeline/lib/rake-pipeline/dsl/project_dsl.rb +108 -0
  112. data/vendor/rake-pipeline/lib/rake-pipeline/dynamic_file_task.rb +194 -0
  113. data/vendor/rake-pipeline/lib/rake-pipeline/error.rb +17 -0
  114. data/vendor/rake-pipeline/lib/rake-pipeline/file_wrapper.rb +195 -0
  115. data/vendor/rake-pipeline/lib/rake-pipeline/filter.rb +267 -0
  116. data/vendor/rake-pipeline/lib/rake-pipeline/filters.rb +4 -0
  117. data/vendor/rake-pipeline/lib/rake-pipeline/filters/concat_filter.rb +63 -0
  118. data/vendor/rake-pipeline/lib/rake-pipeline/filters/gsub_filter.rb +56 -0
  119. data/vendor/rake-pipeline/lib/rake-pipeline/filters/ordering_concat_filter.rb +38 -0
  120. data/vendor/rake-pipeline/lib/rake-pipeline/filters/pipeline_finalizing_filter.rb +21 -0
  121. data/vendor/rake-pipeline/lib/rake-pipeline/graph.rb +178 -0
  122. data/vendor/rake-pipeline/lib/rake-pipeline/manifest.rb +82 -0
  123. data/vendor/rake-pipeline/lib/rake-pipeline/manifest_entry.rb +34 -0
  124. data/vendor/rake-pipeline/lib/rake-pipeline/matcher.rb +141 -0
  125. data/vendor/rake-pipeline/lib/rake-pipeline/middleware.rb +73 -0
  126. data/vendor/rake-pipeline/lib/rake-pipeline/precompile.rake +8 -0
  127. data/vendor/rake-pipeline/lib/rake-pipeline/project.rb +338 -0
  128. data/vendor/rake-pipeline/lib/rake-pipeline/rails_plugin.rb +10 -0
  129. data/vendor/rake-pipeline/lib/rake-pipeline/railtie.rb +34 -0
  130. data/vendor/rake-pipeline/lib/rake-pipeline/reject_matcher.rb +29 -0
  131. data/vendor/rake-pipeline/lib/rake-pipeline/server.rb +15 -0
  132. data/vendor/rake-pipeline/lib/rake-pipeline/sorted_pipeline.rb +19 -0
  133. data/vendor/rake-pipeline/lib/rake-pipeline/version.rb +6 -0
  134. data/vendor/rake-pipeline/rails/init.rb +2 -0
  135. data/vendor/rake-pipeline/rake-pipeline.gemspec +24 -0
  136. data/vendor/rake-pipeline/spec/cli_spec.rb +73 -0
  137. data/vendor/rake-pipeline/spec/concat_filter_spec.rb +37 -0
  138. data/vendor/rake-pipeline/spec/dsl/pipeline_dsl_spec.rb +165 -0
  139. data/vendor/rake-pipeline/spec/dsl/project_dsl_spec.rb +41 -0
  140. data/vendor/rake-pipeline/spec/dynamic_file_task_spec.rb +119 -0
  141. data/vendor/rake-pipeline/spec/encoding_spec.rb +106 -0
  142. data/vendor/rake-pipeline/spec/file_wrapper_spec.rb +132 -0
  143. data/vendor/rake-pipeline/spec/filter_spec.rb +367 -0
  144. data/vendor/rake-pipeline/spec/graph_spec.rb +56 -0
  145. data/vendor/rake-pipeline/spec/gsub_filter_spec.rb +87 -0
  146. data/vendor/rake-pipeline/spec/manifest_entry_spec.rb +46 -0
  147. data/vendor/rake-pipeline/spec/manifest_spec.rb +67 -0
  148. data/vendor/rake-pipeline/spec/matcher_spec.rb +141 -0
  149. data/vendor/rake-pipeline/spec/middleware_spec.rb +199 -0
  150. data/vendor/rake-pipeline/spec/ordering_concat_filter_spec.rb +42 -0
  151. data/vendor/rake-pipeline/spec/pipeline_spec.rb +232 -0
  152. data/vendor/rake-pipeline/spec/project_spec.rb +295 -0
  153. data/vendor/rake-pipeline/spec/rake_acceptance_spec.rb +720 -0
  154. data/vendor/rake-pipeline/spec/rake_tasks_spec.rb +21 -0
  155. data/vendor/rake-pipeline/spec/reject_matcher_spec.rb +31 -0
  156. data/vendor/rake-pipeline/spec/sorted_pipeline_spec.rb +27 -0
  157. data/vendor/rake-pipeline/spec/spec_helper.rb +38 -0
  158. data/vendor/rake-pipeline/spec/support/spec_helpers/file_utils.rb +35 -0
  159. data/vendor/rake-pipeline/spec/support/spec_helpers/filters.rb +37 -0
  160. data/vendor/rake-pipeline/spec/support/spec_helpers/input_helpers.rb +23 -0
  161. data/vendor/rake-pipeline/spec/support/spec_helpers/memory_file_wrapper.rb +35 -0
  162. data/vendor/rake-pipeline/spec/support/spec_helpers/memory_manifest.rb +19 -0
  163. data/vendor/rake-pipeline/tools/perfs +101 -0
  164. metadata +497 -0
@@ -0,0 +1,4 @@
1
+ require "rake-pipeline/filters/concat_filter"
2
+ require "rake-pipeline/filters/ordering_concat_filter"
3
+ require "rake-pipeline/filters/pipeline_finalizing_filter"
4
+ require "rake-pipeline/filters/gsub_filter"
@@ -0,0 +1,63 @@
1
+ module Rake
2
+ class Pipeline
3
+ # A built-in filter that simply accepts a series
4
+ # of inputs and concatenates them into output files
5
+ # based on the output file name generator.
6
+ #
7
+ # @example
8
+ # !!!ruby
9
+ # Pipeline.build do
10
+ # input "app/assets", "**/*.js"
11
+ # output "public"
12
+ #
13
+ # # create a concatenated output file for each
14
+ # # directory of inputs.
15
+ # filter(Rake::Pipeline::ConcatFilter) do |input|
16
+ # # input files will look something like:
17
+ # # javascripts/admin/main.js
18
+ # # javascripts/admin/app.js
19
+ # # javascripts/users/main.js
20
+ # #
21
+ # # and the outputs will look like:
22
+ # # javascripts/admin.js
23
+ # # javascripts/users.js
24
+ # directory = File.dirname(input)
25
+ # ext = File.extname(input)
26
+ #
27
+ # "#{directory}#{ext}"
28
+ # end
29
+ # end
30
+ class ConcatFilter < Rake::Pipeline::Filter
31
+ # @param [String] string the name of the output file to
32
+ # concatenate inputs to.
33
+ # @param [Proc] block a block to use as the Filter's
34
+ # {#output_name_generator}.
35
+ def initialize(string=nil, &block)
36
+ block = proc { string } if string
37
+ super(&block)
38
+ end
39
+
40
+ # @method encoding
41
+ # @return [String] the String +"BINARY"+
42
+ processes_binary_files
43
+
44
+ # implement the {#generate_output} method required by
45
+ # the {Filter} API. In this case, simply loop through
46
+ # the inputs and write their contents to the output.
47
+ #
48
+ # Recall that this method will be called once for each
49
+ # unique output file.
50
+ #
51
+ # @param [Array<FileWrapper>] inputs an Array of
52
+ # {FileWrapper} objects representing the inputs to
53
+ # this filter.
54
+ # @param [FileWrapper] a single {FileWrapper} object
55
+ # representing the output.
56
+ def generate_output(inputs, output)
57
+ inputs.each do |input|
58
+ output.write input.read
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,56 @@
1
+ module Rake
2
+ class Pipeline
3
+ # A built in filter that applies String#gsub behavior.
4
+ #
5
+ # @example
6
+ # !!!ruby
7
+ # Pipeline.build do
8
+ # input "app/assets", "**/*.js"
9
+ # output "public"
10
+ #
11
+ # # replace javascript comments
12
+ # filter(Rake::Pipeline::GsubFilter, /\//\w+$/, '')
13
+ # end
14
+ class GsubFilter < Filter
15
+ # Arguments mimic String#gsub with one notable exception.
16
+ # String#gsub accepts a block where $1, $2, and friends are
17
+ # accessible. Due to Ruby's scoping rules of these variables
18
+ # they are not accssible inside the block itself. Instead they
19
+ # are passed in as additional arguments. Here's an example:
20
+ #
21
+ # @example
22
+ # !!!ruby
23
+ # Rake::Pipeline::GsubFilter.new /(\w+)\s(\w+)/ do |entire_match, capture1, capture2|
24
+ # # process the match
25
+ # end
26
+ #
27
+ # @see String#gsub
28
+ def initialize(*args, &block)
29
+ @args, @block = args, block
30
+ super() { |input| input }
31
+ end
32
+
33
+ # Implement the {#generate_output} method required by
34
+ # the {Filter} API. In this case, simply loop through
35
+ # the inputs and write String#gsub content to the output.
36
+ #
37
+ # @param [Array<FileWrapper>] inputs an Array of
38
+ # {FileWrapper} objects representing the inputs to
39
+ # this filter.
40
+ # @param [FileWrapper] a single {FileWrapper} object
41
+ # representing the output.
42
+ def generate_output(inputs, output)
43
+ inputs.each do |input|
44
+ if @block
45
+ content = input.read.gsub(*@args) do |match|
46
+ @block.call match, *$~.captures
47
+ end
48
+ output.write content
49
+ else
50
+ output.write input.read.gsub(*@args)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,38 @@
1
+ class Rake::Pipeline
2
+ # A filter that concats files in a specified order.
3
+ #
4
+ # @example
5
+ # !!!ruby
6
+ # Rake::Pipeline.build do
7
+ # input "app/assets", "**/*.js"
8
+ # output "public"
9
+ #
10
+ # # Concat each file into libs.js but make sure
11
+ # # that jQuery and Ember come first.
12
+ # filter Rake::Pipeline::OrderingConcatFilter, ["jquery.js", "ember.js"], "libs.js"
13
+ # end
14
+ class OrderingConcatFilter < ConcatFilter
15
+
16
+ # @param [Array<String>] ordering an Array of Strings
17
+ # of file names that should come in the specified order
18
+ # @param [String] string the name of the output file to
19
+ # concatenate inputs to.
20
+ # @param [Proc] block a block to use as the Filter's
21
+ # {#output_name_generator}.
22
+ def initialize(ordering, string=nil, &block)
23
+ @ordering = ordering
24
+ super(string, &block)
25
+ end
26
+
27
+ # Extend the {#generate_output} method supplied by {ConcatFilter}.
28
+ # Re-orders the inputs such that the specified files come first.
29
+ # If a file is not in the list it will come after the specified files.
30
+ def generate_output(inputs, output)
31
+ @ordering.reverse.each do |name|
32
+ file = inputs.find{|i| i.path == name }
33
+ inputs.unshift(inputs.delete(file)) if file
34
+ end
35
+ super
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ require 'set'
2
+ module Rake
3
+ class Pipeline
4
+ # @private
5
+ #
6
+ # A built-in filter that copies a pipeline's generated files over
7
+ # to its output.
8
+ class PipelineFinalizingFilter < ConcatFilter
9
+
10
+ # @return [Array[FileWrapper]] a list of the pipeline's
11
+ # output files, excluding any files that were originally
12
+ # inputs to the pipeline, meaning they weren't processed
13
+ # by any filter and should not be copied to the output.
14
+ def input_files
15
+ pipeline_input_files = Set.new pipeline.input_files
16
+
17
+ Set.new(super) - pipeline_input_files
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,178 @@
1
+ require "set"
2
+
3
+ module Rake
4
+ class Pipeline
5
+ # The goal of this class is to make is easy to implement dynamic
6
+ # dependencies in additional_dependencies without having to parse
7
+ # all the files all of the time.
8
+ #
9
+ # To illustrate, imagine that we have two source files with the
10
+ # following inline dependencies:
11
+ #
12
+ # * application.scss
13
+ # * _core.scss
14
+ # * admin.scss
15
+ # * _admin.scss
16
+ #
17
+ # And further imagine that `_admin.scss` has an inline dependency
18
+ # on `_core.scss`.
19
+ #
20
+ # On initial build, we will scan all of the source files, find
21
+ # the dependencies, and build a node for each file, annotating
22
+ # the source files with `:source => true`. We also store off the
23
+ # `mtime` of each file in its node. We link each file to its
24
+ # dependencies.
25
+ #
26
+ # The `additional_dependencies` are a map of the files to their
27
+ # children, which will be used when generating rake tasks.
28
+ #
29
+ # Later, let's say that we change `_admin.scss`. We will need
30
+ # to unlink its dependencies first (on `_core.scss`), rescan
31
+ # the file, and create nodes for its dependencies. If no new
32
+ # dependencies
33
+
34
+ class Graph
35
+ class MissingNode < StandardError
36
+ end
37
+
38
+ class Node
39
+ # @return [String] the identifier of the node
40
+ attr_reader :name
41
+
42
+ # @return [Set] a Set of parent nodes
43
+ attr_reader :parents
44
+
45
+ # @return [Set] a Set of child nodes
46
+ attr_reader :children
47
+
48
+ # @return [Hash] a Hash of metadata
49
+ attr_reader :metadata
50
+
51
+ # @param [String] name the identifier of the node
52
+ # @param [Hash] metadata an optional hash of metadata
53
+ def initialize(name, metadata={})
54
+ @name = name
55
+ @parents = Set.new
56
+ @children = Set.new
57
+ @metadata = metadata
58
+ end
59
+
60
+ # A node is equal another node if it has the same name.
61
+ # This is because the Graph ensures that only one node
62
+ # with a given name can be created.
63
+ #
64
+ # @param [Node] other the node to compare
65
+ def ==(other)
66
+ @name == other.name
67
+ end
68
+ end
69
+
70
+ def initialize
71
+ @map = {}
72
+ end
73
+
74
+ # @return [Array] an Array of all of the nodes in the graph
75
+ def nodes
76
+ @map.values
77
+ end
78
+
79
+ # Add a new node to the graph. If an existing node with the
80
+ # current name already exists, do not add the node.
81
+ #
82
+ # @param [String] name an identifier for the node.
83
+ # @param [Hash] metadata optional metadata for the node
84
+ def add(name, metadata={})
85
+ return if @map.include?(name)
86
+ @map[name] = Node.new(name, metadata)
87
+ end
88
+
89
+ # Remove a node from the graph. Unlink its parent and children
90
+ # from it.
91
+ #
92
+ # If the existing node does not exist, raise.
93
+ #
94
+ # @param [String] name an identifier for the node
95
+ def remove(name)
96
+ node = verify(name)
97
+
98
+ node.parents.each do |parent_node|
99
+ parent_node.children.delete node
100
+ end
101
+
102
+ node.children.each do |child_node|
103
+ child_node.parents.delete node
104
+ end
105
+
106
+ @map.delete(name)
107
+ end
108
+
109
+ # Add a link from the parent to the child. This link is a
110
+ # two-way link, so the child will be added to the parent's
111
+ # `children` and the parent will be added to the child's
112
+ # `parents`.
113
+ #
114
+ # The parent and child are referenced by node identifier.
115
+ #
116
+ # @param [String] parent the identifier of the parent
117
+ # @param [String] child the identifier of the child
118
+ def link(parent, child)
119
+ parent, child = lookup(parent, child)
120
+
121
+ parent.children << child
122
+ child.parents << parent
123
+ end
124
+
125
+ # Remove a link from the parent to the child.
126
+ #
127
+ # The parent and child are referenced by node identifier.
128
+ #
129
+ # @param [String] parent the identifier of the parent
130
+ # @param [String] child the identifier of the child
131
+ def unlink(parent, child)
132
+ parent, child = lookup(parent, child)
133
+
134
+ parent.children.delete(child)
135
+ child.parents.delete(parent)
136
+ end
137
+
138
+ # Look up a node by name
139
+ #
140
+ # @param [String] name the identifier of the node
141
+ # @return [Node] the node referenced by the specified identifier
142
+ def [](name)
143
+ @map[name]
144
+ end
145
+
146
+ private
147
+ # Verify that the parent and child nodes exist, and return
148
+ # the nodes with the specified identifiers.
149
+ #
150
+ # The parent and child are referenced by node identifier.
151
+ #
152
+ # @param [String] parent the identifier of the parent
153
+ # @param [String] child the identifier of the child
154
+ # @return [Array(Node, Node)] the parent and child nodes
155
+ def lookup(parent, child)
156
+ parent = verify(parent)
157
+ child = verify(child)
158
+
159
+ return parent, child
160
+ end
161
+
162
+ # Verify that a node with a given identifier exists, and
163
+ # if it does, return it.
164
+ #
165
+ # If it does not, raise an exception.
166
+ #
167
+ # @param [String] name the identifier of the node
168
+ # @raise [MissingNode] if a node with the given name is
169
+ # not found, raise.
170
+ # @return [Node] the n
171
+ def verify(name)
172
+ node = @map[name]
173
+ raise MissingNode, "Node #{name} does not exist" unless node
174
+ node
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,82 @@
1
+ require 'json'
2
+
3
+ module Rake
4
+ class Pipeline
5
+ # A Manifest is a container for storing dynamic dependency information.
6
+ # A {DynamicFileTask} will use a {Manifest} to keep track of its dynamic
7
+ # dependencies. This allows us to avoid scanning a file for dynamic
8
+ # dependencies if its contents have not changed.
9
+ class Manifest
10
+ attr_accessor :entries
11
+ attr_accessor :manifest_file
12
+
13
+ def initialize(manifest_file="manifest.json")
14
+ @manifest_file ||= manifest_file
15
+ @entries = {}
16
+ end
17
+
18
+ # Get the manifest off the file system, if it exists.
19
+ def read_manifest
20
+ @entries = File.file?(manifest_file) ? JSON.parse(File.read(manifest_file)) : {}
21
+
22
+ # convert the manifest JSON into a Hash of ManifestEntry objects
23
+ @entries.each do |file, raw|
24
+ @entries[file] = Rake::Pipeline::ManifestEntry.from_hash(raw)
25
+ end
26
+
27
+ self
28
+ end
29
+
30
+ # Write a JSON representation of this manifest out to disk if we
31
+ # have entries to save.
32
+ def write_manifest
33
+ unless @entries.empty?
34
+ File.open(manifest_file, "w") do |file|
35
+ file.puts JSON.generate(as_json)
36
+ end
37
+ end
38
+ end
39
+
40
+ # Convert this Manifest into a hash suitable for converting to
41
+ # JSON.
42
+ def as_json
43
+ hash = {}
44
+
45
+ @entries.each do |name, entry|
46
+ hash[name] = entry.as_json
47
+ end
48
+
49
+ hash
50
+ end
51
+
52
+ # Look up an entry by filename.
53
+ def [](key)
54
+ @entries[key]
55
+ end
56
+
57
+ # Set an entry
58
+ def []=(key, value)
59
+ @entries[key] = value
60
+ end
61
+
62
+ def empty?
63
+ entries.empty?
64
+ end
65
+
66
+ def files
67
+ entries.inject({}) do |hash, pair|
68
+ file = pair.first
69
+ entry = pair.last
70
+
71
+ hash.merge!(file => entry.mtime)
72
+
73
+ entry.deps.each_pair do |name, time|
74
+ hash.merge!(name => time)
75
+ end
76
+
77
+ hash
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end