jarrett-quarto 1.1.0 → 1.2.0

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 CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -89,6 +89,7 @@ module Quarto
89
89
  #
90
90
  # * <tt>:xpath</tt> - An XPath expression to limit the search. If this option is not given, the default XPath is "//element_name"
91
91
  def self.find(quantifier, options = {})
92
+ raise 'You must call use_xml() in generate.rb before using the models' if xml_doc.nil?
92
93
  raise ArgumentError, "Quantifier must be :all, :first, or :last, but got #{quantifier.inspect}" unless [:all, :first, :last].include?(quantifier)
93
94
  raise ArgumentError, "Options must be a Hash, but got #{options.inspect}" unless options.is_a?(Hash)
94
95
  if options.has_key?(:xpath)
@@ -73,6 +73,10 @@ module Quarto
73
73
  @console = @options[:console]
74
74
  end
75
75
 
76
+ def urls_file_path # :nodoc:
77
+ @project_path + '/urls.rb'
78
+ end
79
+
76
80
  attr_reader :output_path # :nodoc:
77
81
 
78
82
  protected
@@ -111,7 +115,7 @@ module Quarto
111
115
  else
112
116
  subdir = "#{@output_path}/#{directory}"
113
117
  if !File.exists? subdir
114
- Dir.mkdir subdir
118
+ FileUtils::mkdir_p subdir
115
119
  end
116
120
  path = "#{subdir}/#{filename}"
117
121
  end
@@ -124,9 +128,11 @@ module Quarto
124
128
  # Renders +template+ to a string. Sets local variables within the template to the values given
125
129
  # in +locals+.
126
130
  def render_to_s(template, locals, options = {})
131
+ require urls_file_path
132
+
127
133
  page_template_path = "#{@project_path}/pages/#{template}"
128
134
  page_template = ERB.new(File.read(page_template_path))
129
- page_content = Rendering.render(page_template, locals)
135
+ page_content = Rendering.render(page_template, locals, [Quarto::ProjectUrls])
130
136
 
131
137
  if options.has_key?(:layout)
132
138
  layout = options[:layout]
@@ -141,8 +147,9 @@ module Quarto
141
147
 
142
148
  if layout
143
149
  layout_template_path = "#{@project_path}/layouts/#{layout}"
150
+ raise ArgumentError, "Template doesn't exist: #{layout_template_path}" unless File.exists?(layout_template_path)
144
151
  layout_template = ERB.new(File.read(layout_template_path))
145
- Rendering.render(layout_template, locals) do
152
+ Rendering.render(layout_template, locals, [Quarto::ProjectUrls]) do
146
153
  page_content
147
154
  end
148
155
  else
@@ -13,6 +13,16 @@ Quarto.generate do
13
13
  # e.g.:
14
14
  # render 'companies.html.erb', '', 'companies.html', :companies => Company.find(:all)
15
15
  end
16
+ )
17
+
18
+ STARTER_URLS_FILE = %q(
19
+ module Quarto
20
+ module ProjectUrls
21
+ include Quarto::UrlHelper
22
+
23
+
24
+ end
25
+ end
16
26
  )
17
27
  # Initialize a new Quarto project at the specified path. Creates a generate.rb file and the necessary subfolders.
18
28
  def self.init_project(project_path)
@@ -33,6 +43,12 @@ end
33
43
  file.print(STARTER_GENERATE_FILE)
34
44
  end
35
45
  end
46
+ urls_file = project_path + '/urls.rb'
47
+ unless File.exists?(urls_file)
48
+ File.open(urls_file, 'w') do |file|
49
+ file.print(STARTER_URLS_FILE)
50
+ end
51
+ end
36
52
  true
37
53
  end
38
54
  end
@@ -1,11 +1,31 @@
1
1
  module Quarto
2
2
  class Rendering # :nodoc: all
3
- include UrlHelper
3
+ include Quarto::UrlHelper
4
4
 
