jarrett-quarto 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/quarto/generator.rb +11 -0
- data/lib/quarto/rendering.rb +3 -10
- data/lib/quarto/url_helper.rb +7 -3
- data/quarto.gemspec +2 -2
- data/spec/rendering_spec.rb +0 -7
- data/spec/sample_project/urls.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- data/spec/url_helper_spec.rb +20 -18
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.1
|
data/lib/quarto/generator.rb
CHANGED
@@ -76,6 +76,14 @@ module Quarto
|
|
76
76
|
@console = @options[:console]
|
77
77
|
end
|
78
78
|
|
79
|
+
def self.current_output_file_path
|
80
|
+
@current_output_file_path
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.current_output_file_path=(path)
|
84
|
+
@current_output_file_path = path
|
85
|
+
end
|
86
|
+
|
79
87
|
def urls_file_path # :nodoc:
|
80
88
|
@project_path + '/urls.rb'
|
81
89
|
end
|
@@ -115,17 +123,20 @@ module Quarto
|
|
115
123
|
|
116
124
|
if directory.nil? or directory.empty?
|
117
125
|
path = "#{@output_path}/#{filename}"
|
126
|
+
self.class.current_output_file_path = filename
|
118
127
|
else
|
119
128
|
subdir = "#{@output_path}/#{directory}"
|
120
129
|
if !File.exists? subdir
|
121
130
|
FileUtils::mkdir_p subdir
|
122
131
|
end
|
123
132
|
path = "#{subdir}/#{filename}"
|
133
|
+
self.class.current_output_file_path = "#{directory}/#{filename}"
|
124
134
|
end
|
125
135
|
|
126
136
|
File.open(path, 'w') do |file|
|
127
137
|
file.print render_to_s(template, locals, options)
|
128
138
|
end
|
139
|
+
self.class.current_output_file_path = nil
|
129
140
|
end
|
130
141
|
|
131
142
|
# Renders +template+ to a string. Sets local variables within the template to the values given
|
data/lib/quarto/rendering.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Quarto
|
2
2
|
class Rendering # :nodoc: all
|
3
|
-
def initialize(__erb_template, __locals, __mixins
|
3
|
+
def initialize(__erb_template, __locals, __mixins)
|
4
4
|
unless __erb_template.is_a?(ERB)
|
5
5
|
raise ArgumentError, "Expected ERB but got #{__erb_template.inspect}"
|
6
6
|
end
|
@@ -29,19 +29,12 @@ module Quarto
|
|
29
29
|
end
|
30
30
|
|
31
31
|
@result = __erb_template.result(__b)
|
32
|
-
@output_file_path = __output_file_path
|
33
32
|
end
|
34
33
|
|
35
|
-
def self.render(erb_template, locals, mixins = [],
|
36
|
-
new(erb_template, locals, mixins,
|
34
|
+
def self.render(erb_template, locals, mixins = [], &block)
|
35
|
+
new(erb_template, locals, mixins, &block).result
|
37
36
|
end
|
38
37
|
|
39
38
|
attr_reader :result
|
40
|
-
|
41
|
-
protected
|
42
|
-
|
43
|
-
def output_file_path
|
44
|
-
@output_file_path
|
45
|
-
end
|
46
39
|
end
|
47
40
|
end
|
data/lib/quarto/url_helper.rb
CHANGED
@@ -31,7 +31,12 @@ module Quarto
|
|
31
31
|
# the current output file is in <tt>output/employees</tt>, and you call
|
32
32
|
# <tt>relative_path('images/foo.jpg')</tt>, the result will be <tt>../images/foo.jpg</tt>.
|
33
33
|
def relative_path(path)
|
34
|
-
current_hierarchy =
|
34
|
+
current_hierarchy = Quarto::Generator.current_output_file_path
|
35
|
+
unless current_hierarchy.is_a?(String)
|
36
|
+
raise "Expected Quarto::Generator.current_output_file_path to be a String, but got #{current_hierarchy.inspect}"
|
37
|
+
end
|
38
|
+
current_hierarchy = current_hierarchy.split('/')
|
39
|
+
current_hierarchy.pop # remove the filename
|
35
40
|
target_hierarchy = path.split('/')
|
36
41
|
while current_hierarchy[0] == target_hierarchy[0]
|
37
42
|
current_hierarchy.shift
|
@@ -40,14 +45,13 @@ module Quarto
|
|
40
45
|
rel_path = current_hierarchy.inject('') do |result, dir|
|
41
46
|
result + '../'
|
42
47
|
end
|
43
|
-
#puts target_hierarchy.inspect
|
44
48
|
rel_path << target_hierarchy.join('/')
|
45
49
|
end
|
46
50
|
|
47
51
|
def url_for_with_element_wrapper(options = {})
|
48
52
|
if options.is_a?(Quarto::ElementWrapper::Base)
|
49
53
|
if options.respond_to?(:to_path)
|
50
|
-
return options.to_path
|
54
|
+
return relative_path(options.to_path)
|
51
55
|
else
|
52
56
|
raise "#{options.class} must define to_path if you want to pass an instance into link_to or url_for"
|
53
57
|
end
|
data/quarto.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{quarto}
|
5
|
-
s.version = "1.6.
|
5
|
+
s.version = "1.6.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jarrett Colby"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-22}
|
10
10
|
s.default_executable = %q{quarto}
|
11
11
|
s.description = %q{Quarto is a Ruby framework for generating collections of documents from XML. It steps in where XSLT just won't cut it. Potential applications include web sites and e-books. It's built on top of ERB and REXML.}
|
12
12
|
s.email = %q{jarrett@uchicago.edu}
|
data/spec/rendering_spec.rb
CHANGED
@@ -42,11 +42,4 @@ describe Quarto::Rendering do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
context '#output_file_path' do
|
47
|
-
it 'should return the path' do
|
48
|
-
rendering = Quarto::Rendering.new(ERB.new('foo'), {}, [], 'bar/baz')
|
49
|
-
rendering.send(:output_file_path).should == 'bar/baz'
|
50
|
-
end
|
51
|
-
end
|
52
45
|
end
|
data/spec/sample_project/urls.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/url_helper_spec.rb
CHANGED
@@ -118,12 +118,16 @@ describe Quarto::UrlHelper do
|
|
118
118
|
class TemplateOutsideRails
|
119
119
|
include Quarto::UrlHelper
|
120
120
|
end
|
121
|
+
|
122
|
+
Quarto::Generator.current_output_file_path = ''
|
121
123
|
end
|
122
124
|
|
123
125
|
after :each do
|
124
126
|
Object.class_eval do
|
125
127
|
remove_const :TemplateOutsideRails
|
126
128
|
end
|
129
|
+
|
130
|
+
Quarto::Generator.current_output_file_path = nil
|
127
131
|
end
|
128
132
|
|
129
133
|
it 'should be defined' do
|
@@ -179,6 +183,8 @@ describe Quarto::UrlHelper do
|
|
179
183
|
|
180
184
|
include Quarto::UrlHelper
|
181
185
|
end
|
186
|
+
|
187
|
+
Quarto::Generator.current_output_file_path = ''
|
182
188
|
end
|
183
189
|
|
184
190
|
after :each do
|
@@ -186,6 +192,8 @@ describe Quarto::UrlHelper do
|
|
186
192
|
remove_const :RAILS_GEM_VERSION
|
187
193
|
remove_const :RailsTemplate
|
188
194
|
end
|
195
|
+
|
196
|
+
Quarto::Generator.current_output_file_path = nil
|
189
197
|
end
|
190
198
|
|
191
199
|
it 'should pass the parameter through to the Rails url_for if the parameter is not an ElementWrapper::Base' do
|
@@ -210,12 +218,6 @@ describe Quarto::UrlHelper do
|
|
210
218
|
before :all do
|
211
219
|
class MockRendering
|
212
220
|
include Quarto::UrlHelper
|
213
|
-
|
214
|
-
def initialize(output_file_path)
|
215
|
-
@output_file_path = output_file_path
|
216
|
-
end
|
217
|
-
|
218
|
-
attr_accessor :output_file_path
|
219
221
|
end
|
220
222
|
end
|
221
223
|
|
@@ -225,25 +227,25 @@ describe Quarto::UrlHelper do
|
|
225
227
|
end
|
226
228
|
end
|
227
229
|
|
228
|
-
it 'should call output_file_path' do
|
229
|
-
|
230
|
-
|
230
|
+
it 'should call Generator.output_file_path' do
|
231
|
+
Quarto::Generator.current_output_file_path = 'employees'
|
232
|
+
Quarto::Generator.should_receive(:current_output_file_path).and_return('employees')
|
233
|
+
rendering = MockRendering.new
|
231
234
|
rendering.relative_path('images/foo.jpg')
|
235
|
+
Quarto::Generator.current_output_file_path = nil
|
232
236
|
end
|
233
237
|
|
234
238
|
it 'should derive the correct relative path from output_file_path to the given file' do
|
235
|
-
rendering = MockRendering.new('employees')
|
236
|
-
rendering.relative_path('images/foo.jpg').should == '../images/foo.jpg'
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'should work for complex directory structures' do
|
240
239
|
[
|
241
|
-
['
|
242
|
-
['
|
243
|
-
['a/b/
|
240
|
+
['employees.html', 'images/foo.jpg', 'images/foo.jpg'],
|
241
|
+
['countries/companies/employees.html', 'assets/images/foo.jpg', '../../assets/images/foo.jpg'],
|
242
|
+
['a/b/c/d/e/f/g.html', 'a/b/z.html', '../../../../z.html'],
|
243
|
+
['a/b/y/z.html', 'a/b/c/d/e/f.gif', '../c/d/e/f.gif']
|
244
244
|
].each do |output_file_path, target, expected|
|
245
|
-
|
245
|
+
Quarto::Generator.current_output_file_path = output_file_path
|
246
|
+
rendering = MockRendering.new
|
246
247
|
rendering.relative_path(target).should == expected
|
248
|
+
Quarto::Generator.current_output_file_path = nil
|
247
249
|
end
|
248
250
|
end
|
249
251
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jarrett-quarto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarrett Colby
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-22 00:00:00 -07:00
|
13
13
|
default_executable: quarto
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|