staticmatic2 2.0.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/Gemfile +12 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +20 -0
- data/README.markdown +107 -0
- data/Rakefile +45 -0
- data/VERSION.yml +5 -0
- data/bin/staticmatic +140 -0
- data/lib/staticmatic.rb +25 -0
- data/lib/staticmatic/base.rb +123 -0
- data/lib/staticmatic/compass.rb +5 -0
- data/lib/staticmatic/compass/app_integration.rb +18 -0
- data/lib/staticmatic/compass/configuration_defaults.rb +44 -0
- data/lib/staticmatic/compass/installer.rb +15 -0
- data/lib/staticmatic/configuration.rb +20 -0
- data/lib/staticmatic/deployers/aws-s3.rb +71 -0
- data/lib/staticmatic/deployers/config/amazon.yml +7 -0
- data/lib/staticmatic/error.rb +17 -0
- data/lib/staticmatic/helpers.rb +12 -0
- data/lib/staticmatic/helpers/assets_helper.rb +116 -0
- data/lib/staticmatic/helpers/current_path_helper.rb +22 -0
- data/lib/staticmatic/helpers/form_helper.rb +23 -0
- data/lib/staticmatic/helpers/render_helper.rb +13 -0
- data/lib/staticmatic/helpers/tag_helper.rb +35 -0
- data/lib/staticmatic/helpers/url_helper.rb +59 -0
- data/lib/staticmatic/mixins/build.rb +77 -0
- data/lib/staticmatic/mixins/helpers.rb +15 -0
- data/lib/staticmatic/mixins/render.rb +153 -0
- data/lib/staticmatic/mixins/rescue.rb +12 -0
- data/lib/staticmatic/mixins/server.rb +7 -0
- data/lib/staticmatic/mixins/setup.rb +16 -0
- data/lib/staticmatic/server.rb +86 -0
- data/lib/staticmatic/template_error.rb +44 -0
- data/lib/staticmatic/templates/rescues/default.haml +7 -0
- data/lib/staticmatic/templates/rescues/template.haml +18 -0
- data/spec/base_spec.rb +13 -0
- data/spec/compass_integration_spec.rb +27 -0
- data/spec/helpers/asset_helper_spec.rb +43 -0
- data/spec/helpers/custom_helper_spec.rb +18 -0
- data/spec/render_spec.rb +44 -0
- data/spec/rescue_spec.rb +36 -0
- data/spec/sandbox/test_site/config/compass.rb +1 -0
- data/spec/sandbox/test_site/config/site.rb +0 -0
- data/spec/sandbox/test_site/src/helpers/application_helper.rb +5 -0
- data/spec/sandbox/test_site/src/layouts/alternate_layout.haml +3 -0
- data/spec/sandbox/test_site/src/layouts/default.haml +7 -0
- data/spec/sandbox/test_site/src/layouts/projects.haml +1 -0
- data/spec/sandbox/test_site/src/pages/hello_world.erb +1 -0
- data/spec/sandbox/test_site/src/pages/index.haml +5 -0
- data/spec/sandbox/test_site/src/pages/layout_test.haml +2 -0
- data/spec/sandbox/test_site/src/pages/page_one.haml +3 -0
- data/spec/sandbox/test_site/src/pages/page_two.haml +2 -0
- data/spec/sandbox/test_site/src/pages/page_with_error.haml +5 -0
- data/spec/sandbox/test_site/src/pages/page_with_partial_error.haml +3 -0
- data/spec/sandbox/test_site/src/partials/menu.haml +1 -0
- data/spec/sandbox/test_site/src/partials/partial_with_error.haml +1 -0
- data/spec/sandbox/test_site/src/stylesheets/application.sass +5 -0
- data/spec/sandbox/test_site/src/stylesheets/css_with_error.sass +5 -0
- data/spec/sandbox/test_site/src/stylesheets/nested/a_nested_stylesheet.sass +0 -0
- data/spec/sandbox/test_site/src/stylesheets/partials/_forms.sass +2 -0
- data/spec/sandbox/test_site/src/stylesheets/sassy.scss +12 -0
- data/spec/server_spec.rb +11 -0
- data/spec/setup_spec.rb +22 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/template_error_spec.rb +23 -0
- data/staticmatic.gemspec +158 -0
- data/website/Gemfile +1 -0
- data/website/config/site.rb +17 -0
- data/website/site/docs/compass_integration.html +70 -0
- data/website/site/docs/getting_started.html +49 -0
- data/website/site/docs/helpers.html +22 -0
- data/website/site/images/bycurve21.gif +0 -0
- data/website/site/images/curve21.jpg +0 -0
- data/website/site/images/homepage-build.jpg +0 -0
- data/website/site/images/homepage-previewing.jpg +0 -0
- data/website/site/images/homepage-templating.jpg +0 -0
- data/website/site/stylesheets/ie.css +5 -0
- data/website/site/stylesheets/print.css +372 -0
- data/website/site/stylesheets/screen.css +488 -0
- data/website/src/helpers/content_helper.rb +10 -0
- data/website/src/layouts/default.haml +15 -0
- data/website/src/pages/development.haml +9 -0
- data/website/src/pages/docs/_menu.haml +4 -0
- data/website/src/pages/docs/_requires_prerelease.haml +4 -0
- data/website/src/pages/docs/compass_integration.haml +54 -0
- data/website/src/pages/docs/getting_started.haml +31 -0
- data/website/src/pages/docs/helpers.haml +1 -0
- data/website/src/pages/index.haml +27 -0
- data/website/src/stylesheets/_base.scss +43 -0
- data/website/src/stylesheets/_defaults.scss +260 -0
- data/website/src/stylesheets/ie.scss +10 -0
- data/website/src/stylesheets/print.scss +33 -0
- data/website/src/stylesheets/screen.scss +73 -0
- metadata +238 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
compass (0.10.6)
|
|
5
|
+
haml (>= 3.0.4)
|
|
6
|
+
git (1.2.5)
|
|
7
|
+
haml (3.0.25)
|
|
8
|
+
jeweler (1.5.2)
|
|
9
|
+
bundler (~> 1.0.0)
|
|
10
|
+
git (>= 1.2.5)
|
|
11
|
+
rake
|
|
12
|
+
rack (1.2.1)
|
|
13
|
+
rake (0.8.7)
|
|
14
|
+
rspec (1.3.1)
|
|
15
|
+
thor (0.14.6)
|
|
16
|
+
|
|
17
|
+
PLATFORMS
|
|
18
|
+
ruby
|
|
19
|
+
|
|
20
|
+
DEPENDENCIES
|
|
21
|
+
bundler (>= 1.0.10)
|
|
22
|
+
compass
|
|
23
|
+
haml (>= 2.0.0)
|
|
24
|
+
jeweler (>= 1.5.2)
|
|
25
|
+
rack (>= 1.0)
|
|
26
|
+
rspec (~> 1.3.1)
|
|
27
|
+
thor (>= 0.14.6)
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (C) 2009 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.
|
data/README.markdown
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# StaticMatic: Build and Deploy
|
|
2
|
+
|
|
3
|
+
Build static websites using modern dynamic tools:
|
|
4
|
+
|
|
5
|
+
- [Haml](http://haml-lang.com/)
|
|
6
|
+
- [Sass](http://sass-lang.com/)
|
|
7
|
+
- [Coffeescript](http://jashkenas.github.com/coffee-script/)
|
|
8
|
+
- [Compass](compass-style.org)
|
|
9
|
+
- And more to come.
|
|
10
|
+
|
|
11
|
+
And deploy to Amazon S3:
|
|
12
|
+
|
|
13
|
+
$ staticmatic s3_deploy
|
|
14
|
+
|
|
15
|
+
In other words:
|
|
16
|
+
|
|
17
|
+
StaticMatic build StaticMatic deploy
|
|
18
|
+
src/ ==> build/ ==> mywebsite.com/
|
|
19
|
+
index.haml ==> index.html ==> index.html
|
|
20
|
+
style.sass ==> style.css ==> style.css
|
|
21
|
+
js/ ==> js/ ==> js/
|
|
22
|
+
app.coffee ==> app.js ==> app.js
|
|
23
|
+
img/ ==> img/ ==> img/
|
|
24
|
+
logo.png ==> logo.png ==> logo.png
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
Instantly setup a new project:
|
|
29
|
+
|
|
30
|
+
$ staticmatic init my-project
|
|
31
|
+
|
|
32
|
+
This will give you a basic skeleton:
|
|
33
|
+
|
|
34
|
+
my-project/
|
|
35
|
+
src/
|
|
36
|
+
_layouts/
|
|
37
|
+
default.haml
|
|
38
|
+
_partials/
|
|
39
|
+
example.haml
|
|
40
|
+
index.haml
|
|
41
|
+
|
|
42
|
+
Preview your static website:
|
|
43
|
+
|
|
44
|
+
$ cd my-project
|
|
45
|
+
$ staticmatic preview
|
|
46
|
+
Site root is: .
|
|
47
|
+
StaticMatic Preview Server
|
|
48
|
+
Ctrl+C to exit
|
|
49
|
+
...
|
|
50
|
+
|
|
51
|
+
Visit http://localhost:3000 to view your website in action.
|
|
52
|
+
|
|
53
|
+
When you're ready to deploy, convert your haml/sass/whatever files into plain html, css, and javascript:
|
|
54
|
+
|
|
55
|
+
staticmatic build
|
|
56
|
+
|
|
57
|
+
This will convert everything into a freshly generated `build/` folder, all ready to deploy!
|
|
58
|
+
|
|
59
|
+
## Special Folders
|
|
60
|
+
|
|
61
|
+
<my-project>/
|
|
62
|
+
src/
|
|
63
|
+
_layouts/
|
|
64
|
+
_partials/
|
|
65
|
+
|
|
66
|
+
- The `_layouts` folder is where layout files will be searched for. These files must contain a `yield` statement.
|
|
67
|
+
|
|
68
|
+
- The `_partials` folder is the last place partial files will be searched for. Any partial in this folder should not be prefixed with an underscore _
|
|
69
|
+
|
|
70
|
+
*USEFUL:* Any file or folder prefixed with an underscore _ will not be copied into the generated `site/` folder, nor will they be converted by haml, coffeescript, etc
|
|
71
|
+
|
|
72
|
+
## Partials
|
|
73
|
+
|
|
74
|
+
Partials are searched for in the following order:
|
|
75
|
+
|
|
76
|
+
- The file's current directory (the file must be prefixed with an underscore in this case)
|
|
77
|
+
- `src/_partials/`
|
|
78
|
+
|
|
79
|
+
Examples:
|
|
80
|
+
|
|
81
|
+
# Searches for the default rendering engine file type
|
|
82
|
+
= partial 'sidebar'
|
|
83
|
+
|
|
84
|
+
# Equivalent to the above statement
|
|
85
|
+
= partial 'sidebar.haml'
|
|
86
|
+
|
|
87
|
+
# Directly inserts html file
|
|
88
|
+
= partial 'help-content.html'
|
|
89
|
+
|
|
90
|
+
# Use your own directory structure
|
|
91
|
+
= partial 'blog-content/2011/vacation.html'
|
|
92
|
+
|
|
93
|
+
## Anti-Cache
|
|
94
|
+
|
|
95
|
+
Force the browser to ignore its cache whenever you damn well feel like it:
|
|
96
|
+
|
|
97
|
+
# Creates a query string based on the current unix time
|
|
98
|
+
stylesheets :menu, :form, :qstring => true
|
|
99
|
+
|
|
100
|
+
<link href="/css/menu.css?_=1298789103" media="all" rel="stylesheet" type="text/css"/>
|
|
101
|
+
<link href="/css/form.css?_=1298789103" media="all" rel="stylesheet" type="text/css"/>
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# Or, use your own qstring
|
|
105
|
+
javascripts :app, :qstring => '2.0.6'
|
|
106
|
+
|
|
107
|
+
<script language="javascript" src="js/app.js?_=2.0.6" type="text/javascript"></script>
|
data/Rakefile
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# require 'psych'
|
|
2
|
+
require 'bundler'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
Bundler.setup(:default, :development)
|
|
6
|
+
rescue Bundler::BundlerError => e
|
|
7
|
+
$stderr.puts e.message
|
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
9
|
+
exit e.status_code
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# require 'rake'
|
|
13
|
+
require 'jeweler'
|
|
14
|
+
require 'spec/rake/spectask'
|
|
15
|
+
require File.expand_path("../lib/staticmatic", __FILE__)
|
|
16
|
+
|
|
17
|
+
Jeweler::Tasks.new do |gem|
|
|
18
|
+
gem.name = "staticmatic2"
|
|
19
|
+
gem.email = "gilbertbgarza@gmail.com"
|
|
20
|
+
gem.license = "MIT"
|
|
21
|
+
gem.summary = "Build static websites using modern dynamic tools"
|
|
22
|
+
gem.homepage = "http://github.com/mindeavor/staticmatic"
|
|
23
|
+
gem.executables = "staticmatic"
|
|
24
|
+
gem.authors = ["Stephen Bartholomew", "Gilbert B Garza"]
|
|
25
|
+
|
|
26
|
+
gem.description = <<-EOF
|
|
27
|
+
StaticMatic helps you quickly create maintainable static websites using
|
|
28
|
+
tools such as Haml and Sass.
|
|
29
|
+
|
|
30
|
+
Quickly deploy to services such as Amazon S3 in a single command.
|
|
31
|
+
EOF
|
|
32
|
+
|
|
33
|
+
gem.rubyforge_project = "staticmatic2"
|
|
34
|
+
|
|
35
|
+
gem.files.include "[A-Z]*", "{bin,lib,spec}/**/*"
|
|
36
|
+
gem.files.exclude "spec/sandbox/tmp", "spec/sandbox/test_site/site/*"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Jeweler::RubygemsDotOrgTasks.new
|
|
40
|
+
|
|
41
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
42
|
+
spec.libs << 'lib' << 'spec'
|
|
43
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
44
|
+
# spec.spec_opts = ['--options', 'spec/spec.opts']
|
|
45
|
+
end
|
data/VERSION.yml
ADDED
data/bin/staticmatic
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'thor'
|
|
5
|
+
lib_dir = File.dirname(__FILE__) + '/../lib/staticmatic'
|
|
6
|
+
require lib_dir
|
|
7
|
+
Dir[File.join lib_dir,'deployers','*.rb'].each do |deployer|
|
|
8
|
+
require deployer
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Skeletons directly taken from Monk (https://github.com/monkrb/monk). Thanks Monk!
|
|
12
|
+
class StaticExe < Thor
|
|
13
|
+
include Thor::Actions
|
|
14
|
+
|
|
15
|
+
[:skip, :pretend, :force, :quiet].each do |task|
|
|
16
|
+
class_options.delete task
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# functions related to initializing a project
|
|
20
|
+
|
|
21
|
+
desc "one", "two"
|
|
22
|
+
def one_two
|
|
23
|
+
puts 'one two'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
desc "init", "Initialize a static directory structure"
|
|
27
|
+
method_option :skeleton, :type => :string, :aliases => "-s"
|
|
28
|
+
def init(target = ".")
|
|
29
|
+
clone(source(options[:skeleton] || "default") || options[:skeleton], target) ?
|
|
30
|
+
cleanup(target) :
|
|
31
|
+
say_status(:error, clone_error(target))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
desc "show NAME", "Display the repository address for NAME"
|
|
35
|
+
def show(name)
|
|
36
|
+
say_status name, source(name) || "repository not found"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
desc "list", "Lists the configured repositories"
|
|
40
|
+
def list
|
|
41
|
+
sm_config.keys.sort.each do |key|
|
|
42
|
+
show(key)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "add NAME REPOSITORY", "Add the repository to the configuration file"
|
|
47
|
+
def add(name, repository)
|
|
48
|
+
sm_config[name] = repository
|
|
49
|
+
write_sm_config_file
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
desc "rm NAME", "Remove the repository from the configuration file"
|
|
53
|
+
def rm(name)
|
|
54
|
+
sm_config.delete(name)
|
|
55
|
+
write_sm_config_file
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Previewing and building an existing project
|
|
59
|
+
|
|
60
|
+
desc "preview DIRECTORY", "Start a web server to preview your project"
|
|
61
|
+
def preview(directory = '.')
|
|
62
|
+
say 'Launching preview server...', :cyan
|
|
63
|
+
staticmatic = StaticMatic::Base.new(directory)
|
|
64
|
+
$:.push File.join(directory, "lib")
|
|
65
|
+
staticmatic.run('preview')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc "build DIRECTORY", "Build your project into a freshly generated build/ folder"
|
|
69
|
+
def build(directory = '.')
|
|
70
|
+
say 'Building website...', :cyan
|
|
71
|
+
staticmatic = StaticMatic::Base.new(directory)
|
|
72
|
+
$:.push File.join(directory, "lib")
|
|
73
|
+
staticmatic.run('build')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def lib_path(*paths)
|
|
79
|
+
File.join(File.dirname(__FILE__) + '/../lib/staticmatic', *paths)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def site_path(directory,*paths)
|
|
83
|
+
File.join(directory, 'build', *paths)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def clone(source, target)
|
|
87
|
+
if Dir["#{target}/*"].empty?
|
|
88
|
+
say_status :fetching, source
|
|
89
|
+
system "git clone -q --depth 1 #{source} #{target}"
|
|
90
|
+
$?.success?
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def cleanup(target)
|
|
95
|
+
inside(target) { remove_file ".git" }
|
|
96
|
+
say_status :initialized, target
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def source(name = "default")
|
|
100
|
+
sm_config[name]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def sm_config_file
|
|
104
|
+
@sm_config_file ||= File.join(sm_home, ".staticmatic")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def sm_config
|
|
108
|
+
@sm_config ||= begin
|
|
109
|
+
write_sm_config_file unless File.exists?(sm_config_file)
|
|
110
|
+
YAML.load_file(sm_config_file)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def write_sm_config_file
|
|
115
|
+
remove_file(sm_config_file, :verbose => false)
|
|
116
|
+
create_file(sm_config_file, nil, :verbose => false) do
|
|
117
|
+
config = @sm_config || { "default" => "git://github.com/mindeavor/staticmatic-basic.git" }
|
|
118
|
+
config.to_yaml
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def self.source_root
|
|
123
|
+
"."
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def clone_error(target)
|
|
127
|
+
"Couldn't clone repository into target directory '#{target}'. " +
|
|
128
|
+
"You must have git installed and the target directory must be empty."
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def sm_home
|
|
132
|
+
ENV["STATICMATIC_HOME"] || File.join(Thor::Util.user_home)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
if File.exists?("Thorfile")
|
|
137
|
+
load("Thorfile")
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
StaticExe.start
|
data/lib/staticmatic.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'compass'
|
|
3
|
+
require 'haml'
|
|
4
|
+
require 'sass'
|
|
5
|
+
require 'sass/plugin'
|
|
6
|
+
require 'rack'
|
|
7
|
+
require 'rack/handler/webrick'
|
|
8
|
+
require 'cgi'
|
|
9
|
+
require 'fileutils'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module StaticMatic
|
|
13
|
+
VERSION = "0.11.0"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
["render", "build", "setup", "server", "helpers", "rescue"].each do |mixin|
|
|
17
|
+
require File.join(File.dirname(__FILE__), "staticmatic", "mixins", mixin)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
["base", "configuration", "error", "server", "helpers", "template_error", "compass"].each do |lib|
|
|
21
|
+
require File.join(File.dirname(__FILE__), "staticmatic", lib)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Haml::Helpers.class_eval("include StaticMatic::Helpers")
|
|
25
|
+
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
module StaticMatic
|
|
2
|
+
class Base
|
|
3
|
+
|
|
4
|
+
include StaticMatic::RenderMixin
|
|
5
|
+
include StaticMatic::BuildMixin
|
|
6
|
+
include StaticMatic::SetupMixin
|
|
7
|
+
include StaticMatic::HelpersMixin
|
|
8
|
+
include StaticMatic::ServerMixin
|
|
9
|
+
include StaticMatic::RescueMixin
|
|
10
|
+
|
|
11
|
+
attr_accessor :configuration
|
|
12
|
+
attr_reader :current_page, :src_dir, :site_dir
|
|
13
|
+
|
|
14
|
+
def current_file
|
|
15
|
+
@current_file_stack[0] || ""
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def initialize(base_dir, configuration = Configuration.new)
|
|
19
|
+
@configuration = configuration
|
|
20
|
+
@current_page = nil
|
|
21
|
+
@current_file_stack = []
|
|
22
|
+
@base_dir = base_dir
|
|
23
|
+
@src_dir = File.join(@base_dir, "src")
|
|
24
|
+
@site_dir = File.join(@base_dir, "build")
|
|
25
|
+
|
|
26
|
+
if File.exists?(File.join(@src_dir, "_layouts", "application.haml"))
|
|
27
|
+
puts "DEPRECATION: _layouts/application.haml will be renamed to _layouts/default.haml in 0.12.0"
|
|
28
|
+
@default_layout = "application"
|
|
29
|
+
else
|
|
30
|
+
@default_layout = "default"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
@scope = Object.new
|
|
34
|
+
@scope.instance_variable_set("@staticmatic", self)
|
|
35
|
+
|
|
36
|
+
load_configuration
|
|
37
|
+
configure_compass
|
|
38
|
+
|
|
39
|
+
load_helpers
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def load_configuration
|
|
43
|
+
configuration = StaticMatic::Configuration.new
|
|
44
|
+
config_file = File.join(@base_dir, "config", "site.rb")
|
|
45
|
+
|
|
46
|
+
if !File.exists?(config_file)
|
|
47
|
+
config_file = File.join(@base_dir, "src", "configuration.rb")
|
|
48
|
+
|
|
49
|
+
if File.exists?(config_file)
|
|
50
|
+
puts "DEPRECATION: #{@base_dir}/src/configuration.rb will be moved to #{@base_dir}/config/site.rb in 0.12.0"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if File.exists?(config_file)
|
|
55
|
+
config = File.read(config_file)
|
|
56
|
+
eval(config)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Compass.sass_engine_options.merge!(configuration.sass_options)
|
|
60
|
+
@configuration = configuration
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def base_dir
|
|
64
|
+
@base_dir
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def run(command)
|
|
68
|
+
puts "Site root is: #{@base_dir}"
|
|
69
|
+
|
|
70
|
+
if %w(build setup preview).include?(command)
|
|
71
|
+
send(command)
|
|
72
|
+
else
|
|
73
|
+
puts "#{command} is not a valid StaticMatic command"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# TODO: DRY this _exists? section up
|
|
78
|
+
def template_exists?(name, ext, dir = '')
|
|
79
|
+
if ext == 'html'
|
|
80
|
+
src_file_names('haml').include? "#{name}.haml"
|
|
81
|
+
elsif ext == 'css'
|
|
82
|
+
(src_file_names('sass').include? "#{name}.sass") ||
|
|
83
|
+
(src_file_names('scss').include? "#{name}.scss")
|
|
84
|
+
elsif ext == 'js'
|
|
85
|
+
src_file_names('coffee').include? "#{name}.coffee"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def layout_exists?(name)
|
|
90
|
+
File.exists? full_layout_path(name)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def full_layout_path(name)
|
|
94
|
+
File.join(@src_dir, "_layouts", "#{name}.haml")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def configure_compass
|
|
98
|
+
Compass.configuration.project_path = @base_dir
|
|
99
|
+
|
|
100
|
+
compass_config_path = File.join(@base_dir, "config", "compass.rb")
|
|
101
|
+
|
|
102
|
+
if File.exists?(compass_config_path)
|
|
103
|
+
Compass.add_configuration(compass_config_path)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
configuration.sass_options.merge!(Compass.configuration.to_sass_engine_options)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# TODO OPTIMIZE: caching, maybe?
|
|
110
|
+
def src_file_paths(*exts)
|
|
111
|
+
Dir["#{@src_dir}/**/*.{#{ exts.join(',') }}"].reject do |path|
|
|
112
|
+
# reject any files with a prefixed underscore, as
|
|
113
|
+
# well as any files in a folder with a prefixed underscore
|
|
114
|
+
path.split('/').map {|x| x.match('^\_')}.any?
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def src_file_names(*exts)
|
|
119
|
+
src_file_paths(*exts).map {|p| File.split(p)[1]}
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
end
|