5
- def initialize(__erb_template, __locals)
5
+ def initialize(__erb_template, __locals, __mixins)
6
+ unless __erb_template.is_a?(ERB)
7
+ raise ArgumentError, "Expected ERB but got #{__erb_template.inspect}"
8
+ end
9
+
10
+ unless __locals.is_a?(Hash)
11
+ raise ArgumentError, "Expected Hash but got #{__locals.inspect}"
12
+ end
13
+
14
+ unless __mixins.is_a?(Array)
15
+ raise ArgumentError, "Expected Array but got #{__mixins.inspect}"
16
+ end
17
+
18
+ __mixins.each do |mixin|
19
+ unless mixin.is_a?(Module)
20
+ raise ArgumentError, "Expected Module but got #{mixin.inspect}"
21
+ end
22
+ extend(mixin)
23
+ end
24
+
6
25
  __b = binding
26
+
7
27
  __locals.each_key do |var_name|
8
- # In the context of this method (rather than of this block),
28
+ # In the context of the binding (rather than of this block),
9
29
  # define the local variables
10
30
  eval "#{var_name} = __locals[:#{var_name}]", __b
11
31
  end
@@ -13,8 +33,8 @@ module Quarto
13
33
  @result = __erb_template.result(__b)
14
34
  end
15
35
 
16
- def self.render(erb_template, locals, &block)
17
- new(erb_template, locals, &block).result
36
+ def self.render(erb_template, locals, mixins = [], &block)
37
+ new(erb_template, locals, mixins, &block).result
18
38
  end
19
39
 
20
40
  attr_reader :result
@@ -1,10 +1,20 @@
1
1
  require 'cgi'
2
+ require 'uri'
2
3
 
3
4
  module Quarto
4
5
 
5
6
  # This module is included in Generator and thus made available in <tt>generate.rb</tt> files.
6
7
 
7
8
  module UrlHelper
9
+ def self.included(base)
10
+ if defined? RAILS_GEM_VERSION
11
+ base.class_eval do
12
+ alias_method :url_for_without_element_wrapper, :url_for
13
+ alias_method :url_for, :url_for_with_element_wrapper
14
+ end
15
+ end
16
+ end
17
+
8
18
  # Generates an absolute URL, using the <tt>:site_root</tt> config value. (To change <tt>:site_root</tt>,
9
19
  # put something like this in <tt>generate.rb</tt>:
10
20
  # config(:site_root, 'http://your_domain.com/whatever')
@@ -12,9 +22,64 @@ module Quarto
12
22
  "#{Quarto.config[:site_root]}#{str}"
13
23
  end
14
24
 
25
+ def url_for_with_element_wrapper(options = {})
26
+ if options.is_a?(Quarto::ElementWrapper::Base)
27
+ if options.respond_to?(:to_path)
28
+ return options.to_path
29
+ else
30
+ raise "#{options.class} must define to_path if you want to pass an instance into link_to or url_for"
31
+ end
32
+ else
33
+ if defined? RAILS_GEM_VERSION
34
+ return url_for_without_element_wrapper(options)
35
+ else
36
+ raise ArgumentError, "Don\'t know how to generate URL from #{options.inspect}"
37
+ end
38
+ end
39
+ end
40
+
15
41
  # Replaces spaces with dashes and deletes special characters.
16
42
  def urlize(str)
17
43
  str.to_s.gsub(/[^ a-zA-Z0-9_-]/, '').tr(' ', '-')
18
44
  end
