gumdrop 0.7.3.1 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ # v0.7.4
2
+ - All rendered content (including layouts) will relativize paths starting with / on href="" and src="" for html files. Can be set to array of file exts to process at `config.relative_paths_for= ['.html']` or sett to process all files `config.relative_paths_for= :all` or turned off entirely by `config.relative_paths= false`
3
+ - Proxy server is disabled by default. Enable it `configure.proxy = true`
4
+
1
5
  # v0.7.3
2
6
  - Bugfix: Correctly runs content through multiple processors (when multiple are specified in the filename. ie: test.js.erb.coffee gets sent through CoffeeScript then erb)
3
7
 
@@ -2,6 +2,8 @@
2
2
  module Gumdrop
3
3
 
4
4
  class Content
5
+
6
+ MUNGABLE_RE= Regexp.new(%Q<(href|data|src)([\s]*)=([\s]*)('|"|&quot;|&#34;|&#39;)?\\/([\\/]?)>, 'i')
5
7
 
6
8
  attr_accessor :path,
7
9
  :level,
@@ -53,7 +55,7 @@ module Gumdrop
53
55
  content = layout.template.render(context, content:content) { content }
54
56
  layout= context.get_template()
55
57
  end
56
- content
58
+ relativize content, context
57
59
  end
58
60
 
59
61
  def renderTo(context, output_path, filters=[], opts={})
@@ -149,6 +151,22 @@ module Gumdrop
149
151
  uri
150
152
  end
151
153
  end
154
+
155
+ def relativize(content, ctx)
156
+ if site.config.relative_paths
157
+ if site.config.relative_paths_for == :all or site.config.relative_paths_for.include?(@ext)
158
+ path_to_root= ctx.path_to_root
159
+ content = content.gsub MUNGABLE_RE do |match|
160
+ if $5 == '/'
161
+ "#{ $1 }#{ $2 }=#{ $3 }#{ $4 }/"
162
+ else
163
+ "#{ $1 }#{ $2 }=#{ $3 }#{ $4 }#{ path_to_root }"
164
+ end
165
+ end
166
+ end
167
+ end
168
+ content
169
+ end
152
170
 
153
171
  end
154
172
 
@@ -14,9 +14,9 @@ module Gumdrop
14
14
  def uri(path, opts={})
15
15
  path= path[1..-1] if path.starts_with?('/') # and path != "/"
16
16
  uri_string= if !@site.config.relative_paths or force_absolute
17
- "/#{path}"
17
+ "/#{ path }"
18
18
  else
19
- "#{'../'*@state['current_depth']}#{path}"
19
+ "#{ path_to_root }#{ path }"
20
20
  end
21
21
  if opts[:fresh] and @site.node_tree.has_key?(path)
22
22
  uri_string += "?v=#{ @site.node_tree[path].mtime.to_i }"
@@ -24,6 +24,10 @@ module Gumdrop
24
24
  uri_string = "/" if uri_string == ""
25
25
  uri_string
26
26
  end
27
+
28
+ def path_to_root
29
+ '../' * @state['current_depth']
30
+ end
27
31
 
28
32
  def url(path)
29
33
  path= path[1..-1] if path.starts_with?('/')
@@ -4,7 +4,8 @@ module Gumdrop
4
4
 
5
5
  DEFAULT_OPTIONS= {
6
6
  relative_paths: true,
7
- proxy_enabled: true,
7
+ relative_paths_for: ['.html', '.htm', '.php'],
8
+ proxy_enabled: false,
8
9
  output_dir: "./output",
9
10
  source_dir: "./source",
10
11
  data_dir: './data',
@@ -1,5 +1,5 @@
1
1
  module Gumdrop
2
2
 
3
- VERSION = "0.7.3.1" unless defined?(::Gumdrop::VERSION)
3
+ VERSION = "0.7.4" unless defined?(::Gumdrop::VERSION)
4
4
 
5
5
  end
@@ -1,6 +1,20 @@
1
1
  require 'minitest/spec'
2
2
  require 'minitest/autorun'
3
3
  require 'gumdrop'
4
+ #require File.join File.dirname(__FILE__), 'diff.rb'
5
+
6
+ fixture_src_path= File.join ".", "specs", "fixtures", "source"
7
+ fixture_exp_path= File.join ".", "specs", "fixtures", "expected"
8
+
9
+ def get_test_site
10
+ site= Gumdrop::Site.new File.join(".", "specs", "fixtures", "source", 'Gumdrop'), :quiet=>true
11
+ site.rescan
12
+ end
13
+
14
+ def get_expected(filename)
15
+ path= File.join ".", "specs", "fixtures", "expected", filename
16
+ File.read path
17
+ end
4
18
 
5
19
  describe Gumdrop::Content do
6
20
  # before do
@@ -9,13 +23,15 @@ describe Gumdrop::Content do
9
23
 
10
24
  it "should process the content through all the engines specified in the file ext" do
11
25
 
12
- path= File.join ".", "specs", "fixtures", 'Gumdrop'
13
- site= Gumdrop::Site.new path
26
+ # path= File.join fixture_src_path, 'Gumdrop'
27
+ # site= Gumdrop::Site.new path, :quiet=>true
28
+ # site.rescan
29
+ site= get_test_site
14
30
 
15
- path= File.join ".", "specs", "fixtures", 'test.js.erb.coffee'
31
+ path= File.join fixture_src_path, 'test.js.erb.coffee'
16
32
  content= Gumdrop::Content.new( path, site )
17
33
 
18
- path= File.join ".", "specs", "fixtures", 'expected-test.js'
34
+ path= File.join fixture_exp_path, 'test.js'
19
35
  expected= File.read path
20
36
 
21
37
  content= content.render()
@@ -24,7 +40,32 @@ describe Gumdrop::Content do
24
40
  # puts expected
25
41
 
26
42
  content.must_equal expected
43
+ end
27
44
 
45
+ it "should relativize all absolute paths (when starts with /)" do
46
+ site= get_test_site
47
+ # puts site.node_tree.keys
48
+
49
+ page= site.contents('posts/post1.html').first
50
+ content= page.render
51
+ expected= get_expected('posts/post1.html')
52
+ # puts content
53
+ content.must_equal expected
54
+
55
+ page= site.contents('posts/post1.js').first
56
+ content= page.render
57
+ # puts content
58
+ content.must_equal get_expected('posts/post1.js')
59
+
60
+ page= site.contents('sub/sub/sub/test.html').first
61
+ content= page.render
62
+ # puts content
63
+ content.must_equal get_expected('sub/sub/sub/test.html')
64
+
65
+ page= site.contents('sub/sub/sub/test2.html').first
66
+ content= page.render
67
+ # puts content
68
+ content.must_equal get_expected('sub/sub/sub/test2.html')
28
69
  end
29
70
 
30
71
  # it "can be created with no arguments" do
@@ -0,0 +1 @@
1
+ <h1>My First Post</h1><img src="../media/crap.png" /><p>Go to <a href="../about/hell">Hell</a></p>
@@ -0,0 +1,14 @@
1
+ (function() {
2
+ var Test;
3
+
4
+ Test = (function() {
5
+
6
+ function Test() {
7
+ this.img = $('<img src="../media/my-images.png">');
8
+ }
9
+
10
+ return Test;
11
+
12
+ })();
13
+
14
+ }).call(this);
@@ -0,0 +1,5 @@
1
+ <h1>My Second Post</h2>
2
+ <div>
3
+ <a href="../about/site">About the site</a>
4
+ <a href="../about/site"><img src="../media/logo.png"/></a>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ <h1>My Second Post</h2>
2
+ <div>
3
+ <a href="../../../about/site">About the site</a>
4
+ <a href="../../../about/site"><img src="../../../media/logo.png"/></a>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ <h1>My Second Post</h2>
2
+ <div>
3
+ <a href="../../../about/site">About the site</a>
4
+ <a href="../../../about/site"><img src="../../../media/logo.png"/></a>
5
+ </div>
@@ -0,0 +1,13 @@
1
+ require 'slim'
2
+
3
+ configure do
4
+
5
+ set :site_title, "Test"
6
+ set :site_tagline, "a test site"
7
+
8
+ set :source_dir, "./"
9
+
10
+ # set :relative_paths_for, ['.html']
11
+ # set :relative_paths_for, :all #default
12
+
13
+ end
@@ -0,0 +1,6 @@
1
+ h1 My First Post
2
+
3
+ img src="/media/crap.png"
4
+
5
+ markdown:
6
+ Go to [Hell](/about/hell)
@@ -0,0 +1,3 @@
1
+ class Test
2
+ constructor: ->
3
+ @img= $('<img src="/media/my-images.png">')
@@ -0,0 +1,5 @@
1
+ <h1>My Second Post</h2>
2
+ <div>
3
+ <a href="/about/site">About the site</a>
4
+ <a href="/about/site"><img src="/media/logo.png"/></a>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ <h1>My Second Post</h2>
2
+ <div>
3
+ <a href="/about/site">About the site</a>
4
+ <a href="/about/site"><img src="/media/logo.png"/></a>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ <h1>My Second Post</h2>
2
+ <div>
3
+ <a href="/about/site">About the site</a>
4
+ <a href="/about/site"><img src="/media/logo.png"/></a>
5
+ </div>
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 3
9
- - 1
10
- version: 0.7.3.1
8
+ - 4
9
+ version: 0.7.4
11
10
  platform: ruby
12
11
  authors:
13
12
  - Matt McCray
@@ -130,10 +129,20 @@ files:
130
129
  - lib/gumdrop/view_helpers.rb
131
130
  - specs/content_spec.rb
132
131
  - specs/deferred_loader_spec.rb
133
- - specs/fixtures/Gumdrop
134
- - specs/fixtures/expected-test.js
135
- - specs/fixtures/test.js.coffee
136
- - specs/fixtures/test.js.erb.coffee
132
+ - specs/fixtures/expected/posts/post1.html
133
+ - specs/fixtures/expected/posts/post1.js
134
+ - specs/fixtures/expected/posts/post2.html
135
+ - specs/fixtures/expected/sub/sub/sub/test.html
136
+ - specs/fixtures/expected/sub/sub/sub/test2.html
137
+ - specs/fixtures/expected/test.js
138
+ - specs/fixtures/source/Gumdrop
139
+ - specs/fixtures/source/posts/post1.html.slim
140
+ - specs/fixtures/source/posts/post1.js.coffee
141
+ - specs/fixtures/source/posts/post2.html.erb
142
+ - specs/fixtures/source/sub/sub/sub/test.html
143
+ - specs/fixtures/source/sub/sub/sub/test2.html.erb
144
+ - specs/fixtures/source/test.js.coffee
145
+ - specs/fixtures/source/test.js.erb.coffee
137
146
  - specs/hash_object_spec.rb
138
147
  - templates/backbone/Gemfile
139
148
  - templates/backbone/Gumdrop
File without changes