gumdrop 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. data/.gitignore +3 -0
  2. data/ChangeLog.md +13 -0
  3. data/Gemfile +6 -2
  4. data/Gemfile.lock +43 -3
  5. data/Rakefile +37 -21
  6. data/Readme.md +60 -158
  7. data/bin/gumdrop +2 -1
  8. data/gumdrop.gemspec +11 -4
  9. data/lib/gumdrop/builder.rb +164 -0
  10. data/lib/gumdrop/cli/external.rb +14 -9
  11. data/lib/gumdrop/cli/internal.rb +54 -22
  12. data/lib/gumdrop/cli.rb +21 -0
  13. data/lib/gumdrop/content.rb +195 -132
  14. data/lib/gumdrop/data.rb +185 -0
  15. data/lib/gumdrop/data_providers/csv.rb +18 -0
  16. data/lib/gumdrop/data_providers/pstore.rb +25 -0
  17. data/lib/gumdrop/data_providers/sqlite.rb +43 -0
  18. data/lib/gumdrop/data_providers/xml.rb +15 -0
  19. data/lib/gumdrop/data_providers/yaml_and_json.rb +18 -0
  20. data/lib/gumdrop/data_providers/yamldb.rb +18 -0
  21. data/lib/gumdrop/data_providers/yamldoc.rb +12 -0
  22. data/lib/gumdrop/generator.rb +118 -94
  23. data/lib/gumdrop/renderer.rb +272 -0
  24. data/lib/gumdrop/server.rb +36 -27
  25. data/lib/gumdrop/site.rb +283 -338
  26. data/lib/gumdrop/support/compressor.rb +52 -0
  27. data/lib/gumdrop/support/sprockets.rb +14 -23
  28. data/lib/gumdrop/support/stitch.rb +25 -14
  29. data/lib/gumdrop/support/yaml_doc_template.rb +29 -0
  30. data/lib/gumdrop/util/configurable.rb +44 -0
  31. data/lib/gumdrop/util/core_ex.rb +84 -0
  32. data/lib/gumdrop/util/eventable.rb +35 -0
  33. data/lib/gumdrop/util/hash_object.rb +70 -0
  34. data/lib/gumdrop/util/loggable.rb +44 -0
  35. data/lib/gumdrop/util/pager.rb +51 -0
  36. data/lib/gumdrop/{support → util}/proxy_handler.rb +7 -6
  37. data/lib/gumdrop/util/scanner.rb +47 -0
  38. data/lib/gumdrop/util/site_access.rb +16 -0
  39. data/lib/gumdrop/util/view_helpers.rb +50 -0
  40. data/lib/gumdrop/util/yaml_doc.rb +51 -0
  41. data/lib/gumdrop/version.rb +2 -2
  42. data/lib/gumdrop.rb +40 -77
  43. data/specs/content_spec.rb +83 -73
  44. data/specs/fixtures/expected/data-access/from-csv.html +4 -0
  45. data/specs/fixtures/expected/data-access/from-json.html +6 -0
  46. data/specs/fixtures/expected/data-access/from-sqlite.html +5 -0
  47. data/specs/fixtures/expected/data-access/from-xml.html +4 -0
  48. data/specs/fixtures/expected/data-access/from-yaml.html +5 -0
  49. data/specs/fixtures/expected/data-access/from-yamldb.html +5 -0
  50. data/specs/fixtures/expected/data-access/from-yamldoc.html +2 -0
  51. data/specs/fixtures/expected/gen-with-block/as-file.html +1 -0
  52. data/specs/fixtures/expected/gen-with-block/as-plain.html +1 -0
  53. data/specs/fixtures/expected/gen-with-block/layout-nested.html +1 -0
  54. data/specs/fixtures/expected/gen-with-block/layout-nil.html +1 -0
  55. data/specs/fixtures/expected/gen-with-block/layout-wrap.html +1 -0
  56. data/specs/fixtures/expected/gen-with-inline-render/0-as-file.html +4 -0
  57. data/specs/fixtures/expected/gen-with-inline-render/0-as-plain.html +4 -0
  58. data/specs/fixtures/expected/gen-with-inline-render/0-layout-nil.html +4 -0
  59. data/specs/fixtures/expected/gen-with-inline-render/0-layout-sub.html +4 -0
  60. data/specs/fixtures/expected/gen-with-inline-render/0-layout-wrap.html +4 -0
  61. data/specs/fixtures/expected/gen-with-inline-render/1-as-file.html +4 -0
  62. data/specs/fixtures/expected/gen-with-inline-render/1-as-plain.html +4 -0
  63. data/specs/fixtures/expected/gen-with-inline-render/1-layout-nil.html +4 -0
  64. data/specs/fixtures/expected/gen-with-inline-render/1-layout-sub.html +4 -0
  65. data/specs/fixtures/expected/gen-with-inline-render/1-layout-wrap.html +4 -0
  66. data/specs/fixtures/expected/goodbye.html +1 -0
  67. data/specs/fixtures/expected/hello.html +1 -0
  68. data/specs/fixtures/expected/image.png +0 -0
  69. data/specs/fixtures/expected/index.html +47 -0
  70. data/specs/fixtures/expected/js/sprockets-app.js +7 -0
  71. data/specs/fixtures/expected/js/stitch-app.js +65 -0
  72. data/specs/fixtures/expected/js/stitch-app.min.js +5 -0
  73. data/specs/fixtures/expected/js/stitch-app.min.src.js +65 -0
  74. data/specs/fixtures/expected/js/straight.js +8 -0
  75. data/specs/fixtures/expected/js/test-coffee.js +5 -0
  76. data/specs/fixtures/expected/pages/docs/force-abs.html +2 -0
  77. data/specs/fixtures/expected/pages/docs/index.html +2 -0
  78. data/specs/fixtures/expected/partials/hoisted-data.html +3 -0
  79. data/specs/fixtures/expected/partials/nested.html +7 -0
  80. data/specs/fixtures/expected/partials/params.html +1 -0
  81. data/specs/fixtures/expected/partials/with-layouts.html +1 -0
  82. data/specs/fixtures/expected/robots.txt +1 -0
  83. data/specs/fixtures/expected/test-multi-procs.html +4 -0
  84. data/specs/fixtures/expected/test-nested-layout.html +1 -0
  85. data/specs/fixtures/expected/test-no-layout.html +2 -0
  86. data/specs/fixtures/expected/test-yamldoc.html +1 -0
  87. data/specs/fixtures/expected/test.html +2 -0
  88. data/{templates/backbone → specs/fixtures/source}/Gemfile +8 -4
  89. data/specs/fixtures/source/Gemfile.lock +84 -0
  90. data/specs/fixtures/source/Gumdrop +60 -9
  91. data/specs/fixtures/source/data/csv_data.csv +2 -0
  92. data/specs/fixtures/source/data/json_data.json +13 -0
  93. data/specs/fixtures/source/data/sql_data.sqlite +0 -0
  94. data/specs/fixtures/source/data/xml_data.xml +4 -0
  95. data/specs/fixtures/source/data/yaml_db.yamldb +9 -0
  96. data/specs/fixtures/source/data/yaml_items.yaml +2 -0
  97. data/specs/fixtures/source/data/yamldoc.yamldoc +4 -0
  98. data/specs/fixtures/source/data-access/from-csv.html.erb +4 -0
  99. data/specs/fixtures/source/data-access/from-json.html.erb +6 -0
  100. data/specs/fixtures/source/data-access/from-sqlite.html.erb +5 -0
  101. data/specs/fixtures/source/data-access/from-xml.html.erb +5 -0
  102. data/specs/fixtures/source/data-access/from-yaml.html.erb +5 -0
  103. data/specs/fixtures/source/data-access/from-yamldb.html.erb +5 -0
  104. data/specs/fixtures/source/data-access/from-yamldoc.html.erb +2 -0
  105. data/specs/fixtures/source/gen-with-inline-render.generator +7 -0
  106. data/specs/fixtures/source/goodbye.html.erb +1 -0
  107. data/specs/fixtures/source/hello.html +1 -0
  108. data/specs/fixtures/source/image.png +0 -0
  109. data/specs/fixtures/source/index.html.erb +6 -0
  110. data/specs/fixtures/source/js/sprockets/app.js +2 -0
  111. data/specs/fixtures/source/js/sprockets/view.js.coffee +1 -0
  112. data/specs/fixtures/source/js/stitch/app.js +1 -0
  113. data/specs/fixtures/source/js/stitch/view.js.coffee +1 -0
  114. data/specs/fixtures/source/js/straight.js +8 -0
  115. data/specs/fixtures/source/js/test-coffee.js.coffee +1 -0
  116. data/specs/fixtures/source/layouts/site.layout.erb +1 -0
  117. data/specs/fixtures/source/layouts/sub.layout.erb +1 -0
  118. data/specs/fixtures/source/layouts/wrap.layout.erb +1 -0
  119. data/specs/fixtures/source/pages/_users-nested.html.erb +7 -0
  120. data/specs/fixtures/source/pages/docs/force-abs.html.erb +2 -0
  121. data/specs/fixtures/source/pages/docs/index.html.erb +2 -0
  122. data/specs/fixtures/source/partials/_post_entry.html.erb +4 -0
  123. data/specs/fixtures/source/partials/_provides_name.html.erb +1 -0
  124. data/specs/fixtures/source/partials/_user-params.html.erb +1 -0
  125. data/specs/fixtures/source/partials/_user.html.erb +1 -0
  126. data/specs/fixtures/source/partials/_user_sets_layout.html.erb +1 -0
  127. data/specs/fixtures/source/partials/hoisted-data.html.erb +6 -0
  128. data/specs/fixtures/source/partials/nested.html.erb +1 -0
  129. data/specs/fixtures/source/partials/params.html.erb +1 -0
  130. data/specs/fixtures/source/partials/with-layouts.html.erb +1 -0
  131. data/specs/fixtures/source/test-multi-procs.html.markdown.erb +3 -0
  132. data/specs/fixtures/source/test-nested-layout.html.erb +1 -0
  133. data/specs/fixtures/source/test-no-layout.html.erb +2 -0
  134. data/specs/fixtures/source/test-yamldoc.html.erb.yamldoc +4 -0
  135. data/specs/fixtures/source/test.html.erb +2 -0
  136. data/specs/hash_object_spec.rb +53 -8
  137. data/specs/render_spec.rb +10 -0
  138. data/specs/site_spec.rb +79 -0
  139. data/specs/spec_helper.rb +59 -0
  140. data/templates/blank/Gemfile +0 -4
  141. data/templates/blank/Gumdrop +180 -113
  142. data/templates/default/Gemfile +3 -8
  143. data/templates/default/Gumdrop +166 -95
  144. data/templates/default/ReadMe.md +14 -0
  145. data/templates/default/config.ru +1 -0
  146. data/templates/default/data/news/20120703.yamldoc +14 -0
  147. data/templates/default/data/news/20120704.yamldoc +8 -0
  148. data/templates/{backbone/source/feed.xml.builder.txt → default/source/feed.xml.builder} +4 -4
  149. data/templates/default/source/index.html.erb +10 -1
  150. data/templates/default/source/theme/layout/_sidebar.html +1 -0
  151. data/templates/{backbone/source/theme/templates/site.template.slim → default/source/theme/layout/site.layout.slim} +3 -3
  152. metadata +212 -63
  153. data/lib/gumdrop/context.rb +0 -135
  154. data/lib/gumdrop/data_manager.rb +0 -214
  155. data/lib/gumdrop/support/base_packager.rb +0 -60
  156. data/lib/gumdrop/support/callbacks.rb +0 -30
  157. data/lib/gumdrop/support/hash_object.rb +0 -22
  158. data/lib/gumdrop/view_helpers.rb +0 -25
  159. data/notes.md +0 -347
  160. data/specs/deferred_loader_spec.rb +0 -31
  161. data/specs/fixtures/expected/posts/post1.html +0 -1
  162. data/specs/fixtures/expected/posts/post1.js +0 -14
  163. data/specs/fixtures/expected/posts/post2.html +0 -5
  164. data/specs/fixtures/expected/sub/sub/sub/test.html +0 -5
  165. data/specs/fixtures/expected/sub/sub/sub/test2.html +0 -5
  166. data/specs/fixtures/expected/test.js +0 -14
  167. data/specs/fixtures/source/posts/post1.html.slim +0 -6
  168. data/specs/fixtures/source/posts/post1.js.coffee +0 -3
  169. data/specs/fixtures/source/posts/post2.html.erb +0 -5
  170. data/specs/fixtures/source/sub/sub/sub/test.html +0 -5
  171. data/specs/fixtures/source/sub/sub/sub/test2.html.erb +0 -5
  172. data/specs/fixtures/source/test.js.coffee +0 -4
  173. data/specs/fixtures/source/test.js.erb.coffee +0 -3
  174. data/templates/backbone/Gumdrop +0 -123
  175. data/templates/backbone/Rakefile +0 -38
  176. data/templates/backbone/app/app.js.coffee +0 -49
  177. data/templates/backbone/app/init.js.coffee +0 -10
  178. data/templates/backbone/app/models/.gitkeep +0 -0
  179. data/templates/backbone/app/utils/index.js.coffee +0 -27
  180. data/templates/backbone/app/views/home.js.coffee +0 -17
  181. data/templates/backbone/app/views/styles/home.scss +0 -8
  182. data/templates/backbone/app/views/templates/home.mustache +0 -2
  183. data/templates/backbone/config.ru +0 -20
  184. data/templates/backbone/lib/all.js.coffee +0 -18
  185. data/templates/backbone/lib/backbone.js +0 -1158
  186. data/templates/backbone/lib/hogan.js +0 -509
  187. data/templates/backbone/lib/jquery.js +0 -9266
  188. data/templates/backbone/lib/underscore.js +0 -981
  189. data/templates/backbone/powrc +0 -2
  190. data/templates/backbone/source/default.htaccess.erb +0 -27
  191. data/templates/backbone/source/favicon.ico +0 -0
  192. data/templates/backbone/source/index.html.erb +0 -2
  193. data/templates/backbone/source/theme/screen.css.sass +0 -9
  194. data/templates/backbone/source/theme/scripts/app.js.coffee +0 -4
  195. data/templates/backbone/source/theme/styles/_tools.scss +0 -434
  196. data/templates/backbone/source/theme/templates/app.template.slim +0 -14
  197. data/templates/default/Rakefile +0 -38
  198. data/templates/default/powrc +0 -2
  199. data/templates/default/source/default.htaccess.erb +0 -27
  200. data/templates/default/source/feed.xml.builder.txt +0 -23
  201. data/templates/default/source/theme/templates/site.template.slim +0 -33