45
+
46
+ unless defined? RAILS_GEM_VERSION
47
+ # Similar to Rails' <tt>link_to</tt>, but with less flexibility. Anything you pass to this
48
+ # <tt>link_to</tt> will also work in Rails, but the reverse is not true.
49
+ #
50
+ # This method is only defined if you're not using Quarto within Rails. If you are,
51
+ # the Rails <tt>link_to</tt> will not be overriden by this one. However, you can still pass
52
+ # instances of <tt>ElementWrapper::Base</tt> in, because Quarto patches <tt>url_for</tt> (which is
53
+ # called by Rails' <tt>link_to</tt>).
54
+ #
55
+ # +target+ must be either an instance of <tt>ElementWrapper::Base</tt>, an absolute URL, or
56
+ # a relative URL.
57
+ def link_to(text, target, options = {})
58
+ if !target.is_a?(String) and !target.is_a?(Quarto::ElementWrapper::Base)
59
+ raise ArgumentError, "Expected String or ElementWrapper::Base, but got #{target.inspect}"
60
+ end
61
+ url = url_for(target)
62
+ options = {:html_options => {}}.merge(options)
63
+ output = "<a href=\"#{url}\""
64
+ options[:html_options].each do |attr, value|
65
+ output << " #{attr}=\"#{value}\""
66
+ end
67
+ output + '>' + text + '</a>'
68
+ end
69
+
70
+ # Somewhat compatible with the Rails url_for helper.
71
+ def url_for(options = {})
72
+ if options.is_a?(String)
73
+ uri = URI.parse(options)
74
+ if uri.absolute?
75
+ uri.to_s
76
+ else
77
+ abs_url(uri.to_s)
78
+ end
79
+ else
80
+ url_for_with_element_wrapper(options)
81
+ end
82
+ end
83
+ end
19
84
  end
20
85
  end
data/lib/quarto.rb CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'rexml/document'
5
5
  require 'erb'
6
6
  require 'active_support/inflector'
7
+ require 'fileutils'
7
8
 
8
9
  require 'quarto/config'
9
10
  require 'quarto/xml_doc'
