staticmatic 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +24 -0
  3. data/README.rdoc +48 -0
  4. data/Rakefile +22 -27
  5. data/bin/staticmatic +0 -0
  6. data/lib/staticmatic.rb +12 -4
  7. data/lib/staticmatic/base.rb +30 -242
  8. data/lib/staticmatic/mixins/build.rb +46 -0
  9. data/lib/staticmatic/mixins/helpers.rb +15 -0
  10. data/lib/staticmatic/mixins/render.rb +125 -0
  11. data/lib/staticmatic/mixins/rescue.rb +12 -0
  12. data/lib/staticmatic/mixins/server.rb +6 -0
  13. data/lib/staticmatic/mixins/setup.rb +20 -0
  14. data/lib/staticmatic/template_error.rb +40 -0
  15. data/lib/staticmatic/templates/{application.haml → default/application.haml} +0 -0
  16. data/lib/staticmatic/templates/{application.sass → default/application.sass} +0 -0
  17. data/lib/staticmatic/templates/{index.haml → default/index.haml} +0 -0
  18. data/lib/staticmatic/templates/rescues/default.haml +7 -0
  19. data/lib/staticmatic/templates/rescues/template.haml +18 -0
  20. data/test/test_helper.rb +20 -48
  21. metadata +55 -124
  22. data/CHANGELOG +0 -57
  23. data/LICENSE +0 -21
  24. data/README +0 -56
  25. data/example/site/contact.html +0 -17
  26. data/example/site/index.html +0 -16
  27. data/example/site/javascripts/application.css +0 -2
  28. data/example/src/layouts/application.haml +0 -11
  29. data/example/src/pages/contact.haml +0 -3
  30. data/example/src/pages/index.haml +0 -3
  31. data/example/src/pages/test test/blah.haml +0 -1
  32. data/example/src/stylesheets/application.sass +0 -4
  33. data/lib/staticmatic/version.rb +0 -34
  34. data/test/base_test.rb +0 -60
  35. data/test/helpers_test.rb +0 -296
  36. data/test/sandbox/test_site/configuration.rb +0 -0
  37. data/test/sandbox/test_site/site/index.html +0 -10
  38. data/test/sandbox/test_site/site/stylesheets/application.css +0 -2
  39. data/test/sandbox/test_site/src/helpers/application_helper.rb +0 -5
  40. data/test/sandbox/test_site/src/layouts/alternate_layout.haml +0 -3
  41. data/test/sandbox/test_site/src/layouts/application.haml +0 -7
  42. data/test/sandbox/test_site/src/layouts/projects.haml +0 -1
  43. data/test/sandbox/test_site/src/pages/index.haml +0 -5
  44. data/test/sandbox/test_site/src/pages/layout_test.haml +0 -2
  45. data/test/sandbox/test_site/src/partials/menu.haml +0 -1
  46. data/test/sandbox/test_site/src/stylesheets/application.sass +0 -2
  47. data/test/server_test.rb +0 -12
  48. data/test/test_helper_test.rb +0 -49
  49. data/test/version_test.rb +0 -28
  50. data/website/site/download.html +0 -84
  51. data/website/site/faq.html +0 -101
  52. data/website/site/helper_central/index.html +0 -144
  53. data/website/site/how_to_use.html +0 -307
  54. data/website/site/images/bycurve21.gif +0 -0
  55. data/website/site/images/curve21.jpg +0 -0
  56. data/website/site/images/homepage-build.jpg +0 -0
  57. data/website/site/images/homepage-previewing.jpg +0 -0
  58. data/website/site/images/homepage-templating.jpg +0 -0
  59. data/website/site/index.html +0 -98
  60. data/website/site/releases/0_8_10.html +0 -106
  61. data/website/site/releases/0_8_4.html +0 -101
  62. data/website/site/releases/0_8_8.html +0 -96
  63. data/website/site/releases/0_9_0.html +0 -124
  64. data/website/site/stylesheets/application.css +0 -287
  65. data/website/src/helpers/application_helper.rb +0 -5
  66. data/website/src/layouts/application.haml +0 -43
  67. data/website/src/layouts/test.haml +0 -4
  68. data/website/src/pages/_qa.haml +0 -2
  69. data/website/src/pages/download.haml +0 -15
  70. data/website/src/pages/faq.haml +0 -8
  71. data/website/src/pages/helper_central/_helper.haml +0 -7
  72. data/website/src/pages/helper_central/index.haml +0 -21
  73. data/website/src/pages/how_to_use.haml +0 -270
  74. data/website/src/pages/index.haml +0 -27
  75. data/website/src/pages/releases/0_8_10.haml +0 -22
  76. data/website/src/pages/releases/0_8_4.haml +0 -25
  77. data/website/src/pages/releases/0_8_8.haml +0 -35
  78. data/website/src/pages/releases/0_9_0.haml +0 -34
  79. data/website/src/partials/news.haml +0 -10
