staticmatic 0.8.10 → 0.9.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.
@@ -8,16 +8,154 @@ class HelpersTest < Test::Unit::TestCase
8
8
  def setup
9
9
  @staticmatic = StaticMatic::Base.new(File.dirname(__FILE__) + '/sandbox/test_site')
10
10
  end
11
-
11
+
12
+ # Stylesheets tests
12
13
  def test_should_generate_stylesheet_links
13
- assert_match "href=\"/stylesheets\/application.css\"", stylesheets
14
+ set_current_page("/index.html")
15
+ expected_output = %q{<link href="stylesheets/application.css" media="all"}
16
+ assert_match expected_output, stylesheets
17
+
18
+ expected_output = %q{<link href="stylesheets/application.css" media="print"}
19
+ assert_match expected_output, stylesheets(:media => :print)
20
+
21
+ expected_output = %q{<link href="stylesheets/application.css" media="all"}
22
+ assert_match expected_output, stylesheets(:application)
23
+
24
+ expected_output = %q{<link href="stylesheets/application.css" media="print"}
25
+ assert_match expected_output, stylesheets(:application, :media => :print)
26
+
27
+ set_current_page("/subdir/index.html")
28
+ expected_output = %q{<link href="../stylesheets/application.css"}
29
+ assert_match expected_output, stylesheets
30
+
31
+ set_current_page("/subdir/other/index.html")
32
+ expected_output = %q{<link href="../../stylesheets/application.css"}
33
+ assert_match expected_output, stylesheets
14
34
  end
15
35
 
36
+ # Link tests
16
37
  def test_should_autolink_page
17
- expected_output = %q{<a href="/test.html">Test</a>}
38
+ set_current_page("/index.html")
39
+ expected_output = %q{<a href="test.html">Test</a>}
40
+ assert_match expected_output, link("Test")
41
+
42
+ set_current_page("/subdir/index.html")
43
+ expected_output = %q{<a href="../test.html">Test</a>}
44
+ assert_match expected_output, link("Test")
45
+
46
+ set_current_page("/subdir/other/index.html")
47
+ expected_output = %q{<a href="../../test.html">Test</a>}
18
48
  assert_match expected_output, link("Test")
19
49
  end