data/lib/gumdrop/site.rb CHANGED
@@ -1,414 +1,359 @@
1
- require 'pathname'
2
-
3
1
  module Gumdrop
4
2
 
5
- DEFAULT_OPTIONS= {
3
+ WEB_PAGE_EXTS= %w(.html .htm)
4
+ JETSAM_FILES= %w(**/.DS_Store .git* .git/**/* .svn/**/* **/.sass-cache/**/* Gumdrop)
5
+
6
+ DEFAULT_CONFIG= {
6
7
  relative_paths: true,
7
- relative_paths_for: ['.html', '.htm', '.php'],
8
+ relative_paths_exts: WEB_PAGE_EXTS,
9
+ default_layout: 'site',
10
+ layout_exts: WEB_PAGE_EXTS,
8
11
  proxy_enabled: false,
9
12
  output_dir: "./output",
10
13
  source_dir: "./source",
11
14
  data_dir: './data',
12
- log: './logs/build.log',
13
- ignore: %w(.DS_Store .gitignore .git .svn .sass-cache),
14
- server_timeout: 15,
15
- # server_port: 4567,
16
- env: 'production'
15
+ log: STDOUT,
16
+ log_level: :info,
17
+ ignore: JETSAM_FILES,
18
+ blacklist: [],
19
+ server_timeout: 5,
20
+ server_port: 4567,
21
+ env: :production,
22
+ file_change_test: :checksum
17
23
  }
18
24
 
19
25
  class Site
26
+ include Util::Configurable
27
+ include Util::Eventable
28
+ include Util::Loggable
20
29
 
21
- extend Support::Callbacks
22
-
23
- attr_reader :opts,
24
- :root_path,
25
- :src_path,
26
- :out_path,
27
- :data_path,
28
- :blacklist,
29
- :greylist,
30
- :redirects,
31
- :content_filters,
32
- :layouts,
33
- :partials,
34
- :generators,
35
- :config,
36
- :data,
37
- :sitefile,
38
- :content_hash,
39
- :last_run
40
-
41
- callbacks :on_start,
42
- :on_before_scan,
43
- :on_scan,
44
- :on_before_generate,
45
- :on_generate,
46
- :on_before_render,
47
- :on_render,
48
- :on_before_render_item,
49
- :on_render_item,
50
- :on_end
30
+ config_accessor :source_dir, :output_dir, :data_dir,
31
+ :mode, :env, :ignore, :blacklist
51
32
 
52
- def initialize(sitefile, opts={})
53
- @sitefile = File.expand_path sitefile
54
- @root_path = File.dirname @sitefile
55
- @opts = opts
56
- @last_run = nil
57
- reset_all()
58
- end
33
+ attr_reader :sitefile, :options, :root, :contents, :data,
34
+ :layouts, :generators, :partials, :last_run
59
35
 
60
- def opts=(opts={})
61
- @opts= opts
62
- end
36
+ # hmmm...
37
+ attr_accessor :active_renderer, :active_builder
63
38
 
64
- def contents(*args)
65
- opts= args.extract_options!
66
- pattern= args.first || nil
39
+ # You shouldn't call this yourself! Access it via Gumdrop.site
40
+ def initialize(sitefile, opts={})
41
+ Gumdrop.send :set_current_site, self
42
+ @sitefile= sitefile.expand_path
43
+ @options= Util::HashObject.from opts
44
+ _options_updated!
45
+ @root= File.dirname @sitefile
46
+ @last_run= 0
47
+ clear
48
+ end
49
+
50
+ def options=(opts={})
51
+ @options.merge!(opts)
52
+ _options_updated!
53
+ end
54
+
55
+
56
+ def clear()
57
+ @contents= ContentList.new
58
+ @layouts= SpecialContentList.new ".layout"
59
+ @partials= SpecialContentList.new
60
+ @generators= []
61
+ @data= DataManager.new
62
+ @is_scanned= false
63
+ _reset_config!
64
+ _load_sitefile
65
+ self
66
+ end
67
67
 
68
- if pattern.nil? or pattern.empty?
69
- if opts[:as] == :hash
70
- @content_hash
71
- else
72
- @content_hash.values
73
- end
74
-
75
- else
76
- if pattern.is_a? Array
77
- nodes= opts[:as] == :hash ? {} : []
78
- pattern.each do |subpattern|
79
- if opts[:as]== :hash
80
- nodes.merge! match_nodes(subpattern, opts)
81
- else
82
- nodes << match_nodes(subpattern, opts)
83
- end
84
- end
85
- opts[:as]== :hash ? nodes : nodes.flatten
86
- else
87
- match_nodes(pattern, opts)
88
- end
68
+ def scan(force=false)
69
+ if !@is_scanned or force
70
+ clear if @is_scanned # ????
71
+ _content_scanner
72
+ @is_scanned= true
73
+ generate
89
74
  end
75
+ self
90
76
  end
91
77
 
92
- def rescan
93
- on_start(self)
94
- reset_all()
95
- scan()
96
- @last_run= Time.now
97
- # TODO: should on_before_render and on_render be called for rescan()?
98
- on_end(self)
78
+ def scan_only # For testing...
79
+ if !@is_scanned or force
80
+ clear if @is_scanned # ????
81
+ _content_scanner
82
+ end
99
83
  self
100
84
  end
101
85
 
102
- def build(force_reset=false)
103
- on_start(self)
104
- report "[#{ Time.new }]"
105
- reset_all() if force_reset
106
- scan()
107
- render()
108
- @last_run= Time.now
109
- on_end(self)
110
- report "[Done]"
86
+ def generate
87
+ _execute_generators
111
88
  self
112
89
  end
113
-
114
- def rebuild
115
- build true
116
- end
117
90
 
118
- def report(msg, level=:info)
119
- case level
120
- when :info
121
- unless @opts[:quiet]
122
- if @opts[:subdued]
123
- print "."
124
- else
125
- @log.info msg
126
- end
127
- end
128
- when :warning, :warn
129
- @log.warn msg
130
- else
131
- print "!" if @opts[:subdued]
132
- @log.error msg
91
+ def in_blacklist?(path)
92
+ blacklist.any? do |pattern|
93
+ path.path_match? pattern
133
94
  end
134
95
  end
135
96
 
136
- # FIXME: Should a new Context be created for every page? For now
137
- # it's a single context for whole site
138
- def render_context
139
- @context ||= Context.new self
140
- @context
141
- end
142
-
143
- # Match a path using a glob-like file pattern
144
- def path_match(path, pattern)
145
- File.fnmatch pattern, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_CASEFOLD
97
+ def ignore_path?(path)
98
+ config.ignore.any? do |pattern|
99
+ path.path_match? pattern
100
+ end
146
101
  end
147
102
 
148
- private
149
-
150
- def scan
151
- build_tree()
152
- run_generators()
153
- self
103
+ def source_path
104
+ @source_path ||= source_dir.expand_path(root)
154
105
  end
155
106
 
156
-
157
- def reset_all
158
- @content_filters = []
159
- @blacklist = []
160
- @greylist = []
161
- @redirects = []
162
-
163
- @content_hash = Hash.new {|h,k| h[k]= nil }
164
- @layouts = Hash.new {|h,k| h[k]= nil }
165
- @partials = Hash.new {|h,k| h[k]= nil }
166
- @generators = Hash.new {|h,k| h[k]= nil }
167
-
168
- @config = Gumdrop::Config.new DEFAULT_OPTIONS
169
- @config.env = @opts[:env] if @opts.has_key? :env
170
-
171
- clear_on_start()
172
- clear_on_before_scan()
173
- clear_on_scan()
174
- clear_on_before_generate()
175
- clear_on_generate()
176
- clear_on_before_render()
177
- clear_on_render()
178
- clear_on_before_render_item()
179
- clear_on_render_item()
180
- clear_on_end()
181
-
182
- load_sitefile()
183
-
184
- @data_path = get_expanded_path(@config.data_dir)
185
- @src_path = get_expanded_path(@config.source_dir)
186
- @out_path = get_expanded_path(@config.output_dir)
187
-
188
- @data = Gumdrop::DataManager.new self, @data_path
189
-
190
- init_logging()
107
+ def output_path
108
+ @output_path ||= output_dir.expand_path(root)
191
109
  end
192
110
 
193
- def match_nodes(pattern, opts={})
194
- nodes = opts[:as] == :hash ? {} : []
195
- @content_hash.keys.each do |path|
196
- if path_match path, pattern
197
- if opts[:as] == :hash
198
- nodes[path]= @content_hash[path]
199
- else
200
- nodes << @content_hash[path]
201
- end
202
- end
203
- end
204
- nodes
111
+ def data_path
112
+ @data_path ||= data_dir.expand_path(root)
205
113
  end
206
114
 
207
- def init_logging
208
- begin
209
- @log = Logger.new @config.log, 'daily'
210
- rescue
211
- target= if @opts[:quiet]
212
- nil
115
+ def resolve(path=nil, opts={})
116
+ case
117
+ when path.is_a?(Content)
118
+ path
119
+ when !path.nil?
120
+ contents.first(path) || partials.first(path)
121
+ when opts[:page]
122
+ contents.first opts[:page]
123
+ when opts[:partial]
124
+ partials.first opts[:partial]
125
+ when opts[:layout]
126
+ layouts.first opts[:layout]
127
+ when opts[:generator]
128
+ generators.first opts[:generator]
213
129
  else
214
- STDOUT
215
- end
216
- @log = Logger.new target
217
- # report "Using STDOUT for logging because of exception: #{ $! }" unless target.nil?
218
- end
219
- @log.formatter = proc do |severity, datetime, progname, msg|
220
- # "#{datetime}: #{msg}\n"
221
- " #{msg}\n"
130
+ nil
222
131
  end
223
132
  end
224
133
 
225
- def get_expanded_path(path)
226
- if (Pathname.new path).absolute?
227
- path
228
- else
229
- File.expand_path File.join(@root_path, path)
230
- end
134
+ # Events stop bubbling here.
135
+ def parent
136
+ nil
231
137
  end
232
138
 
233
- def load_sitefile
234
- source= File.read( @sitefile )
235
- dsl = Sitefile.new self
236
- dsl.instance_eval source
237
- dsl
139
+ def config_did_change
140
+ Gumdrop.init_logging
238
141
  end
239
142
 
240
- def build_tree
241
- report "[Scanning from #{src_path}]", :info
242
- on_before_scan(self)
243
- # Report blacklists and greylists
244
- blacklist.each do |path|
245
- report " blacklist: #{path}", :info
246
- end
247
- greylist.each do |path|
248
- report " greylist: #{path}", :info
249
- end
143
+ private
144
+
145
+ def _reset_config!
146
+ config.clear.merge! DEFAULT_CONFIG
147
+ config.env= @options.env.to_sym if @options.env
148
+ config.mode= @options.mode.nil? ? :unknown : @options.mode.to_sym
149
+ end
150
+
151
+ def _options_updated!
152
+ config.env= @options.env.to_sym if @options.env
153
+ config.mode= @options.mode.nil? ? :unknown : @options.mode.to_sym
154
+ end
155
+
156
+ def _load_sitefile
157
+ clear_events
158
+ load sitefile
159
+ data.dir= data_path
160
+ rescue Exception => ex
161
+ msg= "There is an error in your Gumdrop file!"
162
+ # $stderr.puts msg
163
+ log.error msg
164
+ log.error ex
165
+ raise ex
166
+ end
167
+
168
+ def _content_scanner
169
+ log.info "Gumdrop v#{ Gumdrop::VERSION } - #{ Time.new }"
170
+ log.debug "(config)"
171
+ log.debug config
172
+ log.debug "(options)"
173
+ log.debug @options
174
+ log.debug "[Scanning: #{source_path}]"
175
+ # Report ignore list
176
+ ignore.each {|p| log.debug " ignoring: #{p}" }
250
177
  # Scan Filesystem
251
- Dir.glob("#{src_path}/**/*", File::FNM_DOTMATCH).each do |path|
252
- unless File.directory? path or @config.ignore.include?( File.basename(path) )
253
- node= Content.new(path, self)
254
- path= node.to_s
255
- if blacklist.any? {|pattern| path_match path, pattern }
256
- report " excluding: #{path}", :info
257
- else
258
- node.ignore greylist.any? {|pattern| path_match path, pattern }
259
- # Sort out Layouts, Generators, and Partials
260
- if File.extname(path) == ".template"
261
- layouts[path]= node
262
- layouts[File.basename(path)]= node
263
-
264
- elsif File.extname(path) == ".generator"
265
- generators[File.basename(path)]= Generator.new( node, self )
266
-
267
- elsif File.basename(path).starts_with?("_")
268
- partial_name= File.basename(path)[1..-1].gsub(File.extname(File.basename(path)), '')
269
- partial_node_path= File.join File.dirname(path), partial_name
270
- # puts "Creating partial #{partial_name} from #{path}"
271
- partials[partial_name]= node
272
- partials[partial_node_path]= node
273
-
274
- else
275
- @content_hash[path]= node
276
- end
277
- end
178
+ event_block :scan do
179
+ scanner= Util::Scanner.new(source_path, {}, &method(:_scanner_validator))
180
+ scanner.each do |path, rel|
181
+ content= Content.new(path)
182
+ layouts.add content and next if content.layout?
183
+ partials.add content and next if content.partial?
184
+ generators << Generator.new(content) and next if content.generator?
185
+ contents.add content
186
+ log.debug " including: #{ rel }"
278
187
  end
188
+ contents.keys.size
279
189
  end
280
- on_scan(self)
190
+ @is_scanned= true
281
191
  end
282
192
 
283
- def run_generators
284
- report "[Executing Generators]", :info
285
- on_before_generate(self)
286
- generators.each_pair do |path, generator|
287
- generator.execute()
288
- end
289
- on_generate(self)
193
+ def _scanner_validator(source_path, full_path)
194
+ return true if ignore_path? source_path
195
+ # in_blacklist? source_path
196
+ false
290
197
  end
291
198
 
292
- def render
293
- unless opts[:dry_run]
294
- report "[Compiling to #{@out_path}]", :info
295
- on_before_render(self)
296
- nodes= if opts[:assets]
297
- contents(opts[:assets])
298
- else
299
- contents()
300
- end
301
- nodes.each do |node|
302
- render_content(node, render_context, content_filters)
199
+ def _execute_generators
200
+ log.debug "[Executing Generators]"
201
+ event_block :generate do
202
+ generators.each do |generator|
203
+ generator.execute()
303
204
  end
304
- on_render(self)
305
205
  end
306
206
  end
307
207
 
308
- def render_content(node, ctx, filters)
309
- unless node.ignore?
310
- output_path= File.join(@out_path, node.to_s)
311
- FileUtils.mkdir_p File.dirname(output_path)
312
- begin
313
- on_before_render_item(self, node)
314
- node.renderTo ctx, output_path, filters
315
- on_render_item(self, node)
316
- rescue => ex
317
- report "[!>EXCEPTION<!]: #{ node.to_s }", :error
318
- report [ex.to_s, ex.backtrace].flatten.join("\n"), :error
319
- exit 1 unless @opts[:resume]
320
- end
208
+ end
209
+
210
+ class << self
211
+
212
+ # This will look for a nearby Gumdrop file and load the Site
213
+ # the first time it is called. Each time after it will just
214
+ # return the already created Site.
215
+ def site(opts={}, force_new=false)
216
+ opts= opts.to_symbolized_hash
217
+ unless @current_site.nil? or force_new
218
+ @current_site.options= opts unless opts.empty?
219
+ @current_site
321
220
  else
322
- report " ignoring: #{ node.to_s }", :info
221
+ site_file= fetch_site_file
222
+ unless site_file.nil?
223
+ Site.new site_file, opts
224
+ else
225
+ nil
226
+ end
323
227
  end
324
228
  end
325
- end
326
229
 
327
- class Sitefile
230
+ # Listen for life-cycle events in your Gumdrop file like this:
231
+ #
232
+ # Gumdrop.on :start do |event|
233
+ # puts "Here we go!"
234
+ # end
235
+ #
236
+ # Complete list of events fired by Gumdrop:
237
+ #
238
+ # :start
239
+ # :before_scan
240
+ # :scan
241
+ # :after_scan
242
+ # :before_generate
243
+ # :generate
244
+ # :after_generate
245
+ # :before_generate_item
246
+ # :generate_item
247
+ # :after_generate_item
248
+ # :before_build
249
+ # :build
250
+ # :after_build
251
+ # :before_checksum
252
+ # :checksum
253
+ # :after_checksum
254
+ # :before_render
255
+ # :render
256
+ # :after_render
257
+ # :before_render_item
258
+ # :render_item
259
+ # :after_render_item
260
+ # :before_write
261
+ # :write
262
+ # :after_write
263
+ # :before_copy_file
264
+ # :copy_file
265
+ # :after_copy_file
266
+ # :before_write_file
267
+ # :write_file
268
+ # :after_write_file
269
+ # :end
270
+ #
271
+ # In the block parem `event` you will have access to :site, the
272
+ # current executing site instance, and :payload, where applicable.
273
+ #
274
+ # :render_item is a special event because you can add/override the
275
+ # compiled output by modifying `event.data.return_value`
276
+ #
277
+ def on(event_type, options={}, &block)
278
+ site.on event_type, options, &block
279
+ end
280
+
281
+ # Yield a configuration object. You can update Gumdrop behavior
282
+ # as well as add your own config information.
283
+ def configure(&block)
284
+ site.configure &block
285
+ end
328
286
 
329
- def initialize(site)
330
- @site= site
287
+ # Short cut to the current Site config object.
288
+ def config
289
+ site.config
331
290
  end
332
-
333
- def generate(&block)
334
- # Auto-generated, numerical, key for a site-level generator
335
- @site.generators[@site.generators.keys.length] = Generator.new(block, @site)
291
+
292
+ # The env Gumdrop is run in -- You can set this in the congig
293
+ # or, better, via command line: `gumdrop build -e test`
294
+ def env
295
+ site.env
336
296
  end
337
-
338
- def content_filter(&block)
339
- @site.content_filters << block
297
+
298
+ # Mostly for internal use, but you can update/change it in the
299
+ # configure block.
300
+ def mode
301
+ site.mode
340
302
  end
341
-
342
- def skip(path)
343
- @site.blacklist << path
303
+
304
+ # Returns true if this, or a parent, folder has a Gumdrop file.
305
+ def in_site_folder?(filename="Gumdrop")
306
+ !fetch_site_file(filename).nil?
344
307
  end
345
- alias_method :blacklist, :skip
346
308
 
347
- def ignore(path)
348
- @site.greylist << path
309
+ # Specified paths will be added to the ignore list, preventing
310
+ # matching files from appearing in the source tree
311
+ def ignore(*paths)
312
+ paths.each do |path|
313
+ if path.is_a? Array
314
+ config.ignore.concat path
315
+ else
316
+ config.ignore << path
317
+ end
318
+ end
349
319
  end
350
- alias_method :greylist, :ignore
351
- alias_method :graylist, :ignore
352
320
 
353
- def view_helpers(&block)
354
- Gumdrop::ViewHelpers.class_eval &block
321
+ # Specified paths will not be renderd to output (matching against
322
+ # the source tree).
323
+ def blacklist(*paths)
324
+ paths.each do |path|
325
+ if path.is_a? Array
326
+ config.blacklist.concat path
327
+ else
328
+ config.blacklist << path
329
+ end
330
+ end
355
331
  end
356
332
 
357
- def configure(&block)
358
- if block.arity > 0
359
- block.call @site.config
333
+ protected
334
+
335
+ # Walks up the filesystem, starting from Dir.pwd, looking for
336
+ # a Gumdrop file. Returns nil if not found.
337
+ def fetch_site_file(filename="Gumdrop")
338
+ here= Dir.pwd
339
+ found= File.file? here / filename
340
+ # TODO: Should be smarter -- This is a hack for Windows support "C:\"
341
+ while !found and File.directory?(here) and File.dirname(here).length > 3
342
+ here= File.expand_path here /'..'
343
+ found= File.file? here / filename
344
+ end
345
+ if found
346
+ File.expand_path here / filename
360
347
  else
361
- @site.config.instance_eval &block
348
+ nil
362
349
  end
363
350
  end
364
351
 
365
- def tasks(&block)
366
- Gumdrop::CLI::Internal.class_eval &block
367
- end
368
-
369
- # Callbacks
370
- def on_start(&block)
371
- @site.on_start &block
372
- end
373
- def on_before_scan(&block)
374
- @site.on_before_scan &block
375
- end
376
- def on_scan(&block)
377
- @site.on_scan &block
378
- end
379
- def on_before_generate(&block)
380
- @site.on_before_generate &block
381
- end
382
- def on_generate(&block)
383
- @site.on_generate &block
384
- end
385
- def on_before_render(&block)
386
- @site.on_before_render &block
387
- end
388
- def on_render(&block)
389
- @site.on_render &block
390
- end
391
- def on_before_render_item(&block)
392
- @site.on_before_render &block
393
- end
394
- def on_render_item(&block)
395
- @site.on_render &block
396
- end
397
- def on_end(&block)
398
- @site.on_end &block
399
- end
400
-
401
- end
402
-
403
- class Config < HashObject
404
-
405
- def set(key, value)
406
- self[key]= value
407
- end
408
- def get(key)
409
- self[key]
352
+ def set_current_site(site)
353
+ @current_site= site
410
354
  end
411
355
 
412
356
  end
413
357
 
414
- end
358
+ end
359
+