gumdrop 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/ChangeLog.md +13 -0
- data/Gemfile +6 -2
- data/Gemfile.lock +43 -3
- data/Rakefile +37 -21
- data/Readme.md +60 -158
- data/bin/gumdrop +2 -1
- data/gumdrop.gemspec +11 -4
- data/lib/gumdrop/builder.rb +164 -0
- data/lib/gumdrop/cli/external.rb +14 -9
- data/lib/gumdrop/cli/internal.rb +54 -22
- data/lib/gumdrop/cli.rb +21 -0
- data/lib/gumdrop/content.rb +195 -132
- data/lib/gumdrop/data.rb +185 -0
- data/lib/gumdrop/data_providers/csv.rb +18 -0
- data/lib/gumdrop/data_providers/pstore.rb +25 -0
- data/lib/gumdrop/data_providers/sqlite.rb +43 -0
- data/lib/gumdrop/data_providers/xml.rb +15 -0
- data/lib/gumdrop/data_providers/yaml_and_json.rb +18 -0
- data/lib/gumdrop/data_providers/yamldb.rb +18 -0
- data/lib/gumdrop/data_providers/yamldoc.rb +12 -0
- data/lib/gumdrop/generator.rb +118 -94
- data/lib/gumdrop/renderer.rb +272 -0
- data/lib/gumdrop/server.rb +36 -27
- data/lib/gumdrop/site.rb +283 -338
- data/lib/gumdrop/support/compressor.rb +52 -0
- data/lib/gumdrop/support/sprockets.rb +14 -23
- data/lib/gumdrop/support/stitch.rb +25 -14
- data/lib/gumdrop/support/yaml_doc_template.rb +29 -0
- data/lib/gumdrop/util/configurable.rb +44 -0
- data/lib/gumdrop/util/core_ex.rb +84 -0
- data/lib/gumdrop/util/eventable.rb +35 -0
- data/lib/gumdrop/util/hash_object.rb +70 -0
- data/lib/gumdrop/util/loggable.rb +44 -0
- data/lib/gumdrop/util/pager.rb +51 -0
- data/lib/gumdrop/{support → util}/proxy_handler.rb +7 -6
- data/lib/gumdrop/util/scanner.rb +47 -0
- data/lib/gumdrop/util/site_access.rb +16 -0
- data/lib/gumdrop/util/view_helpers.rb +50 -0
- data/lib/gumdrop/util/yaml_doc.rb +51 -0
- data/lib/gumdrop/version.rb +2 -2
- data/lib/gumdrop.rb +40 -77
- data/specs/content_spec.rb +83 -73
- data/specs/fixtures/expected/data-access/from-csv.html +4 -0
- data/specs/fixtures/expected/data-access/from-json.html +6 -0
- data/specs/fixtures/expected/data-access/from-sqlite.html +5 -0
- data/specs/fixtures/expected/data-access/from-xml.html +4 -0
- data/specs/fixtures/expected/data-access/from-yaml.html +5 -0
- data/specs/fixtures/expected/data-access/from-yamldb.html +5 -0
- data/specs/fixtures/expected/data-access/from-yamldoc.html +2 -0
- data/specs/fixtures/expected/gen-with-block/as-file.html +1 -0
- data/specs/fixtures/expected/gen-with-block/as-plain.html +1 -0
- data/specs/fixtures/expected/gen-with-block/layout-nested.html +1 -0
- data/specs/fixtures/expected/gen-with-block/layout-nil.html +1 -0
- data/specs/fixtures/expected/gen-with-block/layout-wrap.html +1 -0
- data/specs/fixtures/expected/gen-with-inline-render/0-as-file.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/0-as-plain.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/0-layout-nil.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/0-layout-sub.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/0-layout-wrap.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/1-as-file.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/1-as-plain.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/1-layout-nil.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/1-layout-sub.html +4 -0
- data/specs/fixtures/expected/gen-with-inline-render/1-layout-wrap.html +4 -0
- data/specs/fixtures/expected/goodbye.html +1 -0
- data/specs/fixtures/expected/hello.html +1 -0
- data/specs/fixtures/expected/image.png +0 -0
- data/specs/fixtures/expected/index.html +47 -0
- data/specs/fixtures/expected/js/sprockets-app.js +7 -0
- data/specs/fixtures/expected/js/stitch-app.js +65 -0
- data/specs/fixtures/expected/js/stitch-app.min.js +5 -0
- data/specs/fixtures/expected/js/stitch-app.min.src.js +65 -0
- data/specs/fixtures/expected/js/straight.js +8 -0
- data/specs/fixtures/expected/js/test-coffee.js +5 -0
- data/specs/fixtures/expected/pages/docs/force-abs.html +2 -0
- data/specs/fixtures/expected/pages/docs/index.html +2 -0
- data/specs/fixtures/expected/partials/hoisted-data.html +3 -0
- data/specs/fixtures/expected/partials/nested.html +7 -0
- data/specs/fixtures/expected/partials/params.html +1 -0
- data/specs/fixtures/expected/partials/with-layouts.html +1 -0
- data/specs/fixtures/expected/robots.txt +1 -0
- data/specs/fixtures/expected/test-multi-procs.html +4 -0
- data/specs/fixtures/expected/test-nested-layout.html +1 -0
- data/specs/fixtures/expected/test-no-layout.html +2 -0
- data/specs/fixtures/expected/test-yamldoc.html +1 -0
- data/specs/fixtures/expected/test.html +2 -0
- data/{templates/backbone → specs/fixtures/source}/Gemfile +8 -4
- data/specs/fixtures/source/Gemfile.lock +84 -0
- data/specs/fixtures/source/Gumdrop +60 -9
- data/specs/fixtures/source/data/csv_data.csv +2 -0
- data/specs/fixtures/source/data/json_data.json +13 -0
- data/specs/fixtures/source/data/sql_data.sqlite +0 -0
- data/specs/fixtures/source/data/xml_data.xml +4 -0
- data/specs/fixtures/source/data/yaml_db.yamldb +9 -0
- data/specs/fixtures/source/data/yaml_items.yaml +2 -0
- data/specs/fixtures/source/data/yamldoc.yamldoc +4 -0
- data/specs/fixtures/source/data-access/from-csv.html.erb +4 -0
- data/specs/fixtures/source/data-access/from-json.html.erb +6 -0
- data/specs/fixtures/source/data-access/from-sqlite.html.erb +5 -0
- data/specs/fixtures/source/data-access/from-xml.html.erb +5 -0
- data/specs/fixtures/source/data-access/from-yaml.html.erb +5 -0
- data/specs/fixtures/source/data-access/from-yamldb.html.erb +5 -0
- data/specs/fixtures/source/data-access/from-yamldoc.html.erb +2 -0
- data/specs/fixtures/source/gen-with-inline-render.generator +7 -0
- data/specs/fixtures/source/goodbye.html.erb +1 -0
- data/specs/fixtures/source/hello.html +1 -0
- data/specs/fixtures/source/image.png +0 -0
- data/specs/fixtures/source/index.html.erb +6 -0
- data/specs/fixtures/source/js/sprockets/app.js +2 -0
- data/specs/fixtures/source/js/sprockets/view.js.coffee +1 -0
- data/specs/fixtures/source/js/stitch/app.js +1 -0
- data/specs/fixtures/source/js/stitch/view.js.coffee +1 -0
- data/specs/fixtures/source/js/straight.js +8 -0
- data/specs/fixtures/source/js/test-coffee.js.coffee +1 -0
- data/specs/fixtures/source/layouts/site.layout.erb +1 -0
- data/specs/fixtures/source/layouts/sub.layout.erb +1 -0
- data/specs/fixtures/source/layouts/wrap.layout.erb +1 -0
- data/specs/fixtures/source/pages/_users-nested.html.erb +7 -0
- data/specs/fixtures/source/pages/docs/force-abs.html.erb +2 -0
- data/specs/fixtures/source/pages/docs/index.html.erb +2 -0
- data/specs/fixtures/source/partials/_post_entry.html.erb +4 -0
- data/specs/fixtures/source/partials/_provides_name.html.erb +1 -0
- data/specs/fixtures/source/partials/_user-params.html.erb +1 -0
- data/specs/fixtures/source/partials/_user.html.erb +1 -0
- data/specs/fixtures/source/partials/_user_sets_layout.html.erb +1 -0
- data/specs/fixtures/source/partials/hoisted-data.html.erb +6 -0
- data/specs/fixtures/source/partials/nested.html.erb +1 -0
- data/specs/fixtures/source/partials/params.html.erb +1 -0
- data/specs/fixtures/source/partials/with-layouts.html.erb +1 -0
- data/specs/fixtures/source/test-multi-procs.html.markdown.erb +3 -0
- data/specs/fixtures/source/test-nested-layout.html.erb +1 -0
- data/specs/fixtures/source/test-no-layout.html.erb +2 -0
- data/specs/fixtures/source/test-yamldoc.html.erb.yamldoc +4 -0
- data/specs/fixtures/source/test.html.erb +2 -0
- data/specs/hash_object_spec.rb +53 -8
- data/specs/render_spec.rb +10 -0
- data/specs/site_spec.rb +79 -0
- data/specs/spec_helper.rb +59 -0
- data/templates/blank/Gemfile +0 -4
- data/templates/blank/Gumdrop +180 -113
- data/templates/default/Gemfile +3 -8
- data/templates/default/Gumdrop +166 -95
- data/templates/default/ReadMe.md +14 -0
- data/templates/default/config.ru +1 -0
- data/templates/default/data/news/20120703.yamldoc +14 -0
- data/templates/default/data/news/20120704.yamldoc +8 -0
- data/templates/{backbone/source/feed.xml.builder.txt → default/source/feed.xml.builder} +4 -4
- data/templates/default/source/index.html.erb +10 -1
- data/templates/default/source/theme/layout/_sidebar.html +1 -0
- data/templates/{backbone/source/theme/templates/site.template.slim → default/source/theme/layout/site.layout.slim} +3 -3
- metadata +212 -63
- data/lib/gumdrop/context.rb +0 -135
- data/lib/gumdrop/data_manager.rb +0 -214
- data/lib/gumdrop/support/base_packager.rb +0 -60
- data/lib/gumdrop/support/callbacks.rb +0 -30
- data/lib/gumdrop/support/hash_object.rb +0 -22
- data/lib/gumdrop/view_helpers.rb +0 -25
- data/notes.md +0 -347
- data/specs/deferred_loader_spec.rb +0 -31
- data/specs/fixtures/expected/posts/post1.html +0 -1
- data/specs/fixtures/expected/posts/post1.js +0 -14
- data/specs/fixtures/expected/posts/post2.html +0 -5
- data/specs/fixtures/expected/sub/sub/sub/test.html +0 -5
- data/specs/fixtures/expected/sub/sub/sub/test2.html +0 -5
- data/specs/fixtures/expected/test.js +0 -14
- data/specs/fixtures/source/posts/post1.html.slim +0 -6
- data/specs/fixtures/source/posts/post1.js.coffee +0 -3
- data/specs/fixtures/source/posts/post2.html.erb +0 -5
- data/specs/fixtures/source/sub/sub/sub/test.html +0 -5
- data/specs/fixtures/source/sub/sub/sub/test2.html.erb +0 -5
- data/specs/fixtures/source/test.js.coffee +0 -4
- data/specs/fixtures/source/test.js.erb.coffee +0 -3
- data/templates/backbone/Gumdrop +0 -123
- data/templates/backbone/Rakefile +0 -38
- data/templates/backbone/app/app.js.coffee +0 -49
- data/templates/backbone/app/init.js.coffee +0 -10
- data/templates/backbone/app/models/.gitkeep +0 -0
- data/templates/backbone/app/utils/index.js.coffee +0 -27
- data/templates/backbone/app/views/home.js.coffee +0 -17
- data/templates/backbone/app/views/styles/home.scss +0 -8
- data/templates/backbone/app/views/templates/home.mustache +0 -2
- data/templates/backbone/config.ru +0 -20
- data/templates/backbone/lib/all.js.coffee +0 -18
- data/templates/backbone/lib/backbone.js +0 -1158
- data/templates/backbone/lib/hogan.js +0 -509
- data/templates/backbone/lib/jquery.js +0 -9266
- data/templates/backbone/lib/underscore.js +0 -981
- data/templates/backbone/powrc +0 -2
- data/templates/backbone/source/default.htaccess.erb +0 -27
- data/templates/backbone/source/favicon.ico +0 -0
- data/templates/backbone/source/index.html.erb +0 -2
- data/templates/backbone/source/theme/screen.css.sass +0 -9
- data/templates/backbone/source/theme/scripts/app.js.coffee +0 -4
- data/templates/backbone/source/theme/styles/_tools.scss +0 -434
- data/templates/backbone/source/theme/templates/app.template.slim +0 -14
- data/templates/default/Rakefile +0 -38
- data/templates/default/powrc +0 -2
- data/templates/default/source/default.htaccess.erb +0 -27
- data/templates/default/source/feed.xml.builder.txt +0 -23
- 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
|
-
|
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
|
-
|
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:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
-
|
53
|
-
|
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
|
-
|
61
|
-
|
62
|
-
end
|
36
|
+
# hmmm...
|
37
|
+
attr_accessor :active_renderer, :active_builder
|
63
38
|
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
103
|
-
|
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
|
119
|
-
|
120
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
-
|
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
|
-
|
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
|
194
|
-
|
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
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
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
|
-
|
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
|
-
|
226
|
-
|
227
|
-
|
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
|
234
|
-
|
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
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
-
|
190
|
+
@is_scanned= true
|
281
191
|
end
|
282
192
|
|
283
|
-
def
|
284
|
-
|
285
|
-
|
286
|
-
|
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
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
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
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
330
|
-
|
287
|
+
# Short cut to the current Site config object.
|
288
|
+
def config
|
289
|
+
site.config
|
331
290
|
end
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
-
|
339
|
-
|
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
|
-
|
343
|
-
|
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
|
-
|
348
|
-
|
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
|
-
|
354
|
-
|
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
|
-
|
358
|
-
|
359
|
-
|
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
|
-
|
348
|
+
nil
|
362
349
|
end
|
363
350
|
end
|
364
351
|
|
365
|
-
def
|
366
|
-
|
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
|
+
|