20
-
50
+
51
+ def test_should_not_change_url_with_protocol
52
+ expected_output = %q{<a href="mailto:joe@mailinator.com">Email Joe</a>}
53
+ assert_match expected_output, link("Email Joe", "mailto:joe@mailinator.com")
54
+
55
+ %w(http https ftp gopher ssh telnet).each do |protocol|
56
+ expected_output = "<a href=\"#{protocol}://www.google.com\">Google</a>"
57
+ assert_match expected_output, link("Google", "#{protocol}://www.google.com")
58
+ end
59
+ end
60
+
61
+ def test_should_not_change_url_with_existing_relative_path
62
+ ['/index.html', '/subdir/index.html', '/subdir/other/index.html'].each do |the_current_page|
63
+ set_current_page(the_current_page)
64
+
65
+ ['/foo.html', './foo.html', '../other/foo.html'].each do |the_path|
66
+ expected_output = "<a href=\"#{the_path}\">Foo</a>"
67
+ assert_match expected_output, link("Foo", the_path)
68
+ end
69
+ end
70
+ end
71
+
72
+ def test_should_not_change_anchor_url
73
+ ['/index.html', '/subdir/index.html', '/subdir/other.html'].each do |the_current_page|
74
+ set_current_page(the_current_page)
75
+
76
+ expected_output = %q{<a href="#myanchor">Foo</a>}
77
+ assert_match expected_output, link("Foo", "#myanchor")
78
+ end
79
+ end
80
+
81
+ def test_should_strip_html_extension_from_page_links
82
+ @staticmatic.configuration.use_extensions_for_page_links = false
83
+
84
+ set_current_page("/index.html")
85
+ expected_output = %q{<a href="other">Other</a>}
86
+ assert_match expected_output, link("Other")
87
+
88
+ set_current_page("/subdir/index.html")
89
+ expected_output = %q{<a href="../other">Other</a>}
90
+ assert_match expected_output, link("Other")
91
+
92
+ set_current_page("/subdir/other/index.html")
93
+ expected_output = %q{<a href="../../other">Other</a>}
94
+ assert_match expected_output, link("Other")
95
+
96
+ set_current_page("/index.html")
97
+ expected_output = %q{<a href="/other">Other</a>}
98
+ assert_match expected_output, link("Other", "/other.html")
99
+
100
+ expected_output = %q{<a href="/foo/">Foo</a>}
101
+ assert_match expected_output, link("Foo", "/foo/index.html")
102
+
103
+ expected_output = %q{<a href="/">Home</a>}
104
+ assert_match expected_output, link("Home", "/")
105
+ end
106
+
107
+ def test_should_not_strip_extension_from_non_page_links
108
+ @staticmatic.configuration.use_extensions_for_page_links = false
109
+
110
+ set_current_page("/index.html")
111
+ expected_output = %q{<a href="other.zip">Other</a>}
112
+ assert_match expected_output, link("Other", "other.zip")
113
+
114
+ set_current_page("/subdir/index.html")
115
+ expected_output = %q{<a href="../other.zip">Other</a>}
116
+ assert_match expected_output, link("Other", "other.zip")
117
+
118
+ set_current_page("/subdir/other/index.html")
119
+ expected_output = %q{<a href="../../other.zip">Other</a>}
120
+ assert_match expected_output, link("Other", "other.zip")
121
+
122
+ set_current_page("/index.html")
123
+ expected_output = %q{<a href="/other.zip">Other</a>}
124
+ assert_match expected_output, link("Other", "/other.zip")
125
+
126
+ expected_output = %q{<a href="http://www.google.com/index.html">Google</a>}
127
+ assert_match expected_output, link("Google", "http://www.google.com/index.html")
128
+ end
129
+
130
+ def test_should_prefix_relative_path_while_generating_file_name
131
+ ['/other.html', '/subdir/index.html', '/subdir/other/filename.html'].each do |the_current_page|
132
+ set_current_page(the_current_page)
133
+
134
+ ['Other', 'Other File', 'Other / File', 'Other /File/'].each do |link_name|
135
+ ['../', './', '/', '/foo/','../bar/'].each do |relative_path|
136
+ expected_output = %Q{<a href="#{relative_path}#{urlify(link_name)}.html">#{link_name}</a>}
137
+ assert_match expected_output, link("#{relative_path}#{link_name}")
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ def test_should_not_prefix_relative_path_while_generating_file_name
144
+ set_current_page("/other.html")
145
+
146
+ expected_output = %q{<a href="testlink.html">Test/Link</a>}
147
+ assert_match expected_output, link('Test/Link')
148
+
149
+ set_current_page("/subdir/index.html")
150
+ expected_output = %q{<a href="../testlink.html">Test/Link</a>}
151
+ assert_match expected_output, link('Test/Link')
152
+
153
+ set_current_page("/subdir/other/filename.html")
154
+ expected_output = %q{<a href="../../testlink.html">Test/Link</a>}
155
+ assert_match expected_output, link('Test/Link')
156
+ end
157
+
158
+ # Tag tests
21
159
  def test_should_generate_tag_with_block
22
160
  expected_output = %q{<a href="/test.html" title="My Test Link">Test</a>}
23
161
  assert_match expected_output, tag(:a, :href => "/test.html", :title => 'My Test Link') { "Test" }
@@ -28,64 +166,119 @@ class HelpersTest < Test::Unit::TestCase
28
166
  assert_match expected_output, tag(:br)
29
167
  end
30
168
 
169
+ # Urlify tests
31
170
  def test_should_urlify_string
32
171
  assert_equal "stephens_haml_and_sass_project", urlify("Stephen's Haml & Sass Project")
172
+ assert_equal "testlink", urlify("Test/Link")
33
173
  end
34
174
 
175
+ # Text_field tests
35
176
  def test_should_generate_input
36
177
  expected_output = %q{<input type="text" value="blah" name="test"/>}
37
178
  assert_tags_match expected_output, text_field("test", "blah")
38
179
  end
39
-
180
+
181
+ # Javascripts tests
40
182
  def test_should_generate_js_links
41
- expected_output = %q{src="/javascripts/test.js"}
183
+ set_current_page('/index.html')
184
+ expected_output = %q{src="javascripts/test.js"}
185
+ assert_match expected_output, javascripts('test')
186
+
187
+ expected_output = %q{src="javascripts/test.js"}
188
+ assert_match expected_output, javascripts(:test)
189
+
190
+ set_current_page('/subdir/index.html')
191
+ expected_output = %q{src="../javascripts/test.js"}
192
+ assert_match expected_output, javascripts('test')
193
+
194
+ set_current_page('/subdir/other/index.html')
195
+ expected_output = %q{src="../../javascripts/test.js"}
42
196
  assert_match expected_output, javascripts('test')
43
197
  end
198
+
199
+ def test_should_not_change_js_link_with_existing_relative_url
200
+ ['/index.html', '/subdir/index.html', '/subdir/other/index.html'].each do |the_current_page|
201
+ set_current_page(the_current_page)
202
+
203
+ ['/my_javascript.js', './my_javascript.js', '../other/my_javascript.js'].each do |the_path|
204
+ expected_output = "src=\"#{the_path}\""
205
+ assert_match expected_output, javascripts(the_path)
206
+ end
207
+ end
208
+ end
209
+
210
+ def test_should_generate_absolute_js_link
211
+ ['/index.html', '/subdir/index.html', '/subdir/other/foo.html'].each do |the_current_page|
212
+ set_current_page(the_current_page)
213
+
214
+ ['http://staticmatic.rubyforge.org/javascripts/test.js', 'https://staticmatic.rubyforge.org/javascripts/test.js'].each do |the_path|
215
+ expected_output = "src=\"#{the_path}\""
216
+ assert_match expected_output, javascripts(the_path)
217
+ end
218
+ end
219
+ end
44
220
 
45
- # Soon...
221
+ # Partials tests
46
222
  def test_should_include_partial_template
223
+ @staticmatic.instance_eval { def current_file() "/index.haml"; end }
224
+ set_current_page("/index.html")
47
225
  expected_output = "My Menu"
48
- # TODO: make this pass again - current_file is nil because this is not called in the framework
49
- # assert_match expected_output, partial("menu")
50
- assert true
226
+ assert_match expected_output, partial("menu")
51
227
  end
52
228
 
53
- # Image tag tests
229
+ # Image tests
54
230
  def test_should_generate_basic_img_tag
55
- expected_output = %q{<img src="/images/test.gif" alt="Test"/>}
231
+ set_current_page("/index.html")
232
+ expected_output = %q{<img src="images/test.gif" alt="Test"/>}
233
+ assert_tags_match expected_output, img('test.gif')
234
+
235
+ set_current_page("/subdir/index.html")
236
+ expected_output = %q{<img src="../images/test.gif" alt="Test"/>}
237
+ assert_tags_match expected_output, img('test.gif')
238
+
239
+ set_current_page("/subdir/other/index.html")
240
+ expected_output = %q{<img src="../../images/test.gif" alt="Test"/>}
56
241
  assert_tags_match expected_output, img('test.gif')
57
242
  end
58
243
 
59
244
  def test_should_generate_img_tag_with_options
60
- expected_output = %q{<img src="/images/test.gif" alt="Testing the alt" class="testClass"/>}
245
+ set_current_page("/index.html")
246
+ expected_output = %q{<img src="images/test.gif" alt="Testing the alt" class="testClass"/>}
61
247
  assert_tags_match expected_output, img('test.gif', {:alt => 'Testing the alt', :class => 'testClass'})
62
248
  end
63
249
 
64
250
  def test_should_generate_img_tag_with_sub_directory
65
- expected_output = %q{<img src="/images/about_us/test.gif" alt="Test"/>}
251
+ set_current_page("/index.html")
252
+ expected_output = %q{<img src="images/about_us/test.gif" alt="Test"/>}
66
253
  assert_tags_match expected_output, img('about_us/test.gif')
67
254
  end
68
255
 
69
256
  def test_should_generate_img_tag_with_src_left_as_is
70
- expected_output = %q{<img src="/images/test_image.gif" alt="Test image"/>}
71
- assert_tags_match expected_output, img('/images/test_image.gif')
257
+ ['/index.html', '/subdir/index.html', '/subdir/other/index.html'].each do |the_current_page|
258
+ set_current_page(the_current_page)
259
+
260
+ ['/images/test_image.gif', './test_image.gif', '../test_image.gif'].each do |the_path|
261
+ expected_output = "<img src=\"#{the_path}\" alt=\"Test image\"/>"
262
+ assert_tags_match expected_output, img(the_path)
263
+ end
264
+ end
72
265
  end
73
266
 
74
267
  def test_should_generate_absolute_img_tag
75
- expected_output = %q{<img src="http://staticmatic.rubyforge.org/images/bycurve21.gif" alt="Bycurve21"/>}
76
- assert_tags_match expected_output, img('http://staticmatic.rubyforge.org/images/bycurve21.gif')
268
+ ['/index.html', '/subdir/foo.html', '/subdir/other/index.html'].each do |the_current_page|
269
+ set_current_page(the_current_page)
270
+
271
+ ['http://staticmatic.rubyforge.org/images/bycurve21.gif', 'https://staticmatic.rubyforge.org/images/bycurve21.gif'].each do |the_path|
272
+ expected_output = "<img src=\"#{the_path}\" alt=\"Bycurve21\"/>"
273
+ assert_tags_match expected_output, img(the_path)
274
+ end
275
+ end
77
276
  end
78
277
 
79
- def test_should_generate_relative_img_tag_based_on_config
80
- @staticmatic.configuration.use_relative_paths_for_images = true
81
- expected_output = %q{<img src="images/test.gif" alt="Test"/>}
82
- assert_tags_match expected_output, img('test.gif')
83
- end
278
+ private
84
279
 
85
- def test_should_generate_absolute_img_tag_regardles_of_config
86
- @staticmatic.configuration.use_relative_paths_for_images = true
87
- expected_output = %q{<img src="http://staticmatic.rubyforge.org/images/bycurve21.gif" alt="Bycurve21"/>}
88
- assert_tags_match expected_output, img('http://staticmatic.rubyforge.org/images/bycurve21.gif')
280
+ def set_current_page(page)
281
+ @staticmatic.instance_variable_set("@current_page", page)
89
282
  end
90
283
 
91
284
  end
@@ -0,0 +1,26 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/staticmatic'
3
+
4
+ class StaticMaticVersionTest < Test::Unit::TestCase
5
+ def setup
6
+ @base_dir = File.dirname(__FILE__) + '/sandbox/tmp'
7
+ end
8
+
9
+ def test_version_requirements_met
10
+ assert_equal false, StaticMatic::VERSION.requirements_met?("#{StaticMatic::VERSION::MAJOR+1}.0.0")
11
+ assert_equal false, StaticMatic::VERSION.requirements_met?("#{StaticMatic::VERSION::MAJOR}.#{StaticMatic::VERSION::MINOR+1}.0")
12
+ assert_equal false, StaticMatic::VERSION.requirements_met?("#{StaticMatic::VERSION::MAJOR}.#{StaticMatic::VERSION::MINOR}.#{StaticMatic::VERSION::TINY+1}")
13
+ assert_equal true, StaticMatic::VERSION.requirements_met?("#{StaticMatic::VERSION::MAJOR-1}.9999.9999")
14
+ assert_equal true, StaticMatic::VERSION.requirements_met?("#{StaticMatic::VERSION::MAJOR}.#{StaticMatic::VERSION::MINOR-1}.9999")
15
+ assert_equal true, StaticMatic::VERSION.requirements_met?("#{StaticMatic::VERSION::MAJOR}.#{StaticMatic::VERSION::MINOR}.#{StaticMatic::VERSION::TINY-1}")
16
+ assert_equal true, StaticMatic::VERSION.requirements_met?("#{StaticMatic::VERSION::MAJOR}.#{StaticMatic::VERSION::MINOR}.#{StaticMatic::VERSION::TINY}")
17
+
18
+ assert_equal false, StaticMatic::VERSION.requirements_met?(:major => StaticMatic::VERSION::MAJOR+1)
19
+ assert_equal false, StaticMatic::VERSION.requirements_met?(:major => StaticMatic::VERSION::MAJOR, :minor => StaticMatic::VERSION::MINOR+1)
20
+ assert_equal false, StaticMatic::VERSION.requirements_met?(:major => StaticMatic::VERSION::MAJOR, :minor => StaticMatic::VERSION::MINOR, :tiny => StaticMatic::VERSION::TINY+1)
21
+ assert_equal true, StaticMatic::VERSION.requirements_met?(:major => StaticMatic::VERSION::MAJOR-1, :minor => 9999, :tiny => 9999)
22
+ assert_equal true, StaticMatic::VERSION.requirements_met?(:major => StaticMatic::VERSION::MAJOR, :minor => StaticMatic::VERSION::MINOR-1, :tiny => 9999)
23
+ assert_equal true, StaticMatic::VERSION.requirements_met?(:major => StaticMatic::VERSION::MAJOR, :minor => StaticMatic::VERSION::MINOR, :tiny => StaticMatic::VERSION::TINY-1)
24
+ assert_equal true, StaticMatic::VERSION.requirements_met?(:major => StaticMatic::VERSION::MAJOR, :minor => StaticMatic::VERSION::MINOR, :tiny => StaticMatic::VERSION::TINY)
25
+ end
26
+ end
@@ -1,78 +1,84 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
3
- <head>
4
- <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
5
- <title>StaticMatic</title>
6
- <link media="all" href="/stylesheets/application.css" rel="stylesheet"/>
7
- </head>
8
- <body>
9
- <div id='container'>
10
- <div id='header'>
11
- <div class='bycurve21'>
12
- <a href="http://www.curve21.com"><img alt="/images/bycurve21" src="/images/bycurve21.gif"/>
13
- </a>
14
- </div>
15
- <div class='title'>StaticMatic</div>
16
- </div>
17
- <div id='menu'>
18
- <ul>
19
- <li><a href="/">Home</a></li>
20
- <li><a href="/download.html">Download</a></li>
21
- <li><a href="/how_to_use.html">How to use</a></li>
22
- <li>
23
- <a href="http://rubyforge.org/projects/staticmatic">Development</a>
24
- </li>
25
- <li>
26
- <a href="http://groups.google.co.uk/group/staticmatic">Community</a>
27
- </li>
28
- <li><a href="/faq.html">FAQ</a></li>
29
- </ul>
30
- </div>
31
- <div id='content_wrapper'>
32
- <div id='side'>
33
- <div id='news'>
34
- <div class='heading'>News</div>
35
- <div class='title'>0.8.8 Released!</div>
36
- <p>
37
- Complete with:
38
- </p>
39
- <ul>
40
- <li>Helpers</li>
41
- <li>Configuration</li>
42
- </ul>
43
- <a href="/releases/0_8_8.html">And More!</a>
44
- </div>
45
- </div>
46
- <div id='content'>
47
- <h1>Download</h1>
48
- <p>
49
- The simplest way to get StaticMatic is via RubyGems:
50
- </p>
51
- <div class='code'>gem install staticmatic</div>
52
- <h3>Source Code</h3>
53
- <p>
54
- You can get the source code from
55
- <a href="http://rubyforge.org/projects/staticmatic/">RubyForge</a>
56
- :
57
- </p>
58
- <div class='code'>
59
- svn checkout svn://rubyforge.org/var/svn/staticmatic/trunk staticmatic
60
- </div>
61
- </div>
62
- </div>
63
- <div id='footer'>
64
- <p>
65
- Made with StaticMatic, Hosted by
66
- <a href="http://rubyforge.org">RubyForge</a>
67
- </p>
68
- </div>
69
- <script src='http://www.google-analytics.com/urchin.js' type='text/javascript'>
70
- _hamlspace = "";
71
- </script>
72
- <script type='text/javascript'>
73
- _uacct = "UA-775359-8";
74
- urchinTracker();
75
- </script>
76
- </div>
77
- </body>
78
- </html>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
3
+ <head>
4
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
5
+ <title>StaticMatic</title>
6
+ <link href="stylesheets/application.css" media="all" rel="stylesheet"/>
7
+ <link href="stylesheets/application.css" media="screen" rel="stylesheet"/>
8
+ </head>
9
+ <body>
10
+ <div id='container'>
11
+ <div id='header'>
12
+ <div class='bycurve21'>
13
+ <a href="http://www.curve21.com"><img alt="Bycurve21" src="images/bycurve21.gif"/></a>
14
+ </div>
15
+ <div class='title'>StaticMatic</div>
16
+ </div>
17
+ <div id='menu'>
18
+ <ul>
19
+ <li><a href="/">Home</a></li>
20
+ <li><a href="download.html">Download</a></li>
21
+ <li><a href="how_to_use.html">How to use</a></li>
22
+ <li>
23
+ <a href="http://groups.google.co.uk/group/staticmatic">Community</a>
24
+ </li>
25
+ <li><a href="faq.html">FAQ</a></li>
26
+ <li>
27
+ <a href="http://rubyforge.org/tracker/?func=browse&amp;group_id=3712&amp;atid=14306">Report Bug</a>
28
+ </li>
29
+ <li>
30
+ <a href="http://rubyforge.org/projects/staticmatic">Development</a>
31
+ </li>
32
+ </ul>
33
+ </div>
34
+ <div id='content_wrapper'>
35
+ <div id='side'>
36
+ <div id='news'>
37
+ <div class='heading'>News</div>
38
+ <div class='title'>0.9.0 Released!</div>
39
+ <p>Complete with:</p>
40
+ <ul>
41
+ <li>&quot;Local&quot; links are always relative</li>
42
+ <li>
43
+ Ability to strip .html and index.html from link tag urls
44
+ </li>
45
+ <li>configuration.sass_options</li>
46
+ </ul>
47
+ <a href="/releases/0_9_0.html">And More!</a>
48
+ </div>
49
+ </div>
50
+ <div id='content'>
51
+ <h1>Download</h1>
52
+ <p>
53
+ The simplest way to get StaticMatic is via RubyGems:
54
+ </p>
55
+ <div class='code'>gem install staticmatic</div>
56
+ <h3>Source Code</h3>
57
+ <p>
58
+ You can get the source code from
59
+ <a href="http://rubyforge.org/projects/staticmatic/">RubyForge</a>
60
+ :
61
+ </p>
62
+ <div class='code'>
63
+ svn checkout svn://rubyforge.org/var/svn/staticmatic/trunk staticmatic
64
+ </div>
65
+ </div>
66
+ </div>
67
+ <div id='footer'>
68
+ <p>
69
+ Made with StaticMatic
70
+ 0.9.0
71
+ , Hosted by
72
+ <a href="http://rubyforge.org">RubyForge</a>
73
+ </p>
74
+ </div>
75
+ <script src='http://www.google-analytics.com/urchin.js' type='text/javascript'>
76
+ _hamlspace = "";
77
+ </script>
78
+ <script type='text/javascript'>
79
+ _uacct = "UA-775359-8";
80
+ urchinTracker();
81
+ </script>
82
+ </div>
83
+ </body>
84
+ </html>