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_manager.rb
DELETED
@@ -1,214 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
module Gumdrop
|
5
|
-
|
6
|
-
# Supported Data File Types:
|
7
|
-
DATA_DOC_EXTS= %w(json yml yaml ymldb yamldb yamldoc ymldoc)
|
8
|
-
|
9
|
-
class DataManager
|
10
|
-
attr_reader :cache
|
11
|
-
|
12
|
-
def initialize(site, data_dir="./data")
|
13
|
-
@site= site
|
14
|
-
@dir= File.expand_path data_dir
|
15
|
-
@cache= {}
|
16
|
-
end
|
17
|
-
|
18
|
-
def method_missing(key, value=nil)
|
19
|
-
cache_dataset(key)
|
20
|
-
@cache[key]
|
21
|
-
end
|
22
|
-
|
23
|
-
def set(key, value)
|
24
|
-
@cache[key]= value
|
25
|
-
end
|
26
|
-
|
27
|
-
def reset
|
28
|
-
@cache={}
|
29
|
-
end
|
30
|
-
|
31
|
-
def site(pattern=nil, opts={})
|
32
|
-
@site.contents(pattern, opts)
|
33
|
-
end
|
34
|
-
|
35
|
-
def pager_for(key, opts={})
|
36
|
-
base_path= opts.fetch(:base_path, 'page')
|
37
|
-
page_size= opts.fetch(:page_size, 5)
|
38
|
-
data= if key.is_a? Symbol
|
39
|
-
cache_dataset(key)
|
40
|
-
@cache[key]
|
41
|
-
else
|
42
|
-
key
|
43
|
-
end
|
44
|
-
Pager.new( data, base_path, page_size )
|
45
|
-
end
|
46
|
-
|
47
|
-
# Exposing these publicly because, well, they're useful:
|
48
|
-
def load_from_file( filename )
|
49
|
-
ext=File.extname(filename)
|
50
|
-
if ext == '.yamldoc' or ext == '.ymldoc'
|
51
|
-
load_from_yamldoc filename
|
52
|
-
elsif ext == '.yamldb' or ext == '.ymldb'
|
53
|
-
load_from_yamldb filename
|
54
|
-
elsif ext == '.yaml' or ext == '.yml' or ext == '.json'
|
55
|
-
hashes2ostruct( YAML.load_file(filename) )
|
56
|
-
else
|
57
|
-
# raise "Unknown data type (#{ext}) for #{filename}"
|
58
|
-
Gumdrop.report "Unknown data type (#{ext}) for #{filename}", :warning
|
59
|
-
nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
def load_yamldoc(filename, source=nil)
|
63
|
-
load_from_yamldoc filename, source
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def cache_dataset(key)
|
70
|
-
@cache[key]= load_data(key) unless @cache.has_key? key
|
71
|
-
end
|
72
|
-
|
73
|
-
def load_data(key)
|
74
|
-
path=get_filename key
|
75
|
-
return nil if path.nil?
|
76
|
-
if File.directory? path
|
77
|
-
load_from_directory path
|
78
|
-
else
|
79
|
-
load_from_file path
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def load_from_yamldb( filename )
|
84
|
-
docs=[]
|
85
|
-
File.open(filename, 'r') do |f|
|
86
|
-
YAML.load_documents(f) do |doc|
|
87
|
-
docs << hashes2ostruct( doc ) unless doc.has_key?("__proto__")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
docs
|
91
|
-
end
|
92
|
-
|
93
|
-
def load_from_yamldoc( filename, source=nil )
|
94
|
-
source = File.read(filename) if source.nil?
|
95
|
-
|
96
|
-
if source =~ /^(\s*---(.+)---\s*)/m
|
97
|
-
yaml = $2.strip
|
98
|
-
content = source.sub($1, '')
|
99
|
-
data= YAML.load(yaml)
|
100
|
-
else
|
101
|
-
content= source
|
102
|
-
data={}
|
103
|
-
end
|
104
|
-
|
105
|
-
content_set= false
|
106
|
-
data.each_pair do |key, value|
|
107
|
-
if value == '_YAMLDOC_'
|
108
|
-
data[key]= content
|
109
|
-
content_set= true
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
data['content']= content unless content_set
|
114
|
-
|
115
|
-
hashes2ostruct(data)
|
116
|
-
end
|
117
|
-
|
118
|
-
def load_from_directory( filepath )
|
119
|
-
all=[]
|
120
|
-
Dir[ File.join "#{filepath}", "{*.#{ DATA_DOC_EXTS.join ',*.'}}" ].each do |filename|
|
121
|
-
# Gumdrop.report ">> Loading data file: #{filename}"
|
122
|
-
id= File.basename filename
|
123
|
-
obj_hash= load_from_file filename
|
124
|
-
obj_hash._id = id
|
125
|
-
all << obj_hash
|
126
|
-
end
|
127
|
-
all
|
128
|
-
end
|
129
|
-
|
130
|
-
def get_filename(path)
|
131
|
-
lpath= local_path_to(path)
|
132
|
-
if File.directory? lpath
|
133
|
-
lpath
|
134
|
-
else
|
135
|
-
DATA_DOC_EXTS.each do |ext|
|
136
|
-
lpath= local_path_to("#{path}.#{ext}")
|
137
|
-
return lpath if File.exists? lpath
|
138
|
-
end
|
139
|
-
Gumdrop.report "No data found for #{path}", :warning
|
140
|
-
nil
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def local_path_to(filename)
|
145
|
-
File.join(@dir.to_s, filename.to_s)
|
146
|
-
end
|
147
|
-
|
148
|
-
def hashes2ostruct(object)
|
149
|
-
return case object
|
150
|
-
when Hash
|
151
|
-
object = object.clone
|
152
|
-
object.each do |key, value|
|
153
|
-
object[key] = hashes2ostruct(value)
|
154
|
-
end
|
155
|
-
OpenStruct.new(object)
|
156
|
-
when Array
|
157
|
-
object = object.clone
|
158
|
-
object.map! { |i| hashes2ostruct(i) }
|
159
|
-
else
|
160
|
-
object
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
class Pager
|
167
|
-
attr_reader :all, :pages, :base_url, :current_page, :page_sets
|
168
|
-
|
169
|
-
def initialize(articles, base_path="/page", page_size=5)
|
170
|
-
@all= articles
|
171
|
-
@page_size= page_size
|
172
|
-
@base_path= base_path
|
173
|
-
@page_sets= @all.in_groups_of(page_size, false)
|
174
|
-
@pages= []
|
175
|
-
@current_page=1
|
176
|
-
@page_sets.each do |art_ary|
|
177
|
-
@pages << HashObject.new({
|
178
|
-
items: art_ary,
|
179
|
-
page: @current_page,
|
180
|
-
uri: "#{base_path}/#{current_page}",
|
181
|
-
pager: self
|
182
|
-
})
|
183
|
-
@current_page += 1
|
184
|
-
end
|
185
|
-
@current_page= nil
|
186
|
-
end
|
187
|
-
|
188
|
-
def length
|
189
|
-
@pages.length
|
190
|
-
end
|
191
|
-
|
192
|
-
def first
|
193
|
-
@pages.first
|
194
|
-
end
|
195
|
-
|
196
|
-
def last
|
197
|
-
@pages.last
|
198
|
-
end
|
199
|
-
|
200
|
-
def each
|
201
|
-
@current_page=1
|
202
|
-
@pages.each do |page_set|
|
203
|
-
yield page_set
|
204
|
-
@current_page += 1
|
205
|
-
end
|
206
|
-
@current_page= nil
|
207
|
-
end
|
208
|
-
|
209
|
-
def [](key)
|
210
|
-
@pages[key]
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Gumdrop
|
2
|
-
module Support
|
3
|
-
module BasePackager
|
4
|
-
|
5
|
-
def compress_output(content, opts)
|
6
|
-
case opts[:compress]
|
7
|
-
|
8
|
-
when true, :jsmin
|
9
|
-
require 'jsmin'
|
10
|
-
JSMin.minify content
|
11
|
-
|
12
|
-
when :yuic
|
13
|
-
require "yui/compressor"
|
14
|
-
compressor = YUI::JavaScriptCompressor.new(:munge => opts[:obfuscate])
|
15
|
-
compressor.compress(content)
|
16
|
-
|
17
|
-
when :uglify
|
18
|
-
require "uglifier"
|
19
|
-
Uglifier.compile( content, :mangle=>opts[:obfuscate])
|
20
|
-
|
21
|
-
when :packr
|
22
|
-
require 'packr'
|
23
|
-
Packr.pack(content, :shrink_vars => true, :base62 => false, :private=>false)
|
24
|
-
|
25
|
-
when false
|
26
|
-
content
|
27
|
-
|
28
|
-
else
|
29
|
-
# UNKNOWN Compressor type!
|
30
|
-
@site.report "Unknown javascript compressor type! (#{ opts[:compressor] })", :warning
|
31
|
-
content
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def keep_src(name, content, opts)
|
36
|
-
if opts[:keep_src] or opts[:keep_source]
|
37
|
-
ext= File.extname name
|
38
|
-
page name.gsub(ext, "#{opts.fetch(:source_postfix, '-src')}#{ext}") do
|
39
|
-
content
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def prune_src(name, opts)
|
45
|
-
if opts[:prune] and opts[:root]
|
46
|
-
sp = File.expand_path( @site.config.source_dir )
|
47
|
-
rp = File.expand_path(opts[:root])
|
48
|
-
relative_root = rp.gsub(sp, '')[1..-1]
|
49
|
-
rrlen= relative_root.length - 1
|
50
|
-
@site.content_hash.keys.each do |path|
|
51
|
-
if path[0..rrlen] == relative_root and name != path
|
52
|
-
@site.content_hash.delete path
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Gumdrop::Support
|
2
|
-
module Callbacks
|
3
|
-
|
4
|
-
# For defining callbacks
|
5
|
-
def callback(*callback_names)
|
6
|
-
callback_names.each do |name|
|
7
|
-
class_eval <<-EOF
|
8
|
-
def #{name}(*args, &block)
|
9
|
-
if block
|
10
|
-
@_#{name} = [] if @_#{name}.nil?
|
11
|
-
@_#{name} << block
|
12
|
-
elsif @_#{name} and !@_#{name}.nil?
|
13
|
-
@_#{name}.each do |cb|
|
14
|
-
cb.call(*args)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
def clear_#{name}()
|
19
|
-
@_#{name} = nil
|
20
|
-
end
|
21
|
-
EOF
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
alias_method :callbacks, :callback
|
26
|
-
alias_method :define_callback, :callback
|
27
|
-
alias_method :define_callbacks, :callback
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Gumdrop
|
2
|
-
|
3
|
-
class HashObject < ActiveSupport::HashWithIndifferentAccess
|
4
|
-
|
5
|
-
def method_missing(sym, *args, &block)
|
6
|
-
if self.has_key? sym
|
7
|
-
self[sym]
|
8
|
-
|
9
|
-
elsif sym.to_s.ends_with? '='
|
10
|
-
key= sym.to_s.chop.to_sym
|
11
|
-
self[key]= args[0]
|
12
|
-
|
13
|
-
else
|
14
|
-
# FIXME: Return super() or nil for Model#method_missing?
|
15
|
-
# super sym, *args, &block
|
16
|
-
nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
data/lib/gumdrop/view_helpers.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Gumdrop
|
2
|
-
|
3
|
-
module ViewHelpers
|
4
|
-
|
5
|
-
def hidden(&block)
|
6
|
-
#no-op
|
7
|
-
end
|
8
|
-
|
9
|
-
def markdown(source)
|
10
|
-
m= Tilt['markdown'].new { source }
|
11
|
-
m.render
|
12
|
-
end
|
13
|
-
|
14
|
-
def textile(source)
|
15
|
-
m= Tilt['textile'].new { source }
|
16
|
-
m.render
|
17
|
-
end
|
18
|
-
|
19
|
-
def gumdrop_version
|
20
|
-
::Gumdrop::VERSION
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/notes.md
DELETED
@@ -1,347 +0,0 @@
|
|
1
|
-
# General
|
2
|
-
|
3
|
-
Gumdrop is based on personal and project code from several years ago. It's been slowly updated and improved over time. But I've not been able to give it a lot of sustained effort to get it where I want it.
|
4
|
-
|
5
|
-
Since I started, Jekyl, MiddleMan, and other static site tools have been released. While they are all good in their own ways, each miss something that I want. The main difference, at this point in time, are generators. I want to have a static site, but still have data-driven pages.
|
6
|
-
|
7
|
-
Anyway, this is just a place for me to put down my thoughts on what I want to do to get it servicable as a 1.0 candidate:
|
8
|
-
|
9
|
-
|
10
|
-
# Architectural Changes
|
11
|
-
|
12
|
-
- Rendering should be abstracted from Content objects
|
13
|
-
- Building should be abstracted from Site object
|
14
|
-
- Generators should be able to unload themselves and any pages they created
|
15
|
-
- There should be discreet ways of knowing whether a Content object is renderable or not (other than file ext)
|
16
|
-
- DSL generators should accept a name, and optional base_path (applied to all generated page paths)
|
17
|
-
- Callbacks should have the site var in scope
|
18
|
-
- Reporting/logging needs to be abstracted from Site and all dependant objects (Loggable module?)
|
19
|
-
- Project Templates should be abstracted from CLI::Internal (and External) into a module
|
20
|
-
- Make `DataManager` more OO -- abstract data providers. Each provider would specifiy the file extensions they handle.
|
21
|
-
- Bundler.require site.config.env.to_sym
|
22
|
-
|
23
|
-
## Nice to Haves
|
24
|
-
|
25
|
-
- Server should be able to selectively render individual content without rescanning/building the whole tree
|
26
|
-
|
27
|
-
# Impl Notes
|
28
|
-
|
29
|
-
## Content
|
30
|
-
|
31
|
-
- Content objects can know their `level` based on their `full_path` (basically count the slashes)
|
32
|
-
|
33
|
-
```rb
|
34
|
-
contentA = Content.new "source/page.html.erb"
|
35
|
-
contentB = Content.new "source/logo.png"
|
36
|
-
|
37
|
-
contentA.binary? #=> false
|
38
|
-
contentB.binary? #=> true
|
39
|
-
```
|
40
|
-
|
41
|
-
Possible `binary?` method (from ptools):
|
42
|
-
|
43
|
-
```rb
|
44
|
-
class Content
|
45
|
-
def initialize(source_path, generator=nil, &block)
|
46
|
-
@source_path= source_path
|
47
|
-
@filename= File.basename(source_path)
|
48
|
-
@generator=generator
|
49
|
-
@block= block
|
50
|
-
# etc...
|
51
|
-
end
|
52
|
-
|
53
|
-
def binary?(file)
|
54
|
-
@is_binary ||= begin
|
55
|
-
s = (File.read(file, File.stat(file).blksize) || "").split(//)
|
56
|
-
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def generated?
|
61
|
-
!@generator.nil?
|
62
|
-
emd
|
63
|
-
|
64
|
-
def body # Memoize this?
|
65
|
-
if @block
|
66
|
-
@block.call
|
67
|
-
else
|
68
|
-
File.read @source_path
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
```
|
73
|
-
|
74
|
-
## Events/Observable
|
75
|
-
|
76
|
-
Use Observable internally?
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
module Eventable
|
80
|
-
include Observable
|
81
|
-
|
82
|
-
def fire(action, data={}, sender=self)
|
83
|
-
changed
|
84
|
-
notify_observers(sender, action, data)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Usage
|
89
|
-
class MyClass
|
90
|
-
includes Eventable
|
91
|
-
|
92
|
-
def execute
|
93
|
-
fire :my_action, ex:'data'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
```
|
98
|
-
|
99
|
-
Listeners would always have the same signature:
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
class Listener
|
103
|
-
def update(sender, action, data)
|
104
|
-
puts "(#{ sender.inspect }) #{action}: #{ data.inspect }"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
```
|
108
|
-
Have the site listen and bubble the events?
|
109
|
-
|
110
|
-
```ruby
|
111
|
-
class Site
|
112
|
-
includes Eventable
|
113
|
-
|
114
|
-
def # wherever
|
115
|
-
renderer= HtmlRenderer.new
|
116
|
-
renderer.add_observer self
|
117
|
-
renderer.draw # whatever
|
118
|
-
|
119
|
-
#done
|
120
|
-
renderer.delete_observers
|
121
|
-
end
|
122
|
-
|
123
|
-
def update(sender, action, data)
|
124
|
-
fire action, data, sender
|
125
|
-
end
|
126
|
-
end
|
127
|
-
```
|
128
|
-
|
129
|
-
## Rendering
|
130
|
-
|
131
|
-
```rb
|
132
|
-
|
133
|
-
class RenderContext
|
134
|
-
include ViewHelpers
|
135
|
-
|
136
|
-
attr_reader :content, :site, :state
|
137
|
-
# attr_writer :content, :renderer
|
138
|
-
|
139
|
-
def initialize(content, renderer, parent_context=nil)
|
140
|
-
@content= content
|
141
|
-
@renderer= renderer
|
142
|
-
@site= renderer.site
|
143
|
-
@state= {}
|
144
|
-
@parent= parent_context
|
145
|
-
end
|
146
|
-
|
147
|
-
def render(*args) # Not exactly sure yet
|
148
|
-
content= # extract/lookup a content object from args
|
149
|
-
# maybe allow relative lookups from content?
|
150
|
-
@renderer.draw_partial content
|
151
|
-
end
|
152
|
-
|
153
|
-
def get(key)
|
154
|
-
@state[key]
|
155
|
-
end
|
156
|
-
|
157
|
-
def set(key, value)
|
158
|
-
@state[key]= value
|
159
|
-
end
|
160
|
-
|
161
|
-
def method_missing(*stuff)
|
162
|
-
# try to get/set from @state
|
163
|
-
# else try to get from @parent unless @parent.nil?
|
164
|
-
# else try and get it from @content
|
165
|
-
# else return nil ???
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
class Renderer
|
170
|
-
includes Eventable
|
171
|
-
|
172
|
-
attr_reader :site, :context
|
173
|
-
|
174
|
-
def initialize(site)
|
175
|
-
@site= site
|
176
|
-
end
|
177
|
-
|
178
|
-
def draw(content, opts={})
|
179
|
-
return nil if content.binary?
|
180
|
-
@context= RenderContext.new site, content, self
|
181
|
-
output= _render_content content, opts
|
182
|
-
fire :render, content:content, output:output
|
183
|
-
output
|
184
|
-
end
|
185
|
-
|
186
|
-
def draw_partial(content, opts={})
|
187
|
-
return nil if content.binary?
|
188
|
-
opts.defaults! no_layout:true
|
189
|
-
_sub_context content
|
190
|
-
output= _render_content content, opts
|
191
|
-
fire :render_partial, content:content, output:output
|
192
|
-
_revert_context
|
193
|
-
output
|
194
|
-
end
|
195
|
-
|
196
|
-
private
|
197
|
-
|
198
|
-
def _render_content(content, opts)
|
199
|
-
output= content.body
|
200
|
-
_render_pipeline(content.filename).each do |template|
|
201
|
-
output= _render_text output, template
|
202
|
-
end
|
203
|
-
output- _render_layout output unless opts[:no_layout]
|
204
|
-
output
|
205
|
-
end
|
206
|
-
|
207
|
-
def _render_text(text, tmpl, opts)
|
208
|
-
# Tilt Code
|
209
|
-
tmpl.new(opts).render(text) # pass opts on through?
|
210
|
-
end
|
211
|
-
|
212
|
-
def _render_layout(text)
|
213
|
-
# Look for @context[:layout] or site.config.default_template
|
214
|
-
end
|
215
|
-
|
216
|
-
def _render_pipeline(path)
|
217
|
-
# path.split('.') # then sort out how to:
|
218
|
-
# return an array of Tilt templates based on file exts
|
219
|
-
[]
|
220
|
-
end
|
221
|
-
|
222
|
-
def _sub_context(content)
|
223
|
-
@old_context= @context
|
224
|
-
@context= Context.new site, content, self, @old_context
|
225
|
-
end
|
226
|
-
|
227
|
-
def _revert_context
|
228
|
-
@context = @old_context
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
|
233
|
-
```
|
234
|
-
|
235
|
-
## Building
|
236
|
-
|
237
|
-
```ruby
|
238
|
-
class Builder
|
239
|
-
include Eventable
|
240
|
-
|
241
|
-
attr_accessor :site, :renderer
|
242
|
-
|
243
|
-
def initialize(site=nil, renderer=nil)
|
244
|
-
@site= site
|
245
|
-
@renderer= renderer.nil? ? Renderer.new(site) : renderer
|
246
|
-
end
|
247
|
-
|
248
|
-
def execute()
|
249
|
-
fire :build_start
|
250
|
-
site.contents.each do |content|
|
251
|
-
if content.binary?
|
252
|
-
_copy content.src_path => _output_path(content)
|
253
|
-
else
|
254
|
-
output = renderer.draw content
|
255
|
-
_write output => _output_path(content)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
fire :build_end
|
259
|
-
rescue => ex
|
260
|
-
fire :exception, source:self, ex:ex
|
261
|
-
end
|
262
|
-
|
263
|
-
private
|
264
|
-
|
265
|
-
def _copy(files)
|
266
|
-
files.each_pair do |from,to|
|
267
|
-
# File.write code
|
268
|
-
fire :copy, from:from, to:to
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
def _write(files)
|
273
|
-
files.each_pair do |text,to|
|
274
|
-
# File.write code
|
275
|
-
fire :write, from:from, to:to
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
|
281
|
-
# Usage
|
282
|
-
site= Gumdrop.local_site #=> Site
|
283
|
-
renderer= HtmlRenderer.new
|
284
|
-
builder= Builder.new site, renderer
|
285
|
-
builder.execute()
|
286
|
-
```
|
287
|
-
|
288
|
-
# Logging via Events?
|
289
|
-
|
290
|
-
- Only two levels? `:info` and `:warn`? Or add `:error`
|
291
|
-
|
292
|
-
```ruby
|
293
|
-
# Mixin to your class:
|
294
|
-
module Loggable
|
295
|
-
|
296
|
-
# Assumes Eventable? or:
|
297
|
-
# include Eventable
|
298
|
-
|
299
|
-
def log(level, msg=nil)
|
300
|
-
if msg.nil?
|
301
|
-
msg= level
|
302
|
-
level= :info
|
303
|
-
end
|
304
|
-
fire :log, level:level, message:msg
|
305
|
-
end
|
306
|
-
|
307
|
-
def warn(msg)
|
308
|
-
log :warn, msg
|
309
|
-
end
|
310
|
-
|
311
|
-
end
|
312
|
-
|
313
|
-
# Loggers
|
314
|
-
class ConsoleLogger
|
315
|
-
def initialize(levels, format='%<level>s : %<message>s')
|
316
|
-
@listen_for= levels
|
317
|
-
@format= format
|
318
|
-
end
|
319
|
-
def update(sender, action, data)
|
320
|
-
if action == :log
|
321
|
-
if @listen_for.include? data.level
|
322
|
-
data[:sender]= sender.to_s
|
323
|
-
data[:time]= Time.new
|
324
|
-
puts sprintf(@format, data)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
329
|
-
```
|
330
|
-
|
331
|
-
Or maybe not... I think maybe this:
|
332
|
-
|
333
|
-
```ruby
|
334
|
-
module Loggable
|
335
|
-
def log
|
336
|
-
Gumdrop.logger
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
module Gumdrop
|
341
|
-
class << self
|
342
|
-
attr_accessor :logger
|
343
|
-
end
|
344
|
-
end
|
345
|
-
```
|
346
|
-
|
347
|
-
|