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/data.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
# require 'ostruct'
|
2
|
+
|
3
|
+
module Gumdrop
|
4
|
+
|
5
|
+
class DataManager
|
6
|
+
include Util::SiteAccess
|
7
|
+
|
8
|
+
attr_reader :cache
|
9
|
+
|
10
|
+
def initialize(data_dir="./data")
|
11
|
+
@dir= File.expand_path data_dir
|
12
|
+
# reset
|
13
|
+
@cache= Hash.new &method(:_cache_dataset)
|
14
|
+
end
|
15
|
+
|
16
|
+
def dir=(path)
|
17
|
+
@dir= File.expand_path path
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(key, value=nil)
|
21
|
+
@cache[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def set(key, value)
|
25
|
+
@cache[key]= value
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset
|
29
|
+
@cache.clear
|
30
|
+
end
|
31
|
+
|
32
|
+
def contents(pattern=nil, opts={})
|
33
|
+
if pattern.nil?
|
34
|
+
site.contents.all
|
35
|
+
else
|
36
|
+
site.contents(pattern, opts)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def pager_for(key, opts={})
|
41
|
+
data= case key
|
42
|
+
when Symbol
|
43
|
+
@cache[key]
|
44
|
+
when Array
|
45
|
+
key
|
46
|
+
else
|
47
|
+
raise "pager_for requires a lookup symbol or array data."
|
48
|
+
end
|
49
|
+
base_path= opts.fetch(:base_path, 'page')
|
50
|
+
page_size= opts.fetch(:page_size, 5)
|
51
|
+
Util::Pager.new( data, base_path, page_size )
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def _cache_dataset(hash, key)
|
57
|
+
hash[key]= load_data(key) #unless @cache.has_key? key
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_data(key)
|
61
|
+
path=_get_filename key
|
62
|
+
return nil if path.nil?
|
63
|
+
if File.directory? path
|
64
|
+
_load_from_directory path
|
65
|
+
else
|
66
|
+
_load_from_file path
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def _load_from_file( filename )
|
71
|
+
ext=File.extname(filename)[1..-1]
|
72
|
+
provider= Data::Provider.for ext
|
73
|
+
case
|
74
|
+
when provider.nil?
|
75
|
+
raise "Unknown data type (#{ext}) for #{filename}"
|
76
|
+
when provider.available?
|
77
|
+
data= provider.data_for filename
|
78
|
+
log.debug " loaded: #{filename}"
|
79
|
+
data
|
80
|
+
else
|
81
|
+
raise "Unavailable data type (#{ext}) for #{filename}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def _load_from_directory( filepath )
|
86
|
+
all=[]
|
87
|
+
Dir[ filepath / _supported_type_glob ].each do |filename|
|
88
|
+
id= File.basename(filename).gsub(File.extname(filename), '')
|
89
|
+
obj_hash= _load_from_file filename
|
90
|
+
obj_hash._id = id
|
91
|
+
all << obj_hash
|
92
|
+
end
|
93
|
+
all
|
94
|
+
end
|
95
|
+
|
96
|
+
def _get_filename(path)
|
97
|
+
lpath= _local_path_to(path)
|
98
|
+
if File.directory? lpath
|
99
|
+
lpath
|
100
|
+
else
|
101
|
+
_registered_data_types.each do |ext|
|
102
|
+
lpath= _local_path_to("#{path}.#{ext}")
|
103
|
+
return lpath if File.exists? lpath
|
104
|
+
end
|
105
|
+
log.warn "No data found for #{path}"
|
106
|
+
nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def _local_path_to(filename)
|
111
|
+
File.join(@dir.to_s, filename.to_s)
|
112
|
+
end
|
113
|
+
|
114
|
+
def _registered_data_types
|
115
|
+
Data::Provider.registered_exts
|
116
|
+
end
|
117
|
+
|
118
|
+
def _supported_type_glob
|
119
|
+
"{*.#{ _registered_data_types.join ',*.'}}"
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
module Data
|
125
|
+
# Base class for Data Proviers
|
126
|
+
class Provider
|
127
|
+
|
128
|
+
def available?
|
129
|
+
raise "available? must be implemented! (#{self.class})"
|
130
|
+
end
|
131
|
+
|
132
|
+
def data_for(filepath)
|
133
|
+
raise "data_for must be implemented! (#{self.class})"
|
134
|
+
end
|
135
|
+
|
136
|
+
def supply_data(object)
|
137
|
+
case object
|
138
|
+
when Hash
|
139
|
+
object = object.clone
|
140
|
+
object.each do |key, value|
|
141
|
+
object[key] = supply_data(value)
|
142
|
+
end
|
143
|
+
# OpenStruct.new(object)
|
144
|
+
Gumdrop::Util::HashObject.from object
|
145
|
+
when Array
|
146
|
+
object = object.clone
|
147
|
+
object.map! { |item| supply_data(item) }
|
148
|
+
else
|
149
|
+
object
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
class << self
|
154
|
+
|
155
|
+
def extensions(*extnames)
|
156
|
+
provider_class= self
|
157
|
+
@@providers ||= {}
|
158
|
+
extnames.each do |ext|
|
159
|
+
@@providers[ext.to_s]= provider_class
|
160
|
+
end
|
161
|
+
end
|
162
|
+
alias_method :extension, :extensions
|
163
|
+
|
164
|
+
def registered_exts
|
165
|
+
@@providers.keys
|
166
|
+
end
|
167
|
+
|
168
|
+
def for(ext)
|
169
|
+
case
|
170
|
+
when provider_class= @@providers[ext]
|
171
|
+
provider_class.new
|
172
|
+
when provider_class= @@providers[".#{ ext }"]
|
173
|
+
provider_class.new
|
174
|
+
else
|
175
|
+
nil
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
Dir[File.dirname(__FILE__) / 'data_providers' / '*.rb'].each do |lib|
|
184
|
+
require lib
|
185
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Gumdrop::Data
|
2
|
+
class PStoreDataProvider < Provider
|
3
|
+
|
4
|
+
extension :pstore
|
5
|
+
|
6
|
+
def available?
|
7
|
+
require 'pstore'
|
8
|
+
true
|
9
|
+
rescue LoadError
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def data_for(filepath)
|
14
|
+
data={}
|
15
|
+
store= PStore.new(filepath)
|
16
|
+
store.transaction true do
|
17
|
+
store.roots.each do |root|
|
18
|
+
data[root]= store[root]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
supply_data data
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Gumdrop::Data
|
2
|
+
class SqliteDataProvider < Provider
|
3
|
+
|
4
|
+
extensions :sqlite, :sqlite3, :db
|
5
|
+
|
6
|
+
def available?
|
7
|
+
require 'sqlite3'
|
8
|
+
true
|
9
|
+
rescue LoadError
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def data_for(filepath)
|
14
|
+
@db= SQLite3::Database.new( filepath )
|
15
|
+
@live= SqliteLiveData.new @db, self
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class SqliteLiveData
|
21
|
+
attr_reader :db, :provider
|
22
|
+
|
23
|
+
def initialize(db, provider)
|
24
|
+
@db= db
|
25
|
+
@provider= provider
|
26
|
+
@data_hash= Hash.new &method(:load_data_for)
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_data_for(hash, table_name)
|
30
|
+
data=[]
|
31
|
+
db.results_as_hash = true
|
32
|
+
db.execute( "select * from #{ table_name.to_s };" ) do |row|
|
33
|
+
data << row.reject {|key,col| key.is_a? Fixnum }
|
34
|
+
end
|
35
|
+
hash[table_name]= provider.supply_data data
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(key, *args)
|
39
|
+
@data_hash[key]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Gumdrop::Data
|
2
|
+
class YAMLandJSONDataProvider < Provider
|
3
|
+
|
4
|
+
extensions :yaml, :yml, :json
|
5
|
+
|
6
|
+
def available?
|
7
|
+
require 'yaml'
|
8
|
+
true
|
9
|
+
rescue LoadError
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def data_for(filepath)
|
14
|
+
supply_data YAML.load_file(filepath)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Gumdrop::Data
|
2
|
+
class YAMLDBDataProvider < YAMLandJSONDataProvider
|
3
|
+
|
4
|
+
extension :yamldb
|
5
|
+
|
6
|
+
|
7
|
+
def data_for(filepath)
|
8
|
+
docs=[]
|
9
|
+
File.open(filepath, 'r') do |f|
|
10
|
+
YAML.load_documents(f) do |doc|
|
11
|
+
docs << supply_data( doc ) #unless doc.has_key?("__proto__")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
docs
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/gumdrop/generator.rb
CHANGED
@@ -1,124 +1,148 @@
|
|
1
1
|
module Gumdrop
|
2
2
|
|
3
3
|
class Generator
|
4
|
+
include Util::SiteAccess
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
attr_reader :filename, :base_path, :params, :pages
|
10
|
-
|
11
|
-
def initialize(content, site, opts={})
|
12
|
-
@site= site
|
13
|
-
@content= content
|
14
|
-
if @content.is_a? Proc
|
15
|
-
@filename= ""
|
16
|
-
@base_path= ""
|
17
|
-
else
|
18
|
-
@filename= content.filename || ""
|
19
|
-
@base_path= content.slug || ""
|
20
|
-
end
|
21
|
-
@params= HashObject.new
|
6
|
+
def initialize(content=nil, opts={}, &block) # block?
|
7
|
+
@content= content || block
|
8
|
+
@dsl= DSL.new self
|
22
9
|
@pages= []
|
10
|
+
@filename= content.nil? ? (opts[:filename] || '') : content.filename
|
11
|
+
@base_path= content.nil? ? (opts[:base_path] || '') : content.slug
|
23
12
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
instance_eval &@content
|
29
|
-
else
|
30
|
-
instance_eval File.read(@content.path)
|
13
|
+
|
14
|
+
def unload
|
15
|
+
pages.each do |content|
|
16
|
+
site.contents.remove content
|
31
17
|
end
|
18
|
+
@dsl= DSL.new self
|
32
19
|
end
|
33
20
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def data
|
39
|
-
@site.data
|
21
|
+
def reload
|
22
|
+
unload
|
23
|
+
execute
|
40
24
|
end
|
41
25
|
|
42
|
-
def
|
43
|
-
@
|
44
|
-
end
|
45
|
-
|
46
|
-
def set(var_name, value)
|
47
|
-
params[var_name]= value
|
26
|
+
def pages
|
27
|
+
@pages
|
48
28
|
end
|
49
29
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
File.join @site.src_path, @base_path, @name
|
63
|
-
end
|
64
|
-
content= GeneratedContent.new(filepath, block, @site, self, opts)
|
65
|
-
if opts.has_key? :template and !opts[:template].nil?
|
66
|
-
content.template = if @site.layouts.has_key?( opts[:template] )
|
67
|
-
@site.layouts[ opts[:template] ]
|
30
|
+
def gen_page(name, opts={}, params={}, &block)
|
31
|
+
event_block :generate_item do
|
32
|
+
name.relative!
|
33
|
+
opts= params.reverse_merge(opts)
|
34
|
+
filepath= if @base_path.empty?
|
35
|
+
site.source_path / name
|
36
|
+
else
|
37
|
+
site.source_path / @base_path / name
|
38
|
+
end
|
39
|
+
if block.nil?
|
40
|
+
handler= _render_inline_content opts
|
41
|
+
content= site.contents.create filepath, self, &handler
|
68
42
|
else
|
69
|
-
|
70
|
-
end
|
43
|
+
content= site.contents.create filepath, self, &block
|
44
|
+
end
|
45
|
+
content.params.merge! opts
|
46
|
+
content.params.merge! opts[:params] if opts.has_key?(:params)
|
47
|
+
log.debug " generated: #{content.uri}"
|
48
|
+
@pages << content
|
71
49
|
end
|
72
|
-
content.ignore site.greylist.any? {|pattern| site.path_match name, pattern }
|
73
|
-
unless content.ignored
|
74
|
-
content.ignore site.blacklist.any? {|pattern| site.path_match name, pattern }
|
75
|
-
end
|
76
|
-
@site.report " generated: #{content.uri}", :info
|
77
|
-
@site.content_hash[content.uri]= content
|
78
|
-
@pages << content
|
79
|
-
content
|
80
50
|
end
|
81
51
|
|
82
|
-
|
83
|
-
|
84
|
-
if
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
EOF
|
52
|
+
def execute
|
53
|
+
log.debug "(Generator '#{ @filename }')"
|
54
|
+
if @content.is_a? Proc
|
55
|
+
if @content.arity == 1
|
56
|
+
@content.call @dsl
|
57
|
+
else
|
58
|
+
@dsl.instance_eval &@content
|
90
59
|
end
|
91
|
-
opts[:from]= from
|
92
|
-
@site.redirects << opts
|
93
60
|
else
|
94
|
-
@
|
61
|
+
@dsl.instance_eval @content.body
|
95
62
|
end
|
63
|
+
log.debug " created: #{ @pages.size } pages"
|
96
64
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@content_block= block
|
106
|
-
@generated= true
|
107
|
-
@generator= generator
|
65
|
+
|
66
|
+
def _render_inline_content(opts)
|
67
|
+
Proc.new {
|
68
|
+
renderer= site.active_renderer || Renderer.new
|
69
|
+
content= site.resolve(opts[:render], opts)
|
70
|
+
opts[:inline_render]= true
|
71
|
+
renderer.draw content, opts
|
72
|
+
}
|
108
73
|
end
|
109
74
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
75
|
+
class DSL
|
76
|
+
include Util::SiteAccess
|
77
|
+
include Util::ViewHelpers
|
78
|
+
|
79
|
+
attr_reader :params
|
80
|
+
|
81
|
+
def initialize(generator)
|
82
|
+
@generator= generator
|
83
|
+
@params= Util::HashObject.new
|
84
|
+
end
|
85
|
+
|
86
|
+
def data
|
87
|
+
site.data
|
88
|
+
end
|
89
|
+
|
90
|
+
def config
|
91
|
+
site.config
|
92
|
+
end
|
93
|
+
|
94
|
+
def options
|
95
|
+
site.options
|
96
|
+
end
|
97
|
+
|
98
|
+
def env
|
99
|
+
site.env
|
100
|
+
end
|
101
|
+
|
102
|
+
def mode
|
103
|
+
site.mode
|
115
104
|
end
|
105
|
+
|
106
|
+
def set(var_name, value)
|
107
|
+
@params[var_name]= value
|
108
|
+
end
|
109
|
+
def get(var_name)
|
110
|
+
@params[var_name]
|
111
|
+
end
|
112
|
+
|
113
|
+
def page(name, opts={}, &block)
|
114
|
+
@generator.gen_page name, opts, @params, &block
|
115
|
+
end
|
116
|
+
alias_method :content, :page
|
117
|
+
|
118
|
+
def file(name, opts={}, &block)
|
119
|
+
opts[:layout]= opts[:layout] || false
|
120
|
+
page name, opts, &block
|
121
|
+
end
|
122
|
+
|
116
123
|
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
class << self
|
117
128
|
|
118
|
-
|
119
|
-
|
129
|
+
# Generate a page (based on data or whatever) from your
|
130
|
+
# Gumdrop file like this:
|
131
|
+
#
|
132
|
+
# Gumdrop.generate 'label' do |gen|
|
133
|
+
# gen.file 'my-page.html' do
|
134
|
+
# # whatever you return is set as the page contents.
|
135
|
+
# "hello!"
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
#
|
139
|
+
def generate(name=nil, opts={}, &block)
|
140
|
+
opts[:filename]= name unless opts[:filename]
|
141
|
+
site.generators << Generator.new(nil, opts, &block)
|
120
142
|
end
|
121
143
|
|
122
144
|
end
|
123
|
-
|
145
|
+
|
124
146
|
end
|
147
|
+
|
148
|
+
|