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
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
module Gumdrop::Support
|
3
|
+
|
4
|
+
module Compressor
|
5
|
+
|
6
|
+
def compress(content, opts)
|
7
|
+
case opts
|
8
|
+
when Symbol, String
|
9
|
+
do_compress content, opts.to_s.to_sym
|
10
|
+
when Hash
|
11
|
+
do_compress content, opts[:with].to_s.to_sym, opts
|
12
|
+
else
|
13
|
+
# UNKNOWN Compressor type!
|
14
|
+
log.warn "Unknown javascript compressor type!"
|
15
|
+
content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def do_compress(content, type, opts={})
|
22
|
+
case type
|
23
|
+
when :jsmin
|
24
|
+
require 'jsmin'
|
25
|
+
JSMin.minify content
|
26
|
+
|
27
|
+
when :yuic
|
28
|
+
require "yui/compressor"
|
29
|
+
compressor = YUI::JavaScriptCompressor.new(:munge => opts[:obfuscate])
|
30
|
+
compressor.compress(content)
|
31
|
+
|
32
|
+
when :uglify
|
33
|
+
require "uglifier"
|
34
|
+
Uglifier.compile( content, :mangle=>opts[:obfuscate])
|
35
|
+
|
36
|
+
when :packr
|
37
|
+
require 'packr'
|
38
|
+
Packr.pack(content, :shrink_vars => true, :base62 => false, :private=>false)
|
39
|
+
|
40
|
+
else
|
41
|
+
# UNKNOWN Compressor type!
|
42
|
+
log.warn "Unknown javascript compressor type! (#{ type })"
|
43
|
+
content
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
Gumdrop::Generator::DSL.send :include, Compressor
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -1,34 +1,25 @@
|
|
1
|
-
# sprockets.rb
|
2
|
-
begin
|
3
|
-
require 'sprockets'
|
4
|
-
has_sprockets= true
|
5
|
-
rescue LoadError
|
6
|
-
has_sprockets= false
|
7
|
-
end
|
8
1
|
|
9
2
|
module Gumdrop::Support
|
10
3
|
|
11
4
|
module Sprockets # mixes in to generator
|
12
|
-
include BasePackager
|
13
5
|
|
14
|
-
def sprockets(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
page name do
|
23
|
-
compress_output(content, opts)
|
24
|
-
end
|
25
|
-
keep_src(name, content, opts)
|
26
|
-
prune_src(name, opts)
|
27
|
-
else
|
28
|
-
throw "Sprockets can't be loaded. Please add it to your Gemfile."
|
6
|
+
def sprockets(source_file, opts={})
|
7
|
+
require 'sprockets'
|
8
|
+
source_path = source_file || opt[:main] || opt[:from]
|
9
|
+
env = ::Sprockets::Environment.new site.root
|
10
|
+
env.append_path site.source_path
|
11
|
+
env.append_path File.dirname(source_path)
|
12
|
+
[opts[:paths]].flatten.each do |path|
|
13
|
+
env.append_path(path) unless path.nil?
|
29
14
|
end
|
15
|
+
content= env[ source_path ].to_s
|
16
|
+
rescue LoadError
|
17
|
+
raise StandardError, "Sprockets can't be loaded. Please add it to your Gemfile."
|
30
18
|
end
|
31
19
|
|
32
20
|
end
|
33
21
|
|
22
|
+
Gumdrop::Generator::DSL.send :include, Sprockets
|
23
|
+
|
34
24
|
end
|
25
|
+
|
@@ -9,26 +9,37 @@ end
|
|
9
9
|
module Gumdrop::Support
|
10
10
|
|
11
11
|
module Stitch # mixes in to generator
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
|
13
|
+
# Stitch::Package.new options:
|
14
|
+
# :identifier=>'app', # variable name for the library
|
15
|
+
# :paths=>['./app'],
|
16
|
+
# :root=>'./app',
|
17
|
+
# :dependencies=>[], # List of scripts to prepend to top of file (non moduled)
|
18
|
+
def stitch(source_file, opts={})
|
19
|
+
require 'stitch-rb'
|
20
|
+
content= site.resolve source_file
|
21
|
+
path = content.nil? ? source_file : content.source_path
|
22
|
+
stitch_opts= {} #{ root: content.source_path }
|
23
|
+
stitch_opts.merge! opts
|
24
|
+
stitch_opts[:paths] ||= []
|
25
|
+
stitch_opts[:paths] << File.dirname(path)
|
26
|
+
::Stitch::Package.new(stitch_opts).compile
|
27
|
+
rescue LoadError
|
28
|
+
raise StandardError, "Stitch can't be loaded. Please add it to your Gemfile."
|
25
29
|
end
|
26
30
|
|
27
31
|
end
|
28
32
|
|
33
|
+
Gumdrop::Generator::DSL.send :include, Stitch
|
34
|
+
|
29
35
|
end
|
30
36
|
|
31
|
-
|
37
|
+
|
38
|
+
#
|
39
|
+
# These cause weird side effects, need to pull them out into a js-app
|
40
|
+
# specific template!
|
41
|
+
#
|
42
|
+
if false # defined?(Stitch)
|
32
43
|
|
33
44
|
class Stitch::Source
|
34
45
|
# Patch for gumdrop style filenames
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Tilt
|
4
|
+
class YamlDocTemplate < Template
|
5
|
+
|
6
|
+
def render(scope=Object.new, locals={}, &block)
|
7
|
+
yamldoc= Gumdrop::Util::YamlDoc.new(@data)
|
8
|
+
scope.set yamldoc.data if scope.respond_to? :set
|
9
|
+
yamldoc.body
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def prepare
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def evaluate(scope, locals, &block)
|
19
|
+
method = compiled_method(locals.keys)
|
20
|
+
method.bind(scope).call(locals, &block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
Tilt.register Tilt::YamlDocTemplate, 'yamldoc'
|
27
|
+
Tilt.register Tilt::YamlDocTemplate, 'yamdoc'
|
28
|
+
Tilt.register Tilt::YamlDocTemplate, 'yd'
|
29
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Gumdrop::Util
|
2
|
+
|
3
|
+
module Configurable
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def config_accessor(*keys)
|
7
|
+
keys.each do |key|
|
8
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
9
|
+
def #{key}; config[#{key.inspect}]; end
|
10
|
+
def #{key}=(value); config[#{key.inspect}]= value; end
|
11
|
+
RUBY
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
module InstanceMethods
|
18
|
+
|
19
|
+
def config
|
20
|
+
@config ||= HashObject.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure(&block)
|
24
|
+
if block.arity == 1
|
25
|
+
block.call config
|
26
|
+
else
|
27
|
+
config.instance_eval &block
|
28
|
+
end
|
29
|
+
config_did_change
|
30
|
+
end
|
31
|
+
|
32
|
+
def config_did_change
|
33
|
+
# Override me!
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.included(receiver)
|
39
|
+
receiver.extend ClassMethods
|
40
|
+
receiver.send :include, InstanceMethods
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
|
5
|
+
def to_symbolized_hash
|
6
|
+
new_hash= {}
|
7
|
+
self.each {|k,v| new_hash[k.to_sym]= v }
|
8
|
+
new_hash
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hash_object
|
12
|
+
Gumdrop::Util::HashObject.from self
|
13
|
+
end
|
14
|
+
|
15
|
+
def ends_with?(string)
|
16
|
+
self[0..(string.length)] == string
|
17
|
+
end
|
18
|
+
|
19
|
+
def starts_with?(string)
|
20
|
+
self[0..(string.length)] == string
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class String
|
26
|
+
|
27
|
+
def / (other)
|
28
|
+
File.join self, other
|
29
|
+
end
|
30
|
+
|
31
|
+
def relative
|
32
|
+
dup.relative!
|
33
|
+
end
|
34
|
+
|
35
|
+
def relative!
|
36
|
+
sub! /^[\/]/, ''
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def expand_path(relative_to=nil)
|
41
|
+
if (Pathname.new self).absolute?
|
42
|
+
self
|
43
|
+
elsif relative_to.nil?
|
44
|
+
File.expand_path self
|
45
|
+
else
|
46
|
+
File.expand_path relative_to / self
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def path_match?(pattern)
|
51
|
+
File.fnmatch pattern, self, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_CASEFOLD
|
52
|
+
end
|
53
|
+
|
54
|
+
# alias_method :starts_with?, :start_with?
|
55
|
+
# alias_method :ends_with?, :end_with?
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# module PathTools
|
61
|
+
|
62
|
+
# def / (other)
|
63
|
+
# self.join other.to_s
|
64
|
+
# end
|
65
|
+
|
66
|
+
# def - (other)
|
67
|
+
# Pathname.new self.to_s.gsub(other, '')
|
68
|
+
# end
|
69
|
+
|
70
|
+
# def match?(other)
|
71
|
+
# fnmatch? pattern, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_CASEFOLD
|
72
|
+
# end
|
73
|
+
|
74
|
+
# end
|
75
|
+
|
76
|
+
# class Pathname
|
77
|
+
# include PathTools
|
78
|
+
# end
|
79
|
+
|
80
|
+
# class String
|
81
|
+
# def to_pathname
|
82
|
+
# Pathname.new self
|
83
|
+
# end
|
84
|
+
# end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'onfire'
|
2
|
+
|
3
|
+
module Gumdrop::Util
|
4
|
+
|
5
|
+
module Eventable
|
6
|
+
include ::Onfire
|
7
|
+
|
8
|
+
def event_block(target)
|
9
|
+
fire "before_#{target}".to_sym
|
10
|
+
data= HashObject.new
|
11
|
+
result= data.payload= yield(data)
|
12
|
+
fire target, data
|
13
|
+
fire "after_#{target}".to_sym, data
|
14
|
+
data.return_value || result
|
15
|
+
end
|
16
|
+
|
17
|
+
def fire(event, data=nil)
|
18
|
+
data= case
|
19
|
+
when data.nil?
|
20
|
+
HashObject.from site:Gumdrop.site
|
21
|
+
when data.is_a?(Hash)
|
22
|
+
HashObject.from(data).merge site:Gumdrop.site
|
23
|
+
else
|
24
|
+
data
|
25
|
+
end
|
26
|
+
event_for(event, self, data).bubble!
|
27
|
+
end
|
28
|
+
|
29
|
+
def clear_events
|
30
|
+
@event_table ||= Onfire::EventTable.new
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Gumdrop::Util
|
2
|
+
|
3
|
+
class HashObject < Hash
|
4
|
+
|
5
|
+
# All keys are symbols, internally
|
6
|
+
def [](key)
|
7
|
+
super(key.to_sym)
|
8
|
+
end
|
9
|
+
def []=(key, value)
|
10
|
+
super(key.to_sym, value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(sym, *args, &block)
|
14
|
+
if self.has_key? sym.to_s or self.has_key? sym
|
15
|
+
self[sym]
|
16
|
+
elsif sym.to_s.ends_with? '='
|
17
|
+
key= sym.to_s.chop
|
18
|
+
self[key]= args[0]
|
19
|
+
else
|
20
|
+
# super sym, *args, &block # ???
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(key)
|
26
|
+
self[key]
|
27
|
+
end
|
28
|
+
def set(key,value=nil)
|
29
|
+
if key.is_a? Hash
|
30
|
+
key.each do |k,v|
|
31
|
+
self[k]= v
|
32
|
+
end
|
33
|
+
else
|
34
|
+
self[key]= value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_key?(key)
|
39
|
+
super key.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
def store(key,value)
|
43
|
+
super(key.to_sym, value)
|
44
|
+
end
|
45
|
+
|
46
|
+
def merge(other_hash=nil, &block)
|
47
|
+
unless other_hash.nil?
|
48
|
+
super(other_hash.to_symbolized_hash, &block)
|
49
|
+
else
|
50
|
+
super(other_hash, &block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def merge!(other_hash=nil, &block)
|
55
|
+
unless other_hash.nil?
|
56
|
+
super(other_hash.to_symbolized_hash, &block)
|
57
|
+
else
|
58
|
+
super(other_hash, &block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.from(hash={})
|
63
|
+
h= new
|
64
|
+
h.merge!(hash)
|
65
|
+
h
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Gumdrop
|
4
|
+
|
5
|
+
module Util
|
6
|
+
module Loggable
|
7
|
+
def log
|
8
|
+
Gumdrop.log
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
LOG_LEVELS= {
|
16
|
+
debug: Logger::DEBUG,
|
17
|
+
info: Logger::INFO,
|
18
|
+
warn: Logger::WARN,
|
19
|
+
error: Logger::ERROR,
|
20
|
+
fatal: Logger::FATAL,
|
21
|
+
unknown: Logger::UNKNOWN
|
22
|
+
}
|
23
|
+
|
24
|
+
def log
|
25
|
+
@log ||= begin
|
26
|
+
log= Logger.new STDOUT
|
27
|
+
log.level= LOG_LEVELS[:warn]
|
28
|
+
log
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def init_logging
|
33
|
+
level= (site.config.log_level || :warn).to_sym
|
34
|
+
@log = Logger.new site.config.log || STDOUT
|
35
|
+
@log.level= LOG_LEVELS[level]
|
36
|
+
# @log.formatter = proc { |severity, datetime, progname, msg|
|
37
|
+
# # original_formatter.call(severity, datetime, progname, msg.dump)
|
38
|
+
# "#{msg}\n"
|
39
|
+
# }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Gumdrop::Util
|
2
|
+
|
3
|
+
class Pager
|
4
|
+
attr_reader :all, :pages, :base_url, :current_page, :page_sets
|
5
|
+
|
6
|
+
def initialize(articles, base_path="/page", page_size=5)
|
7
|
+
@all= articles
|
8
|
+
@page_size= page_size
|
9
|
+
@base_path= base_path
|
10
|
+
@page_sets= @all.in_groups_of(page_size, false)
|
11
|
+
@pages= []
|
12
|
+
@current_page=1
|
13
|
+
@page_sets.each do |art_ary|
|
14
|
+
@pages << HashObject.from({
|
15
|
+
items: art_ary,
|
16
|
+
page: @current_page,
|
17
|
+
uri: "#{base_path}/#{current_page}",
|
18
|
+
pager: self
|
19
|
+
})
|
20
|
+
@current_page += 1
|
21
|
+
end
|
22
|
+
@current_page= nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def length
|
26
|
+
@pages.length
|
27
|
+
end
|
28
|
+
|
29
|
+
def first
|
30
|
+
@pages.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def last
|
34
|
+
@pages.last
|
35
|
+
end
|
36
|
+
|
37
|
+
def each
|
38
|
+
@current_page=1
|
39
|
+
@pages.each do |page_set|
|
40
|
+
yield page_set
|
41
|
+
@current_page += 1
|
42
|
+
end
|
43
|
+
@current_page= nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def [](key)
|
47
|
+
@pages[key]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -25,8 +25,8 @@ module Gumdrop
|
|
25
25
|
|
26
26
|
def self.handle_proxy(proxy, proxy_url, env)
|
27
27
|
if proxy[:secure] && !HTTPS_ENABLED
|
28
|
-
|
29
|
-
|
28
|
+
log.warn "~ WARNING: HTTPS is not supported on your system, using HTTP instead.\n"
|
29
|
+
log.warn " If you are using Ubuntu, you can run `apt-get install libopenssl-ruby`\n"
|
30
30
|
proxy[:secure] = false
|
31
31
|
end
|
32
32
|
|
@@ -35,7 +35,7 @@ module Gumdrop
|
|
35
35
|
url = proxy[:path_info] #proxy_url #env['PATH_INFO']
|
36
36
|
params = env['QUERY_STRING']
|
37
37
|
|
38
|
-
|
38
|
+
log.info "PROXY: -> #{url}"
|
39
39
|
|
40
40
|
# collect headers...
|
41
41
|
headers = {}
|
@@ -98,7 +98,7 @@ module Gumdrop
|
|
98
98
|
status = response.code # http status code
|
99
99
|
protocol = proxy[:secure] ? 'https' : 'http'
|
100
100
|
|
101
|
-
|
101
|
+
log.log "~ PROXY: #{http_method.upcase} #{status} #{url} -> #{protocol}://#{http_host}:#{http_port}#{http_path}\n"
|
102
102
|
|
103
103
|
# display and construct specific response headers
|
104
104
|
response_headers = {}
|
@@ -122,12 +122,13 @@ module Gumdrop
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
|
125
|
+
#$stderr << " #{key}: #{value}\n"
|
126
|
+
|
126
127
|
response_headers[key] = value
|
127
128
|
end
|
128
129
|
|
129
130
|
if [301, 302, 303, 307].include?(status.to_i) && proxy[:redirect] != false
|
130
|
-
|
131
|
+
log.warn '~ REDIRECTING: '+response_headers['location']+"\n"
|
131
132
|
|
132
133
|
uri = URI.parse(response_headers['location']);
|
133
134
|
http_host = uri.host
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Gumdrop::Util
|
2
|
+
|
3
|
+
class Scanner
|
4
|
+
include Loggable
|
5
|
+
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(base_path, opts={}, &block)
|
9
|
+
@source_glob= base_path / "**" / "*"
|
10
|
+
@options= opts
|
11
|
+
@src_path= base_path
|
12
|
+
@validator= block || method(:_default_validator)
|
13
|
+
end
|
14
|
+
|
15
|
+
def each
|
16
|
+
Dir.glob(@source_glob, File::FNM_DOTMATCH).each do |path|
|
17
|
+
rel_path= _relative(path)
|
18
|
+
unless should_skip? rel_path, path
|
19
|
+
yield path, rel_path
|
20
|
+
else
|
21
|
+
log.debug " excluding: #{ rel_path }"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def should_skip?(path, full_path)
|
27
|
+
return true if File.directory?(full_path)
|
28
|
+
@validator.call(path, full_path) || false
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def _default_validator(src,full)
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def _relative(path)
|
38
|
+
relpath= path.gsub @src_path, ''
|
39
|
+
if relpath[0]== '/'
|
40
|
+
relpath[1..-1]
|
41
|
+
else
|
42
|
+
relpath
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Gumdrop
|
2
|
+
|
3
|
+
module Util
|
4
|
+
module ViewHelpers
|
5
|
+
|
6
|
+
def hidden(&block)
|
7
|
+
#no-op
|
8
|
+
end
|
9
|
+
|
10
|
+
def markdown(source)
|
11
|
+
eng= Gumdrop::Renderer.for 'markdown'
|
12
|
+
unless eng.nil?
|
13
|
+
eng.new(source).render
|
14
|
+
else
|
15
|
+
raise StandardError, "Markdown is not available: Include a Markdown engine in your Gemfile!"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def textile(source)
|
20
|
+
eng= Gumdrop::Renderer.for 'textile'
|
21
|
+
unless eng.nil?
|
22
|
+
eng.new(source).render
|
23
|
+
else
|
24
|
+
raise StandardError, "Textile is not available: Include a Textile engine in your Gemfile!"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def config
|
29
|
+
site.config
|
30
|
+
end
|
31
|
+
|
32
|
+
def data
|
33
|
+
site.data
|
34
|
+
end
|
35
|
+
|
36
|
+
def gumdrop_version
|
37
|
+
::Gumdrop::VERSION
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
|
45
|
+
def view_helpers(&block)
|
46
|
+
Util::ViewHelpers.class_eval &block
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|