staticmatic 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -8
- data/lib/staticmatic/helpers.rb +50 -6
- data/lib/staticmatic.rb +7 -5
- data/test/helpers_test.rb +44 -0
- data/test/sandbox/test_site/config.rb +0 -0
- data/test/sandbox/test_site/site/index.html +10 -0
- data/test/sandbox/test_site/site/stylesheets/application.css +2 -0
- data/test/sandbox/test_site/src/layouts/application.haml +7 -0
- data/test/sandbox/test_site/src/pages/index.haml +1 -0
- data/test/sandbox/test_site/src/stylesheets/application.sass +2 -0
- data/test/staticmatic_test.rb +11 -5
- metadata +20 -2
data/README
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
# StaticMatic
|
2
2
|
|
3
|
-
|
3
|
+
*For information on Haml & Sass please see [haml.hamptoncatlin.com](http://haml.hamptoncatlin.com)*.
|
4
4
|
|
5
5
|
**Please Note:** StaticMatic is fresh out the oven. It has a limited feature set and
|
6
6
|
is only really covering my immediate requirements.
|
7
7
|
|
8
|
-
_However_, I am interested in getting feedback on the idea and code contributions are always welcome.
|
8
|
+
_However_, I am interested in getting feedback on the idea and code contributions & ideas are always welcome.
|
9
9
|
|
10
|
-
|
10
|
+
## What's it all about?
|
11
11
|
|
12
12
|
CMS is overrated. A lot of the time, clients want us to do what we do
|
13
13
|
best - well designed pages with structured, accessible and maintainable markup & styling.
|
@@ -18,7 +18,7 @@ structured, DRY and flexible.
|
|
18
18
|
|
19
19
|
Enter **StaticMatic**.
|
20
20
|
|
21
|
-
|
21
|
+
## Usage
|
22
22
|
|
23
23
|
StaticMatic will set up a basic site structure for you with this command:
|
24
24
|
|
@@ -46,15 +46,33 @@ edited the pages and stylesheets, you can generate the static site:
|
|
46
46
|
|
47
47
|
All of the pages are parsed and wrapped up in application.haml and put into the site directory.
|
48
48
|
|
49
|
-
|
49
|
+
## Templates
|
50
50
|
|
51
51
|
StaticMatic adds a few helpers to the core Haml helpers:
|
52
52
|
|
53
53
|
= link 'Title', 'url'
|
54
54
|
= img 'my_image.jpg'
|
55
55
|
|
56
|
-
|
56
|
+
|
57
|
+
**_Coming soon:_**
|
58
|
+
|
59
|
+
I'm already extending these to include some neat conventions to speed up coding. For example, in the next version:
|
60
|
+
|
61
|
+
= link 'Contact Us'
|
62
|
+
|
63
|
+
will produce
|
64
|
+
|
65
|
+
<a href="contact_us.html">Contact Us</a>
|
66
|
+
|
67
|
+
Or with the Rewriting enabled:
|
68
|
+
|
69
|
+
<a href="contact_us">Contact Us</a>
|
70
|
+
|
71
|
+
## What's Next?
|
57
72
|
|
58
73
|
* Multiple directories of content
|
59
74
|
* Layouts based on directory of page template
|
60
|
-
* Additional Helpers
|
75
|
+
* Additional Helpers
|
76
|
+
* Tests, tests, tests!
|
77
|
+
* Configuration
|
78
|
+
* Default Rewriting for HTML pages (drop the .html)
|
data/lib/staticmatic/helpers.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Haml
|
2
2
|
module Helpers
|
3
3
|
|
4
|
+
# Generates links to all stylesheets in the site's directory
|
4
5
|
def stylesheets
|
5
6
|
stylesheet_dir = "#{base_dir}/site/stylesheets/"
|
6
7
|
output = ""
|
@@ -13,23 +14,51 @@ module Haml
|
|
13
14
|
output
|
14
15
|
end
|
15
16
|
|
17
|
+
# Generate javascript source tags for the specified files
|
18
|
+
#
|
19
|
+
# javascripts('test') -> <script language="javascript" src="javascripts/test.js"></script>
|
20
|
+
#
|
16
21
|
def javascripts(*files)
|
22
|
+
output = ""
|
23
|
+
files.each do |file|
|
24
|
+
if !file.match(/^http\:\/\//)
|
25
|
+
output << tag(:script, :language => 'javascript', :src => "javascripts/#{file}.js") { "" }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
output
|
17
29
|
end
|
18
|
-
|
19
|
-
|
30
|
+
|
31
|
+
# Generates a form text field
|
32
|
+
#
|
33
|
+
def text_field(name, value)
|
34
|
+
tag(:input, :type => "text", :name => name, :value => value)
|
20
35
|
end
|
21
36
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
37
|
+
# Generate an HTML link
|
38
|
+
#
|
39
|
+
# If only the title is passed, it will automatically
|
40
|
+
# create a link from this value:
|
41
|
+
#
|
42
|
+
# link('Test') -> <a href="test.html">Test</a>
|
43
|
+
#
|
44
|
+
def link(title, page = "", options = {})
|
45
|
+
if page.blank?
|
46
|
+
page = urlify(title) + ".html"
|
47
|
+
end
|
48
|
+
|
26
49
|
tag(:a, :href => page) { title }
|
27
50
|
end
|
28
51
|
|
52
|
+
# Generates an image tag
|
29
53
|
def img(name, options = {})
|
30
54
|
tag :img, options.merge!({:src => "images/#{name}"})
|
31
55
|
end
|
32
56
|
|
57
|
+
# Generates HTML tags:
|
58
|
+
#
|
59
|
+
# tag(:br) -> <br/>
|
60
|
+
# tag(:a, :href => 'test.html') { "Test" } -> <a href="test.html">Test</a>
|
61
|
+
#
|
33
62
|
def tag(name, options = {}, &block)
|
34
63
|
output = "<#{name}"
|
35
64
|
options.each do |attribute, value|
|
@@ -45,5 +74,20 @@ module Haml
|
|
45
74
|
end
|
46
75
|
output
|
47
76
|
end
|
77
|
+
|
78
|
+
# Generates a URL friendly string from the value passed:
|
79
|
+
#
|
80
|
+
# "We love Haml" -> "we_love_haml"
|
81
|
+
# "Elf & Ham" -> "elf_and_ham"
|
82
|
+
# "Stephen's gem" -> "stephens_gem"
|
83
|
+
#
|
84
|
+
def urlify(string)
|
85
|
+
string.tr(" ", "_").
|
86
|
+
sub("&", "and").
|
87
|
+
sub("@", "at").
|
88
|
+
tr("^A-Za-z0-9_", "").
|
89
|
+
sub(/_{2,}/, "_").
|
90
|
+
downcase
|
91
|
+
end
|
48
92
|
end
|
49
93
|
end
|
data/lib/staticmatic.rb
CHANGED
@@ -3,10 +3,10 @@ require 'haml'
|
|
3
3
|
require File.dirname(__FILE__) + '/staticmatic/helpers'
|
4
4
|
|
5
5
|
class StaticMatic
|
6
|
-
VERSION = '0.0
|
7
|
-
|
6
|
+
VERSION = '0.1.0'
|
7
|
+
|
8
|
+
# Directories generated for a new site setup
|
8
9
|
cattr_reader :base_dirs
|
9
|
-
|
10
10
|
@@base_dirs = %w{
|
11
11
|
site/
|
12
12
|
site/stylesheets
|
@@ -18,6 +18,7 @@ class StaticMatic
|
|
18
18
|
src/stylesheets
|
19
19
|
}
|
20
20
|
|
21
|
+
# Templates for setup and their location
|
21
22
|
@@templates = {
|
22
23
|
'application.haml' => 'layouts',
|
23
24
|
'application.sass' => 'stylesheets',
|
@@ -50,7 +51,7 @@ class StaticMatic
|
|
50
51
|
end
|
51
52
|
|
52
53
|
@@templates.each do |template, destination|
|
53
|
-
|
54
|
+
copy_file("#{@templates_dir}/#{template}", "#{@src_dir}/#{destination}")
|
54
55
|
end
|
55
56
|
|
56
57
|
puts "Done"
|
@@ -59,6 +60,7 @@ class StaticMatic
|
|
59
60
|
private
|
60
61
|
|
61
62
|
def copy_file(from, to)
|
63
|
+
`cp #{from} #{to}`
|
62
64
|
end
|
63
65
|
|
64
66
|
def save_page(filename, content)
|
@@ -86,7 +88,7 @@ class StaticMatic
|
|
86
88
|
|
87
89
|
filename_without_extension = matches[1]
|
88
90
|
|
89
|
-
page = Haml::Engine.new(File.read("#{@src_dir}/pages/#{file}"))
|
91
|
+
page = Haml::Engine.new(File.read("#{@src_dir}/pages/#{file}", :locals => {:base_dir => @base_dir}))
|
90
92
|
page_content = page.render
|
91
93
|
|
92
94
|
content_with_layout = Haml::Engine.new(layout_content, :locals => {:base_dir => @base_dir}).render { page_content }
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/staticmatic'
|
3
|
+
|
4
|
+
class HelpersTest < Test::Unit::TestCase
|
5
|
+
include Haml::Helpers
|
6
|
+
|
7
|
+
# Provide method in place of local variable for the helpers - don'tcha just love ruby?
|
8
|
+
def base_dir
|
9
|
+
File.dirname(__FILE__) + '/sandbox/test_site'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_generate_stylesheet_links
|
13
|
+
assert_match "href=\"stylesheets\/application.css\"", stylesheets
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_autolink_page
|
17
|
+
expected_output = %q{<a href="test.html">Test</a>}
|
18
|
+
assert_match expected_output, link("Test")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_generate_tag_with_block
|
22
|
+
expected_output = %q{<a href="test.html" title="My Test Link">Test</a>}
|
23
|
+
assert_match expected_output, tag(:a, :href => "test.html", :title => 'My Test Link') { "Test" }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_generate_tag
|
27
|
+
expected_output = %q{<br/>}
|
28
|
+
assert_match expected_output, tag(:br)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_urlify_string
|
32
|
+
assert_equal "stephens_haml_and_sass_project", urlify("Stephen's Haml & Sass Project")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_generate_input
|
36
|
+
expected_output = %q{<input type="text" value="blah" name="test"/>}
|
37
|
+
assert_match expected_output, text_field("test", "blah")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_generate_js_links
|
41
|
+
expected_output = %q{<script src="javascripts/test.js" language="javascript"></script>}
|
42
|
+
assert_match expected_output, javascripts('test')
|
43
|
+
end
|
44
|
+
end
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
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>StaticMatic</title>
|
5
|
+
<link rel="stylesheet" href="stylesheets/application.css" media="all"/>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>StaticMatic!</h1>
|
9
|
+
</body>
|
10
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 StaticMatic!
|
data/test/staticmatic_test.rb
CHANGED
@@ -3,11 +3,7 @@ require File.dirname(__FILE__) + '/../lib/staticmatic'
|
|
3
3
|
|
4
4
|
class StaticMaticTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@base_dir = File.dirname(__FILE__) + '/sandbox'
|
7
|
-
|
8
|
-
StaticMatic.base_dirs.reverse.each do |dir|
|
9
|
-
Dir.delete("#{@base_dir}/#{dir}") if File.exists?("#{@base_dir}/#{dir}")
|
10
|
-
end
|
6
|
+
@base_dir = File.dirname(__FILE__) + '/sandbox/tmp'
|
11
7
|
end
|
12
8
|
|
13
9
|
def test_should_setup_directories
|
@@ -18,4 +14,14 @@ class StaticMaticTest < Test::Unit::TestCase
|
|
18
14
|
assert File.exists?("#{@base_dir}/#{dir}"), "Should create #{dir}"
|
19
15
|
end
|
20
16
|
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
StaticMatic.base_dirs.reverse.each do |dir|
|
20
|
+
Dir.entries("#{@base_dir}/#{dir}").each do |file|
|
21
|
+
next if file.match(/^\./)
|
22
|
+
File.delete("#{@base_dir}/#{dir}/#{file}")
|
23
|
+
end
|
24
|
+
Dir.delete("#{@base_dir}/#{dir}") if File.exists?("#{@base_dir}/#{dir}")
|
25
|
+
end
|
26
|
+
end
|
21
27
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: staticmatic
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2007-05-
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-05-24 00:00:00 +01:00
|
8
8
|
summary: Manage static sites using Haml & Sass
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -58,9 +58,27 @@ files:
|
|
58
58
|
- lib/staticmatic/templates/application.haml
|
59
59
|
- lib/staticmatic/templates/application.sass
|
60
60
|
- lib/staticmatic/templates/index.haml
|
61
|
+
- test/helpers_test.rb
|
61
62
|
- test/sandbox
|
62
63
|
- test/staticmatic_test.rb
|
64
|
+
- test/sandbox/test_site
|
65
|
+
- test/sandbox/tmp
|
66
|
+
- test/sandbox/test_site/config.rb
|
67
|
+
- test/sandbox/test_site/site
|
68
|
+
- test/sandbox/test_site/src
|
69
|
+
- test/sandbox/test_site/site/images
|
70
|
+
- test/sandbox/test_site/site/index.html
|
71
|
+
- test/sandbox/test_site/site/javascripts
|
72
|
+
- test/sandbox/test_site/site/stylesheets
|
73
|
+
- test/sandbox/test_site/site/stylesheets/application.css
|
74
|
+
- test/sandbox/test_site/src/layouts
|
75
|
+
- test/sandbox/test_site/src/pages
|
76
|
+
- test/sandbox/test_site/src/stylesheets
|
77
|
+
- test/sandbox/test_site/src/layouts/application.haml
|
78
|
+
- test/sandbox/test_site/src/pages/index.haml
|
79
|
+
- test/sandbox/test_site/src/stylesheets/application.sass
|
63
80
|
test_files:
|
81
|
+
- test/helpers_test.rb
|
64
82
|
- test/staticmatic_test.rb
|
65
83
|
rdoc_options: []
|
66
84
|
|