staticmatic 0.0.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/README +60 -0
- data/RakeFile +0 -0
- data/bin/staticmatic +19 -0
- data/example/site/contact.html +17 -0
- data/example/site/index.html +16 -0
- data/example/site/stylesheets/application.css +2 -0
- data/example/src/layouts/application.haml +9 -0
- data/example/src/pages/contact.haml +3 -0
- data/example/src/pages/index.haml +5 -0
- data/example/src/stylesheets/application.sass +2 -0
- data/lib/staticmatic.rb +110 -0
- data/lib/staticmatic/helpers.rb +49 -0
- data/lib/staticmatic/templates/application.haml +7 -0
- data/lib/staticmatic/templates/application.sass +2 -0
- data/lib/staticmatic/templates/index.haml +1 -0
- data/test/staticmatic_test.rb +21 -0
- metadata +84 -0
data/README
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
= StaticMatic
|
|
2
|
+
|
|
3
|
+
Managing static sites with [Haml & Sass](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 are always welcome.
|
|
9
|
+
|
|
10
|
+
== Introduction
|
|
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
|
+
pages/
|
|
36
|
+
index.haml
|
|
37
|
+
layouts/
|
|
38
|
+
application.haml
|
|
39
|
+
stylesheets/
|
|
40
|
+
application.sass
|
|
41
|
+
|
|
42
|
+
StaticMatic sets you up with a sample layout, stylesheet and page file. Once you've
|
|
43
|
+
edited the pages and stylesheets, you can generate the static site:
|
|
44
|
+
|
|
45
|
+
staticmatic build <directory>
|
|
46
|
+
|
|
47
|
+
All of the pages are parsed and wrapped up in application.haml and put into the site directory.
|
|
48
|
+
|
|
49
|
+
== Templates
|
|
50
|
+
|
|
51
|
+
StaticMatic adds a few helpers to the core Haml helpers:
|
|
52
|
+
|
|
53
|
+
= link 'Title', 'url'
|
|
54
|
+
= img 'my_image.jpg'
|
|
55
|
+
|
|
56
|
+
== What's Next?
|
|
57
|
+
|
|
58
|
+
* Multiple directories of content
|
|
59
|
+
* Layouts based on directory of page template
|
|
60
|
+
* Additional Helpers
|
data/RakeFile
ADDED
|
File without changes
|
data/bin/staticmatic
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/local/bin/ruby
|
|
2
|
+
require File.dirname(__FILE__) + '/../lib/staticmatic'
|
|
3
|
+
|
|
4
|
+
command = ARGV[0]
|
|
5
|
+
directory = ARGV[1]
|
|
6
|
+
|
|
7
|
+
if !command || !directory
|
|
8
|
+
puts 'Usage: staticmatic <build|setup> <directory>'
|
|
9
|
+
exit
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
staticmatic = StaticMatic.new(directory)
|
|
13
|
+
|
|
14
|
+
case command
|
|
15
|
+
when 'build'
|
|
16
|
+
staticmatic.build
|
|
17
|
+
when 'setup'
|
|
18
|
+
staticmatic.setup
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
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>
|
|
@@ -0,0 +1,16 @@
|
|
|
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>
|
data/lib/staticmatic.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'haml'
|
|
3
|
+
require File.dirname(__FILE__) + '/staticmatic/helpers'
|
|
4
|
+
|
|
5
|
+
class StaticMatic
|
|
6
|
+
VERSION = '0.0.1'
|
|
7
|
+
|
|
8
|
+
cattr_reader :base_dirs
|
|
9
|
+
|
|
10
|
+
@@base_dirs = %w{
|
|
11
|
+
site/
|
|
12
|
+
site/stylesheets
|
|
13
|
+
site/images
|
|
14
|
+
site/javascripts
|
|
15
|
+
src/
|
|
16
|
+
src/pages/
|
|
17
|
+
src/layouts
|
|
18
|
+
src/stylesheets
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@@templates = {
|
|
22
|
+
'application.haml' => 'layouts',
|
|
23
|
+
'application.sass' => 'stylesheets',
|
|
24
|
+
'index.haml' => 'pages'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def initialize(base_dir)
|
|
28
|
+
@base_dir = base_dir
|
|
29
|
+
@src_dir = "#{@base_dir}/src"
|
|
30
|
+
@site_dir = "#{@base_dir}/site"
|
|
31
|
+
@templates_dir = File.dirname(__FILE__) + '/staticmatic/templates'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def build
|
|
35
|
+
build_css
|
|
36
|
+
build_html
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def setup
|
|
40
|
+
if !File.exists?(@base_dir)
|
|
41
|
+
Dir.mkdir(@base_dir)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
@@base_dirs.each do |directory|
|
|
45
|
+
directory = "#{@base_dir}/#{directory}"
|
|
46
|
+
if !File.exists?(directory)
|
|
47
|
+
Dir.mkdir(directory)
|
|
48
|
+
puts "created #{directory}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@@templates.each do |template, destination|
|
|
53
|
+
`cp #{@templates_dir}/#{template} #{@src_dir}/#{destination}`
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
puts "Done"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def copy_file(from, to)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def save_page(filename, content)
|
|
65
|
+
filename = "#{filename}"
|
|
66
|
+
generate_site_file(filename, 'html', content)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def save_stylesheet(filename, content)
|
|
70
|
+
filename = "stylesheets/#{filename}"
|
|
71
|
+
generate_site_file(filename, 'css', content)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def generate_site_file(filename, extension, content)
|
|
75
|
+
site_file = File.new("#{@site_dir}/#{filename}.#{extension}", 'w+')
|
|
76
|
+
site_file << content
|
|
77
|
+
site_file.close
|
|
78
|
+
puts "created #{@site_dir}/#{filename}.#{extension}"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def build_html
|
|
82
|
+
layout_content = File.read("#{@src_dir}/layouts/application.haml")
|
|
83
|
+
|
|
84
|
+
Dir.entries("#{@src_dir}/pages").each do |file|
|
|
85
|
+
if matches = file.match(/([a-z0-9_-]+)\.haml$/)
|
|
86
|
+
|
|
87
|
+
filename_without_extension = matches[1]
|
|
88
|
+
|
|
89
|
+
page = Haml::Engine.new(File.read("#{@src_dir}/pages/#{file}"))
|
|
90
|
+
page_content = page.render
|
|
91
|
+
|
|
92
|
+
content_with_layout = Haml::Engine.new(layout_content, :locals => {:base_dir => @base_dir}).render { page_content }
|
|
93
|
+
|
|
94
|
+
save_page(filename_without_extension, content_with_layout)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def build_css
|
|
100
|
+
Dir.entries("#{@src_dir}/stylesheets").each do |file|
|
|
101
|
+
if matches = file.match(/([a-z0-9_-]+)\.sass$/)
|
|
102
|
+
filename_without_extension = matches[1]
|
|
103
|
+
|
|
104
|
+
stylesheet = Sass::Engine.new(File.read("#{@src_dir}/stylesheets/#{file}"))
|
|
105
|
+
|
|
106
|
+
save_stylesheet(filename_without_extension, stylesheet.render)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Haml
|
|
2
|
+
module Helpers
|
|
3
|
+
|
|
4
|
+
def stylesheets
|
|
5
|
+
stylesheet_dir = "#{base_dir}/site/stylesheets/"
|
|
6
|
+
output = ""
|
|
7
|
+
Dir.entries(stylesheet_dir).each do |file|
|
|
8
|
+
if file.match(/([a-z0-9_-]+)\.css$/)
|
|
9
|
+
output << tag(:link, :href => "stylesheets/#{file}", :rel => 'stylesheet', :media => 'all')
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
output
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def javascripts(*files)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def text_field(name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def submit(title)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def link(title, page = "")
|
|
26
|
+
tag(:a, :href => page) { title }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def img(name, options = {})
|
|
30
|
+
tag :img, options.merge!({:src => "images/#{name}"})
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def tag(name, options = {}, &block)
|
|
34
|
+
output = "<#{name}"
|
|
35
|
+
options.each do |attribute, value|
|
|
36
|
+
output << " #{attribute}=\"#{value}\""
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if block_given?
|
|
40
|
+
output << ">"
|
|
41
|
+
output << yield
|
|
42
|
+
output << "</#{name}>\n"
|
|
43
|
+
else
|
|
44
|
+
output << "/>\n"
|
|
45
|
+
end
|
|
46
|
+
output
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
%h1 StaticMatic!
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require File.dirname(__FILE__) + '/../lib/staticmatic'
|
|
3
|
+
|
|
4
|
+
class StaticMaticTest < Test::Unit::TestCase
|
|
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
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_should_setup_directories
|
|
14
|
+
staticmatic = StaticMatic.new(@base_dir)
|
|
15
|
+
staticmatic.setup
|
|
16
|
+
|
|
17
|
+
StaticMatic.base_dirs.each do |dir|
|
|
18
|
+
assert File.exists?("#{@base_dir}/#{dir}"), "Should create #{dir}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
rubygems_version: 0.9.2
|
|
3
|
+
specification_version: 1
|
|
4
|
+
name: staticmatic
|
|
5
|
+
version: !ruby/object:Gem::Version
|
|
6
|
+
version: 0.0.1
|
|
7
|
+
date: 2007-05-22 00:00:00 +01:00
|
|
8
|
+
summary: Manage static sites using Haml & Sass
|
|
9
|
+
require_paths:
|
|
10
|
+
- lib
|
|
11
|
+
email: steve@curve21.com
|
|
12
|
+
homepage: http//www.curve21.com
|
|
13
|
+
rubyforge_project:
|
|
14
|
+
description:
|
|
15
|
+
autorequire:
|
|
16
|
+
default_executable:
|
|
17
|
+
bindir: bin
|
|
18
|
+
has_rdoc: false
|
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">"
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 0.0.0
|
|
24
|
+
version:
|
|
25
|
+
platform: ruby
|
|
26
|
+
signing_key:
|
|
27
|
+
cert_chain:
|
|
28
|
+
post_install_message:
|
|
29
|
+
authors:
|
|
30
|
+
- Stephen Bartholomew
|
|
31
|
+
files:
|
|
32
|
+
- bin
|
|
33
|
+
- example
|
|
34
|
+
- lib
|
|
35
|
+
- RakeFile
|
|
36
|
+
- README
|
|
37
|
+
- test
|
|
38
|
+
- bin/staticmatic
|
|
39
|
+
- example/site
|
|
40
|
+
- example/src
|
|
41
|
+
- example/site/contact.html
|
|
42
|
+
- example/site/images
|
|
43
|
+
- example/site/index.html
|
|
44
|
+
- example/site/javascripts
|
|
45
|
+
- example/site/stylesheets
|
|
46
|
+
- example/site/stylesheets/application.css
|
|
47
|
+
- example/src/layouts
|
|
48
|
+
- example/src/pages
|
|
49
|
+
- example/src/stylesheets
|
|
50
|
+
- example/src/layouts/application.haml
|
|
51
|
+
- example/src/pages/contact.haml
|
|
52
|
+
- example/src/pages/index.haml
|
|
53
|
+
- example/src/stylesheets/application.sass
|
|
54
|
+
- lib/staticmatic
|
|
55
|
+
- lib/staticmatic.rb
|
|
56
|
+
- lib/staticmatic/helpers.rb
|
|
57
|
+
- lib/staticmatic/templates
|
|
58
|
+
- lib/staticmatic/templates/application.haml
|
|
59
|
+
- lib/staticmatic/templates/application.sass
|
|
60
|
+
- lib/staticmatic/templates/index.haml
|
|
61
|
+
- test/sandbox
|
|
62
|
+
- test/staticmatic_test.rb
|
|
63
|
+
test_files:
|
|
64
|
+
- test/staticmatic_test.rb
|
|
65
|
+
rdoc_options: []
|
|
66
|
+
|
|
67
|
+
extra_rdoc_files: []
|
|
68
|
+
|
|
69
|
+
executables:
|
|
70
|
+
- staticmatic
|
|
71
|
+
extensions: []
|
|
72
|
+
|
|
73
|
+
requirements: []
|
|
74
|
+
|
|
75
|
+
dependencies:
|
|
76
|
+
- !ruby/object:Gem::Dependency
|
|
77
|
+
name: haml
|
|
78
|
+
version_requirement:
|
|
79
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">"
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: 0.0.0
|
|
84
|
+
version:
|