data/quarto.gemspec ADDED
@@ -0,0 +1,72 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{quarto}
5
+ s.version = "1.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jarrett Colby"]
9
+ s.date = %q{2009-06-09}
10
+ s.default_executable = %q{quarto}
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
+ s.email = %q{jarrett@uchicago.edu}
13
+ s.executables = ["quarto"]
14
+ s.extra_rdoc_files = [
15
+ "README"
16
+ ]
17
+ s.files = [
18
+ "README",
19
+ "Rakefile",
20
+ "VERSION",
21
+ "bin/quarto",
22
+ "lib/quarto.rb",
23
+ "lib/quarto/children.rb",
24
+ "lib/quarto/config.rb",
25
+ "lib/quarto/element_wrapper.rb",
26
+ "lib/quarto/generator.rb",
27
+ "lib/quarto/inheritable_attributes.rb",
28
+ "lib/quarto/init_project.rb",
29
+ "lib/quarto/rendering.rb",
30
+ "lib/quarto/url_helper.rb",
31
+ "lib/quarto/xml_doc.rb",
32
+ "quarto.gemspec",
33
+ "test.rb"
34
+ ]
35
+ s.has_rdoc = true
36
+ s.homepage = %q{http://github.com/jarrett/quarto}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.1}
40
+ s.summary = %q{generates HTML or any other format from XML}
41
+ s.test_files = [
42
+ "spec/children_spec.rb",
43
+ "spec/element_wrapper_spec.rb",
44
+ "spec/generator_spec.rb",
45
+ "spec/init_project_spec.rb",
46
+ "spec/matchers/file_matchers.rb",
47
+ "spec/rendering_spec.rb",
48
+ "spec/sample_models.rb",
49
+ "spec/sample_project/generate.rb",
50
+ "spec/sample_project/models/company.rb",
51
+ "spec/sample_project/models/employee.rb",
52
+ "spec/sample_project/models/location.rb",
53
+ "spec/sample_project/models/mascot.rb",
54
+ "spec/sample_project/models/product.rb",
55
+ "spec/sample_project/urls.rb",
56
+ "spec/spec_helper.rb",
57
+ "spec/url_helper_spec.rb"
58
+ ]
59
+
60
+ if s.respond_to? :specification_version then
61
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
+ s.specification_version = 2
63
+
64
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
65
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.2"])
66
+ else
67
+ s.add_dependency(%q<activesupport>, [">= 2.3.2"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<activesupport>, [">= 2.3.2"])
71
+ end
72
+ end
@@ -38,23 +38,6 @@ describe Quarto do
38
38
  end
39
39
  end
40
40
 
41
- module Quarto
42
- # This will be used in the specs below--see the method aliasing
43
- def self.testable_generate(&block)
44
- GenerationTesting.generation_block = block
45
- end
46
-
47
- module GenerationTesting
48
- def self.generation_block
49
- @generation_block
50
- end
51
-
52
- def self.generation_block=(block)
53
- @generation_block = block
54
- end
55
- end
56
- end
57
-
58
41
  describe Quarto::Generator do
59
42
  context '.new' do
60
43
  it 'should accept a path to a project directory' do
@@ -66,32 +49,61 @@ describe Quarto::Generator do
66
49
  include Quarto::UrlHelper
67
50
 
68
51
  before :all do
69
- # Quarto.generate will now return the passed block as a proc
70
- # instead of envoking the whole framework
71
- Quarto.module_eval do
52
+ module Quarto
53
+ def self.testable_generate(&block)
54
+ GenerationTesting.generation_block = block
55
+ end
56
+
57
+ # Quarto.generate will now return the passed block as a proc
58
+ # instead of envoking the whole framework.
59
+ # This would prevent the generation directives from being
60
+ # processed at all, except that below, we call
61
+ # @generator.generate with the saved block
72
62
  class << self
73
-
74
63
  alias_method :untestable_generate, :generate
75
64
  alias_method :generate, :testable_generate
76
65
  end
66
+
67
+ module GenerationTesting
68
+ def self.generation_block
69
+ @generation_block
70
+ end
71
+
72
+ def self.generation_block=(block)
73
+ @generation_block = block
74
+ end
75
+
76
+ def self.last_rendering
77
+ @last_rendering
78
+ end
79
+
80
+ def self.last_rendering=(rendering)
81
+ @last_rendering = rendering
82
+ end
83
+ end
77
84
  end
78
85
 
79
86
  @generator = Quarto::Generator.new(SAMPLE_DIR)
80
87
 
81
- # Clear the directories
88
+ # Clear the directories prior to testing
82
89
  FileUtils.rm_rf @generator.output_path
83
90
 
84
- # Now that we've aliased the methods and load has been called GenerationTesting.generation_block should be set
91
+ # Now that we've aliased the methods and load has been called
92
+ # GenerationTesting.generation_block should be set, so
93
+ # we can execute the generation block.
85
94
  load @generator.generate_file_path
86
95
  @generator.generate(&Quarto::GenerationTesting.generation_block)
87
96
  end
88
97
 
89
98
  after :all do
90
99
  # Reset Quarto.generate to its old behavior
91
- Quarto.module_eval do
100
+ module Quarto
92
101
  class << self
93
102
  alias_method :generate, :untestable_generate
103
+ remove_method :testable_generate
94
104
  end
105
+
106
+ remove_const :GenerationTesting
95
107
  end
96
108
  end
97
109
 
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Quarto::Rendering do
4
+ context '.render' do
5
+ it 'should use the ERB template' do
6
+ template = ERB.new 'foo bar'
7
+ Quarto::Rendering.render(template, {}).should == 'foo bar'
8
+ end
9
+
10
+ it 'should set the local variables' do
11
+ template = ERB.new 'The value of x is <%= x %>.'
12
+ Quarto::Rendering.render(template, {:x => 42}).should == 'The value of x is 42.'
13
+ end
14
+
15
+ it 'should mix in the modules' do
16
+ module SomeMixin
17
+ def foo; 42; end
18
+ end
19
+ template = ERB.new 'SomeMixin#foo returns <%= foo %>.'
20
+ Quarto::Rendering.render(template, {}, [SomeMixin]).should == 'SomeMixin#foo returns 42.'
21
+ Object.class_eval do
22
+ remove_const :SomeMixin
23
+ end
24
+ end
25
+
26
+ it 'should raise ArgumentError if the first parameter is not an ERB template' do
27
+ lambda { Quarto::Rendering.render('foo bar', {}) }.should raise_error(ArgumentError)
28
+ end
29
+
30
+ it 'should raise ArgumentError if the second parameter is not a hash' do
31
+ template = ERB.new 'foo bar'
32
+ lambda { Quarto::Rendering.render(template, [:x, 42]) }.should raise_error(ArgumentError)
33
+ end
34
+
35
+ it 'should raise ArgumentError if the third parameter is not an array of modules' do
36
+ module SomeMixin; end
37
+ template = ERB.new 'foo bar'
38
+ lambda { Quarto::Rendering.render(template, {}, SomeMixin) }.should raise_error(ArgumentError)
39
+ lambda { Quarto::Rendering.render(template, {}, [SomeMixin, 'foo']) }.should raise_error(ArgumentError)
40
+ Object.class_eval do
41
+ remove_const :SomeMixin
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  Quarto.generate do
2
- config(:site_root, 'http://localhost/') # This determines how abs_url works.
2
+ config(:site_root, '') # This determines how abs_url works. If you need your absolute URLs to be prepended with something, you can put it here.
3
3
 
4
4
  use_xml('companies.xml')
5
5
 
@@ -12,4 +12,8 @@ class Company < Quarto::ElementWrapper::Base
12
12
  def competitors
13
13
  @competitors ||= self.class.find(:all, :xpath => "companies/company[industry='#{industry}' and name!='#{name}']")
14
14
  end
15
+
16
+ def to_path
17
+ 'companies.html'
18
+ end
15
19
  end
@@ -1,4 +1,6 @@
1
1
  class Employee < Quarto::ElementWrapper::Base
2
+ include Quarto::UrlHelper
3
+
2
4
  element_attrs :name
3
5
 
4
6
  parent :company
@@ -7,4 +9,8 @@ class Employee < Quarto::ElementWrapper::Base
7
9
  employee = new(el)
8
10
  employee.ivs_from_elements('name')
9
11
  end
12
+
13
+ def to_path
14
+ 'employees/' + urlize(name) + '.html'
15
+ end
10
16
  end
@@ -0,0 +1,9 @@
1
+ module Quarto
2
+ module ProjectUrls
3
+ include Quarto::UrlHelper
4
+
5
+ def companies_url
6
+ abs_url('companies.html')
7
+ end
8
+ end
9
+ end
@@ -12,12 +12,194 @@ describe Quarto::UrlHelper do
12
12
  urlize('John Smith').should == 'John-Smith'
13
13
  end
14
14
 
15
- it 'should not change numbers' do
16
- urlize('a10b').should == 'a10b'
15
+ it 'should not change numbers without decimal points' do
16
+ ['10', '-1', 'a10b'].each do |num|
17
+ urlize(num).should == num
18
+ end
19
+ end
20
+
21
+ it 'should remove the . character' do
22
+ [
23
+ ['foo.bar', 'foobar'],
24
+ ['.foo', 'foo'],
25
+ ['foo.', 'foo'],
26
+ ['10.5', '105']
27
+ ].each do |input, expected|
28
+ urlize(input).should == expected
29
+ end
17
30
  end
18
31
 
19
32
  it 'should not change dashes and underscores' do
20
33
  urlize('foo-bar_baz').should == 'foo-bar_baz'
21
34
  end
22
35
  end
36
+
37
+ context '#link_to' do
38
+ context 'outside Rails' do
39
+ before :each do
40
+ if defined? RAILS_GEM_VERSION
41
+ raise 'RAILS_GEM_VERSION is defined. (It shouldn\'t be when running this spec)'
42
+ end
43
+
44
+ class TemplateOutsideRails
45
+ include Quarto::UrlHelper
46
+ end
47
+ end
48
+
49
+ after :each do
50
+ Object.class_eval do
51
+ remove_const :TemplateOutsideRails
52
+ end
53
+ end
54
+
55
+ it 'should be defined' do
56
+ TemplateOutsideRails.new.should respond_to(:link_to)
57
+ end
58
+
59
+ it 'should call url_for' do
60
+ template = TemplateOutsideRails.new
61
+ template.should_receive(:url_for)
62
+ template.link_to('foo', 'bar')
63
+ end
64
+
65
+ it 'should return an HTML link' do
66
+ expected = '<a href="http://example.com/foo">foo</a>'
67
+ TemplateOutsideRails.new.link_to('foo', 'http://example.com/foo').should == expected
68
+ end
69
+
70
+ it 'should use :html_options' do
71
+ expected = '<a href="http://example.com" onclick="javascript:alert(\'foo\');">Click me</a>'
72
+ template = TemplateOutsideRails.new
73
+ template.link_to(
74
+ 'Click me', 'http://example.com',
75
+ :html_options => {:onclick => 'javascript:alert(\'foo\');'}
76
+ ).should == expected
77
+ end
78
+ end
79
+
80
+ context 'in Rails' do
81
+ it 'should not be redefined if RAILS_GEM_VERSION is defined' do
82
+ RAILS_GEM_VERSION = 'foo'
83
+
84
+ class RailsTemplate
85
+ attr_reader :link_to_called
86
+
87
+ def initialize
88
+ @link_to_called = false
89
+ end
90
+
91
+ def link_to(*args)
92
+ @link_to_called = true
93
+ end
94
+
95
+ include Quarto::UrlHelper
96
+ end
97
+
98
+ template = RailsTemplate.new
99
+ template.link_to('bar')
100
+ template.link_to_called.should == true
101
+
102
+ Object.class_eval do
103
+ remove_const :RailsTemplate
104
+ remove_const :RAILS_GEM_VERSION
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ context '#url_for' do
111
+ context 'outside Rails' do
112
+ before :each do
113
+ if defined? RAILS_GEM_VERSION
114
+ raise 'RAILS_GEM_VERSION is defined. (It shouldn\'t be when running this spec)'
115
+ end
116
+
117
+ class TemplateOutsideRails
118
+ include Quarto::UrlHelper
119
+ end
120
+ end
121
+
122
+ after :each do
123
+ Object.class_eval do
124
+ remove_const :TemplateOutsideRails
125
+ end
126
+ end
127
+
128
+ it 'should be defined' do
129
+ TemplateOutsideRails.new.should respond_to(:url_for)
130
+ end
131
+
132
+ it 'should raise ArgumentError if anything other than a string or an instance of ElementWrapper::Base is passed to it' do
133
+ class MockWrapper
134
+ def is_a?(klass); Quarto::ElementWrapper::Base == klass; end
135
+ def to_path; 'foo'; end;
136
+ end
137
+ TemplateOutsideRails.new.url_for('foo')
138
+ TemplateOutsideRails.new.url_for(MockWrapper.new)
139
+ [1, 0.1, Date.new, URI.parse('http://foo.com')].each do |obj|
140
+ lambda { TemplateOutsideRails.new.url_for(obj) }.should raise_error(ArgumentError)
141
+ end
142
+ Object.class_eval do
143
+ remove_const :MockWrapper
144
+ end
145
+ end
146
+
147
+ it 'should call abs_url if the parameter is a relative URL' do
148
+ ['foo', '/foo'].each do |rel_url|
149
+ template = TemplateOutsideRails.new
150
+ template.should_receive(:abs_url).with(rel_url)
151
+ template.url_for(rel_url)
152
+ end
153
+ end
154
+
155
+ it 'should not modify an absolute url' do
156
+ ['http://example.com', 'http://example.com/foo', 'https://example.com', 'ftp://example.com'].each do |url|
157
+ TemplateOutsideRails.new.url_for(url).should == url
158
+ end
159
+ end
160
+ end
161
+
162
+ context 'in Rails' do
163
+ before :each do
164
+ RAILS_GEM_VERSION = 'foo'
165
+
166
+ class RailsTemplate
167
+ attr_reader :url_for_called
168
+
169
+ def initialize
170
+ @url_for_called = false
171
+ end
172
+
173
+ def url_for(options = {})
174
+ @url_for_called = true
175
+ end
176
+
177
+ include Quarto::UrlHelper
178
+ end
179
+ end
180
+
181
+ after :each do
182
+ Object.class_eval do
183
+ remove_const :RAILS_GEM_VERSION
184
+ remove_const :RailsTemplate
185
+ end
186
+ end
187
+
188
+ it 'should pass the parameter through to the Rails url_for if the parameter is not an ElementWrapper::Base' do
189
+ template = RailsTemplate.new
190
+ template.url_for('bar')
191
+ template.url_for_called.should == true
192
+ end
193
+
194
+ it 'should call to_path if the parameter is an ElementWrapper::Base and RAILS_GEM_VERSION is defined' do
195
+ wrapper = mock
196
+ wrapper.stub!(:to_path).and_return('some_path')
197
+ wrapper.stub!(:is_a?).and_return(true)
198
+ wrapper.should_receive(:is_a?).with(Quarto::ElementWrapper::Base).and_return(true)
199
+ wrapper.should_receive(:to_path)
200
+ template = RailsTemplate.new
201
+ template.url_for(wrapper).should == 'some_path'
202
+ end
203
+ end
204
+ end
23
205
  end
data/test.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'erb'
2
+
3
+ module Foo
4
+ def foo
5
+ 6
6
+ end
7
+ end
8
+
9
+ template = ERB.new %q(
10
+ The value of x is <%= x %>
11
+ The method foo returns <%= foo %>
12
+ )
13
+ x = 42
14
+
15
+ b = binding
16
+
17
+ eval 'include Foo', b
18
+
19
+ template.extend(Foo)
20
+ puts template.result(b)
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.1.0
4
+ version: 1.2.0
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-06 00:00:00 -07:00
12
+ date: 2009-06-09 00:00:00 -07:00
13
13
  default_executable: quarto
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,7 +45,9 @@ files:
45
45
  - lib/quarto/rendering.rb
46
46
  - lib/quarto/url_helper.rb
47
47
  - lib/quarto/xml_doc.rb
48
- has_rdoc: false
48
+ - quarto.gemspec
49
+ - test.rb
50
+ has_rdoc: true
49
51
  homepage: http://github.com/jarrett/quarto
50
52
  post_install_message:
51
53
  rdoc_options:
@@ -69,7 +71,7 @@ requirements: []
69
71
  rubyforge_project:
70
72
  rubygems_version: 1.2.0
71
73
  signing_key:
72
- specification_version: 3
74
+ specification_version: 2
73
75
  summary: generates HTML or any other format from XML
74
76
  test_files:
75
77
  - spec/children_spec.rb
@@ -77,6 +79,7 @@ test_files:
77
79
  - spec/generator_spec.rb
78
80
  - spec/init_project_spec.rb
79
81
  - spec/matchers/file_matchers.rb
82
+ - spec/rendering_spec.rb
80
83
  - spec/sample_models.rb
81
84
  - spec/sample_project/generate.rb
82
85
  - spec/sample_project/models/company.rb
@@ -84,5 +87,6 @@ test_files:
84
87
  - spec/sample_project/models/location.rb
85
88
  - spec/sample_project/models/mascot.rb
86
89
  - spec/sample_project/models/product.rb
90
+ - spec/sample_project/urls.rb
87
91
  - spec/spec_helper.rb
88
92
  - spec/url_helper_spec.rb