data/CHANGELOG DELETED
@@ -1,57 +0,0 @@
1
- *SVN*
2
-
3
- * [NEW] added link_to as an alias to link for those Rails types [Brent Beardsley]
4
-
5
- * [NEW] added text_area helper (patch #14870) [steve ross]
6
-
7
- * [NEW] tag helper adds name as an id if no id and a name given (patch #14870) [steve ross]
8
-
9
- * [NEW] stylesheet type='text/css' attribute is now specified [Brent Beardsley]
10
-
11
- *0.9.0* (October 16th, 2007)
12
-
13
- * [NEW] added StaticMatic::VERSION.requirements_met? [Brent Beardsley]
14
-
15
- * [NEW] added LICENSE and CHANGELOG files [Brent Beardsley]
16
-
17
- * [NEW] can now specify relative paths when only specifying a title - link("../How to download") [Brent Beardsley]
18
-
19
- * [NEW] add src_dir/stylesheets directory to sass load path so you can use @import styles.sass [Brent Beardsley]
20
-
21
- * [NEW] added sass_options hash to configuration so you can configure sass (ie: :style => :compact) [Brent Beardsley]
22
-
23
- * [NEW] added configuration.use_extensions_for_page_links (defaults to true) when false will strip index.html and .html off the end of links for pretty urls [Brent Beardsley]
24
-
25
- * [NEW] made all "local" links (pages/stylesheets/images) relative to the current page and removed use_relative_path_for_* configuration settings [Brent Beardsley]
26
-
27
- * [FIX] no longer add \n after the tag in the tag helper [Brent Beardsley]
28
-
29
- * [FIX] mailto: links were getting a / inserted at in front of the mailto: [Brent Beardsley]
30
-
31
- * [NEW] stylesheets helper can now take a list of stylesheets to include and the order as well as options (ie: :media => :print) [Brent Beardsley]
32
-
33
- * [FIX] clear all instance variables in @scope except @staticmatic [Brent Beardsley]
34
-
35
- * [NEW] added clean and clobber tasks to Rakefile [Brent Beardsley]
36
-
37
- * [NEW] added StaticMatic::VERSION in version.rb [Brent Beardsley]
38
-
39
- * [NEW] added package task to Rakefile and made it the default [Brent Beardsley]
40
-
41
- *0.8.10* (October 12th, 2007)
42
-
43
- * [NEW] rails-like partials. Partials can start with an underscore and live in the pages directory tree, old way still works [Brent Beardsley]
44
-
45
- * [NEW] img helper changes and tests [Jason Tennier]
46
-
47
- * [NEW] added current_page helper for use in other helpers, layouts, or pages [Brent Beardsley]
48
-
49
- * [NEW] add src_dir, site_dir, and current_page attr_reader's on staticmatic class [Brent Beardsley]
50
-
51
- * [FIX] removed dependency on rails needing to be installed [Brent Beardsley]
52
-
53
- * [FIX] fixed preview bug where setting a layout in a page would cause it to be used even for pages that did not have a layout specified and should be using the default [Brent Beardsley]
54
-
55
- * [FIX] tag helper only outputs the attribute if it has a value [Brent Beardsley]
56
-
57
- * [FIX] renamed RakeFile to Rakefile so it'll work on non-windows boxes [Brent Beardsley]
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- Copyright (C) 2007 Stephen Bartholomew
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
data/README DELETED
@@ -1,56 +0,0 @@
1
- # StaticMatic
2
-
3
- *For information on Haml & Sass please see [haml.hamptoncatlin.com](http://haml.hamptoncatlin.com)*.
4
-
5
- **Please Note:** StaticMatic is fresh out the oven. It has a limited feature set and
6
- is only really covering my immediate requirements.
7
-
8
- _However_, I am interested in getting feedback on the idea and code contributions & ideas are always welcome.
9
-
10
- ## What's it all about?
11
-
12
- CMS is overrated. A lot of the time, clients want us to do what we do
13
- best - well designed pages with structured, accessible and maintainable markup & styling.
14
-
15
- CMSs are often perfect for this, but sometimes they can be restrictive and more cumbersome
16
- than just working with good ol' source code. At the same time we want our code to be
17
- structured, DRY and flexible.
18
-
19
- Enter **StaticMatic**.
20
-
21
- ## Usage
22
-
23
- StaticMatic will set up a basic site structure for you with this command:
24
-
25
- staticmatic setup <directory>
26
-
27
- After this command you'll have the following files:
28
-
29
- <directory>/
30
- site/
31
- images/
32
- stylesheets/
33
- javascripts/
34
- src/
35
- helpers/
36
- layouts/
37
- application.haml
38
- pages/
39
- index.haml
40
- partials/
41
- stylesheets/
42
- application.sass
43
-
44
- StaticMatic sets you up with a sample layout, stylesheet and page file. Once you've
45
- edited the pages and stylesheets, you can generate the static site:
46
-
47
- staticmatic build <directory>
48
-
49
- All of the pages are parsed and wrapped up in application.haml and put into the site directory.
50
-
51
- ## Templates
52
-
53
- StaticMatic adds a few helpers to the core Haml helpers:
54
-
55
- = link 'Title', 'url'
56
- = img 'my_image.jpg'
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html>
3
- <head>
4
- <title>Welcome to my site</title>
5
- </head>
6
- <body>
7
- <div id='menu'>
8
- <ul>
9
- <li>Test</li>
10
- </ul>
11
- </div>
12
- <h1>Contact Us</h1>
13
- <p>Use the form below</p>
14
- </body>
15
- </html>
16
- </body>
17
- </html>
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html>
3
- <head>
4
- <title>Welcome to my site</title>
5
- </head>
6
- <body>
7
- <div id='menu'>
8
- <ul>
9
- <li>Test</li>
10
- </ul>
11
- </div>
12
- <h1>This is a test - with a change</h1>
13
- <a href="index"><img src="images/image_path.jpg"/></a>
14
- <img src="images/test"/>
15
- </body>
16
- </html>
@@ -1,2 +0,0 @@
1
- body {
2
- color: #ff0000; }
@@ -1,11 +0,0 @@
1
- !!!
2
- %html
3
- %head
4
- %title Welcome to my site
5
- = stylesheets
6
- %body
7
- #menu
8
- %ul
9
- %li=link "Home", "/"
10
- %li=link "Contact"
11
- = yield
@@ -1,3 +0,0 @@
1
- %h1 Contact Us
2
-
3
- %p Use the form below
@@ -1,3 +0,0 @@
1
- %h1 Welcome to StaticMatic
2
-
3
- %p Managing static site with Haml & Sass
@@ -1 +0,0 @@
1
- %h1 Test
@@ -1,4 +0,0 @@
1
- body
2
- :font
3
- :family verdana
4
- :size 10pt
@@ -1,34 +0,0 @@
1
- module StaticMatic #:nodoc:
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 9
5
- TINY = 5
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- URLIFIED = STRING.tr('.', '_')
9
-
10
- # requirements_met? can take a hash with :major, :minor, :tiny set or
11
- # a string in the format "major.minor.tiny"
12
- def self.requirements_met?(minimum_version = {})
13
- major = minor = tiny = 0
14
- if minimum_version.is_a?(Hash)
15
- major = minimum_version[:major].to_i if minimum_version.has_key?(:major)
16
- minor = minimum_version[:minor].to_i if minimum_version.has_key?(:minor)
17
- tiny = minimum_version[:tiny].to_i if minimum_version.has_key?(:tiny)
18
- else
19
- major, minor, tiny = minimum_version.to_s.split('.').collect { |v| v.to_i }
20
- end
21
- met = false
22
- if StaticMatic::VERSION::MAJOR > major
23
- met = true
24
- elsif StaticMatic::VERSION::MAJOR == major
25
- if StaticMatic::VERSION::MINOR > minor
26
- met = true
27
- elsif StaticMatic::VERSION::MINOR == minor
28
- met = StaticMatic::VERSION::TINY >= tiny
29
- end
30
- end
31
- met
32
- end
33
- end
34
- end
data/test/base_test.rb DELETED
@@ -1,60 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/staticmatic'
3
-
4
- class StaticMaticBaseTest < Test::Unit::TestCase
5
- def setup
6
- @base_dir = File.dirname(__FILE__) + '/sandbox/test_site'
7
- @staticmatic = StaticMatic::Base.new(@base_dir)
8
- end
9
-
10
- def test_initial_configuration_settings
11
- assert_equal true, @staticmatic.configuration.use_extensions_for_page_links
12
- assert_equal 3000, @staticmatic.configuration.preview_server_port
13
- end
14
-
15
- def test_should_setup_directories
16
- tmp_dir = File.dirname(__FILE__) + '/sandbox/tmp'
17
- staticmatic = StaticMatic::Base.new(tmp_dir)
18
- staticmatic.run('setup')
19
-
20
- StaticMatic::Base.base_dirs.each do |dir|
21
- assert File.exists?("#{tmp_dir}/#{dir}"), "Should create #{dir}"
22
- end
23
-
24
- StaticMatic::Base.base_dirs.reverse.each do |dir|
25
- Dir.entries("#{tmp_dir}/#{dir}").each do |file|
26
- next if file.match(/^\./)
27
- File.delete("#{tmp_dir}/#{dir}/#{file}")
28
- end
29
- Dir.delete("#{tmp_dir}/#{dir}") if File.exists?("#{tmp_dir}/#{dir}")
30
- end
31
- end
32
-
33
- def test_should_generate_html_with_layout
34
- content = @staticmatic.generate_html_with_layout("index")
35
- assert_match "StaticMatic", content
36
- assert_match "This is some test content", content
37
- end
38
-
39
- def test_should_generate_html_with_layout_assigned_in_template
40
- content = @staticmatic.generate_html_with_layout("layout_test")
41
- assert_match "Alternate Layout", content
42
- end
43
-
44
- def test_should_generate_css
45
- content = @staticmatic.generate_css("application")
46
- end
47
-
48
- def test_should_find_source_filename_from_path
49
- assert_equal "application", @staticmatic.source_template_from_path("@base_dir/src/stylesheets/application.css")[1]
50
- end
51
-
52
- def test_should_find_layout_from_passed_path
53
- assert_equal "projects", @staticmatic.detirmine_layout("test/projects")
54
- end
55
-
56
- def test_should_include_custom_helper
57
- content = @staticmatic.generate_html_with_layout("index")
58
- assert_match "Hello, Steve!", content
59
- end
60
- end
data/test/helpers_test.rb DELETED
@@ -1,296 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/staticmatic'
3
- require File.dirname(__FILE__) + '/test_helper'
4
-
5
- class HelpersTest < Test::Unit::TestCase
6
- include StaticMatic::Helpers
7
-
8
- def setup
9
- @staticmatic = StaticMatic::Base.new(File.dirname(__FILE__) + '/sandbox/test_site')
10
- end
11
-
12
- # Stylesheets tests
13
- def test_should_generate_stylesheet_links
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
34
- end
35
-
36
- # Link tests
37
- def test_should_autolink_page
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>}
48
- assert_match expected_output, link("Test")
49
- end
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', '//www.google.com/search'].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
159
- def test_should_generate_tag_with_block
160
- expected_output = %q{<a href="/test.html" title="My Test Link">Test</a>}
161
- assert_match expected_output, tag(:a, :href => "/test.html", :title => 'My Test Link') { "Test" }
162
- end
163
-
164
- def test_should_generate_tag
165
- expected_output = %q{<br/>}
166
- assert_match expected_output, tag(:br)
167
- end
168
-
169
- # Urlify tests
170
- def test_should_urlify_string
171
- assert_equal "stephens_haml_and_sass_project", urlify("Stephen's Haml & Sass Project")
172
- assert_equal "testlink", urlify("Test/Link")
173
- end
174
-
175
- # Text_field tests
176
- def test_should_generate_input
177
- expected_output = %q{<input type="text" id="test" value="blah" name="test"/>}
178
- assert_tags_match expected_output, text_field("test", "blah")
179
- end
180
-
181
- # Text_area tests
182
- def test_should_generate_text_area
183
- expected_output = '<textarea id="hello" name="hello">world</textarea>'
184
- assert_equal expected_output, text_area('hello', 'world')
185
- end
186
-
187
- # Element id test
188
- def test_id_should_not_be_overwritten
189
- expected_output = '<textarea id="goodbye" name="hello">world</textarea>'
190
- assert_equal expected_output, text_area('hello', 'world', :id => 'goodbye')
191
- end
192
-
193
- # Javascripts tests
194
- def test_should_generate_js_links
195
- set_current_page('/index.html')
196
- expected_output = %q{src="javascripts/test.js"}
197
- assert_match expected_output, javascripts('test')
198
-
199
- expected_output = %q{src="javascripts/test.js"}
200
- assert_match expected_output, javascripts(:test)
201
-
202
- set_current_page('/subdir/index.html')
203
- expected_output = %q{src="../javascripts/test.js"}
204
- assert_match expected_output, javascripts('test')
205
-
206
- set_current_page('/subdir/other/index.html')
207
- expected_output = %q{src="../../javascripts/test.js"}
208
- assert_match expected_output, javascripts('test')
209
- end
210
-
211
- def test_should_not_change_js_link_with_existing_relative_url
212
- ['/index.html', '/subdir/index.html', '/subdir/other/index.html'].each do |the_current_page|
213
- set_current_page(the_current_page)
214
-
215
- ['/my_javascript.js', './my_javascript.js', '../other/my_javascript.js'].each do |the_path|
216
- expected_output = "src=\"#{the_path}\""
217
- assert_match expected_output, javascripts(the_path)
218
- end
219
- end
220
- end
221
-
222
- def test_should_generate_absolute_js_link
223
- ['/index.html', '/subdir/index.html', '/subdir/other/foo.html'].each do |the_current_page|
224
- set_current_page(the_current_page)
225
-
226
- ['http://staticmatic.rubyforge.org/javascripts/test.js', 'https://staticmatic.rubyforge.org/javascripts/test.js'].each do |the_path|
227
- expected_output = "src=\"#{the_path}\""
228
- assert_match expected_output, javascripts(the_path)
229
- end
230
- end
231
- end
232
-
233
- # Partials tests
234
- def test_should_include_partial_template
235
- @staticmatic.instance_eval { def current_file() "/index.haml"; end }
236
- set_current_page("/index.html")
237
- expected_output = "My Menu"
238
- assert_match expected_output, partial("menu")
239
- end
240
-
241
- # Image tests
242
- def test_should_generate_basic_img_tag
243
- set_current_page("/index.html")
244
- expected_output = %q{<img src="images/test.gif" alt="Test"/>}
245
- assert_tags_match expected_output, img('test.gif')
246
-
247
- set_current_page("/subdir/index.html")
248
- expected_output = %q{<img src="../images/test.gif" alt="Test"/>}
249
- assert_tags_match expected_output, img('test.gif')
250
-
251
- set_current_page("/subdir/other/index.html")
252
- expected_output = %q{<img src="../../images/test.gif" alt="Test"/>}
253
- assert_tags_match expected_output, img('test.gif')
254
- end
255
-
256
- def test_should_generate_img_tag_with_options
257
- set_current_page("/index.html")
258
- expected_output = %q{<img src="images/test.gif" alt="Testing the alt" class="testClass"/>}
259
- assert_tags_match expected_output, img('test.gif', {:alt => 'Testing the alt', :class => 'testClass'})
260
- end
261
-
262
- def test_should_generate_img_tag_with_sub_directory
263
- set_current_page("/index.html")
264
- expected_output = %q{<img src="images/about_us/test.gif" alt="Test"/>}
265
- assert_tags_match expected_output, img('about_us/test.gif')
266
- end
267
-
268
- def test_should_generate_img_tag_with_src_left_as_is
269
- ['/index.html', '/subdir/index.html', '/subdir/other/index.html'].each do |the_current_page|
270
- set_current_page(the_current_page)
271
-
272
- ['/images/test_image.gif', './test_image.gif', '../test_image.gif'].each do |the_path|
273
- expected_output = "<img src=\"#{the_path}\" alt=\"Test image\"/>"
274
- assert_tags_match expected_output, img(the_path)
275
- end
276
- end
277
- end
278
-
279
- def test_should_generate_absolute_img_tag
280
- ['/index.html', '/subdir/foo.html', '/subdir/other/index.html'].each do |the_current_page|
281
- set_current_page(the_current_page)
282
-
283
- ['http://staticmatic.rubyforge.org/images/bycurve21.gif', 'https://staticmatic.rubyforge.org/images/bycurve21.gif'].each do |the_path|
284
- expected_output = "<img src=\"#{the_path}\" alt=\"Bycurve21\"/>"
285
- assert_tags_match expected_output, img(the_path)
286
- end
287
- end
288
- end
289
-
290
- private
291
-
292
- def set_current_page(page)
293
- @staticmatic.instance_variable_set("@current_page", page)
294
- end
295
-
296
- end