staticmatic3 2.1.9
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.
- checksums.yaml +7 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +20 -0
- data/README.md +154 -0
- data/Rakefile +45 -0
- data/VERSION.yml +5 -0
- data/bin/staticmatic +142 -0
- data/lib/staticmatic.rb +22 -0
- data/lib/staticmatic/ambiguous_template_error.rb +19 -0
- data/lib/staticmatic/base.rb +149 -0
- data/lib/staticmatic/compass.rb +5 -0
- data/lib/staticmatic/compass/app_integration.rb +21 -0
- data/lib/staticmatic/compass/configuration_defaults.rb +44 -0
- data/lib/staticmatic/compass/installer.rb +15 -0
- data/lib/staticmatic/configuration.rb +56 -0
- data/lib/staticmatic/deployers/aws-s3.rb +108 -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 +14 -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 +41 -0
- data/lib/staticmatic/mixins/helpers.rb +15 -0
- data/lib/staticmatic/mixins/render.rb +110 -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 +87 -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 +28 -0
- data/spec/helpers/asset_helper_spec.rb +41 -0
- data/spec/helpers/custom_helper_spec.rb +17 -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/site/sub_folder/another_sub_folder/index.html +1 -0
- data/spec/sandbox/test_site/site/sub_folder/another_sub_folder/index.html.html +1 -0
- data/spec/sandbox/test_site/site/sub_folder/index.html +1 -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/_partials/menu.haml +1 -0
- data/spec/sandbox/test_site/src/_partials/partial_with_error.haml +1 -0
- data/spec/sandbox/test_site/src/hello_world.erb +1 -0
- data/spec/sandbox/test_site/src/index.haml +5 -0
- data/spec/sandbox/test_site/src/layout_test.haml +2 -0
- data/spec/sandbox/test_site/src/page_one.haml +3 -0
- data/spec/sandbox/test_site/src/page_two.haml +2 -0
- data/spec/sandbox/test_site/src/page_with_error.haml +5 -0
- data/spec/sandbox/test_site/src/page_with_partial_error.haml +3 -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/spec_helper.rb +14 -0
- data/spec/template_error_spec.rb +23 -0
- data/staticmatic.gemspec +158 -0
- data/staticmatic3.gemspec +164 -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 +285 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
module StaticMatic::RescueMixin
|
2
|
+
# Pass back an error template for the given exception
|
3
|
+
def render_rescue_from_error(exception)
|
4
|
+
rescue_template = (exception.is_a?(StaticMatic::TemplateError)) ? "template" : "default"
|
5
|
+
|
6
|
+
error_template_path = File.expand_path(File.dirname(__FILE__) + "/../templates/rescues/#{rescue_template}.haml")
|
7
|
+
|
8
|
+
@scope.instance_variable_set("@exception", exception)
|
9
|
+
|
10
|
+
render_template(error_template_path)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module StaticMatic::SetupMixin
|
2
|
+
|
3
|
+
def setup
|
4
|
+
Dir.mkdir(@base_dir) unless File.exists?(@base_dir)
|
5
|
+
|
6
|
+
Dir[File.join(File.dirname(__FILE__), "..", "templates", "project", "*")].each do |template|
|
7
|
+
begin
|
8
|
+
FileUtils.cp_r(template, @base_dir)
|
9
|
+
rescue Errno::EEXIST
|
10
|
+
# ignore - template exists
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
puts "Done"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module StaticMatic
|
2
|
+
class Server
|
3
|
+
def initialize(staticmatic, default = nil)
|
4
|
+
@files = default || Rack::File.new(staticmatic.src_dir)
|
5
|
+
@staticmatic = staticmatic
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
@staticmatic.load_helpers
|
10
|
+
path_info = env["PATH_INFO"]
|
11
|
+
|
12
|
+
file_dir, file_name, file_ext = @staticmatic.expand_path(path_info)
|
13
|
+
|
14
|
+
file_dir = CGI::unescape(file_dir)
|
15
|
+
file_name = CGI::unescape(file_name)
|
16
|
+
|
17
|
+
unless file_ext && ["html", "css", "js"].include?(file_ext) &&
|
18
|
+
File.basename(file_name) !~ /^\_/ &&
|
19
|
+
(template_path = @staticmatic.determine_template_path file_name, file_ext, file_dir)
|
20
|
+
return @files.call(env)
|
21
|
+
end
|
22
|
+
|
23
|
+
res = Rack::Response.new
|
24
|
+
|
25
|
+
begin
|
26
|
+
@staticmatic.clear_template_variables!
|
27
|
+
|
28
|
+
if file_ext == "css"
|
29
|
+
res.header["Content-Type"] = "text/css"
|
30
|
+
res.write @staticmatic.render_template(template_path)
|
31
|
+
elsif file_ext == "js"
|
32
|
+
res.header["Content-Type"] = "text/javascript"
|
33
|
+
res.write @staticmatic.render_template(template_path)
|
34
|
+
else
|
35
|
+
res.header["Content-Type"] = "text/html"
|
36
|
+
res.write @staticmatic.render_template_with_layout(template_path)
|
37
|
+
end
|
38
|
+
rescue StaticMatic::Error => e
|
39
|
+
res.write e.message
|
40
|
+
end
|
41
|
+
|
42
|
+
res.finish
|
43
|
+
end
|
44
|
+
|
45
|
+
# Starts the StaticMatic preview server
|
46
|
+
def self.start(staticmatic)
|
47
|
+
[ 'INT', 'TERM' ].each do |signal|
|
48
|
+
Signal.trap(signal) do
|
49
|
+
puts
|
50
|
+
puts "Exiting"
|
51
|
+
exit!(0)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
port = staticmatic.configuration.preview_server_port || 3000
|
55
|
+
|
56
|
+
host = staticmatic.configuration.preview_server_host || ""
|
57
|
+
|
58
|
+
app = Rack::Builder.new do
|
59
|
+
use Rack::ShowExceptions
|
60
|
+
run StaticMatic::Server.new(staticmatic)
|
61
|
+
end
|
62
|
+
|
63
|
+
ssl_enable = staticmatic.configuration.ssl_enable || false
|
64
|
+
|
65
|
+
if not ssl_enable
|
66
|
+
staticmatic.configuration.preview_server.run(app, :Port => port, :Host => host)
|
67
|
+
else
|
68
|
+
ssl_verify_client = OpenSSL::SSL::VERIFY_NONE
|
69
|
+
ssl_private_key = OpenSSL::PKey::RSA.new(File.open(staticmatic.configuration.ssl_private_key_path).read)
|
70
|
+
ssl_certificate = OpenSSL::X509::Certificate.new(File.open(staticmatic.configuration.ssl_certificate_path).read)
|
71
|
+
ssl_cert_name = [["CN", WEBrick::Utils::getservername]]
|
72
|
+
staticmatic.configuration.preview_server.run(
|
73
|
+
app,
|
74
|
+
:Port => port,
|
75
|
+
:Host => host,
|
76
|
+
:SSLEnable => true,
|
77
|
+
:SSLPrivateKey => ssl_private_key,
|
78
|
+
:SSLCertificate => ssl_certificate,
|
79
|
+
:SSLCertName => ssl_cert_name
|
80
|
+
)
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class StaticMatic::TemplateError < StandardError
|
2
|
+
SOURCE_CODE_RADIUS = 3
|
3
|
+
|
4
|
+
attr_reader :original_exception, :backtrace
|
5
|
+
|
6
|
+
def initialize(template, original_exception)
|
7
|
+
@template, @original_exception = template, original_exception
|
8
|
+
@backtrace = original_exception.backtrace
|
9
|
+
|
10
|
+
if template
|
11
|
+
@source = File.read(template)
|
12
|
+
else
|
13
|
+
@source = ""
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: Replace 'haml|sass' with any registered engines
|
18
|
+
def line_number
|
19
|
+
@line_number ||= $2 if backtrace.find { |line| line =~ /\((haml|sass|scss)\)\:(\d+)/ }
|
20
|
+
end
|
21
|
+
|
22
|
+
def filename
|
23
|
+
@template
|
24
|
+
end
|
25
|
+
|
26
|
+
def source_extract(indentation = 0)
|
27
|
+
return "" unless num = line_number
|
28
|
+
num = num.to_i
|
29
|
+
|
30
|
+
source_code = @source.split("\n")
|
31
|
+
|
32
|
+
start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
|
33
|
+
end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
|
34
|
+
|
35
|
+
indent = ' ' * indentation
|
36
|
+
line_counter = start_on_line
|
37
|
+
return unless source_code = source_code[start_on_line..end_on_line]
|
38
|
+
|
39
|
+
source_code.collect do |line|
|
40
|
+
line_counter += 1
|
41
|
+
"#{indent}#{line_counter}: #{line}\n"
|
42
|
+
end.to_s
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
%html
|
2
|
+
%head
|
3
|
+
%style{:type => "text/css"}
|
4
|
+
body { font-family: helvetica, verdana, arial; font-size: 10pt;}
|
5
|
+
%body
|
6
|
+
%h1
|
7
|
+
= @exception.class.name
|
8
|
+
in
|
9
|
+
= @exception.filename
|
10
|
+
|
11
|
+
%p= @exception.original_exception.message
|
12
|
+
|
13
|
+
= @exception.source_extract.gsub(/\n/, "<br/>")
|
14
|
+
|
15
|
+
|
16
|
+
%h2 Backtrace
|
17
|
+
|
18
|
+
= @exception.backtrace.join("<br/>")
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "StaticMatic::Base" do
|
4
|
+
before do
|
5
|
+
setup_staticmatic
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should set initial configuration settings" do
|
9
|
+
@staticmatic.configuration.use_extensions_for_page_links.should == true
|
10
|
+
@staticmatic.configuration.preview_server_port.should == 3000
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Compass integration" do
|
4
|
+
context "with the default staticmatic configuration" do
|
5
|
+
before do
|
6
|
+
setup_staticmatic
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should configure compass" do
|
10
|
+
pending "Compass config not quite right yet"
|
11
|
+
Compass.configuration.project_path.should == TEST_SITE_PATH
|
12
|
+
Compass.configuration.sass_dir.should == File.join("src", "stylesheets")
|
13
|
+
Compass.configuration.css_dir.should == File.join("site", "stylesheets")
|
14
|
+
Compass.configuration.images_dir.should == File.join("site", "images")
|
15
|
+
Compass.configuration.http_images_path.should == "images"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with a custom configuration" do
|
20
|
+
before do
|
21
|
+
setup_staticmatic
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should allow site config to override defaults" do
|
25
|
+
Compass.configuration.http_path.should == "http://a.test.host"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe "Helpers:" do
|
5
|
+
include StaticMatic::Helpers::AssetsHelper
|
6
|
+
include StaticMatic::Helpers::CurrentPathHelper
|
7
|
+
include StaticMatic::Helpers::TagHelper
|
8
|
+
before do
|
9
|
+
setup_staticmatic
|
10
|
+
end
|
11
|
+
|
12
|
+
context "When using the stylesheet helper" do
|
13
|
+
before do
|
14
|
+
@links = stylesheets
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set up links for all stylesheets" do
|
18
|
+
@links.should match(/stylesheets\/application\.css/)
|
19
|
+
@links.should match(/stylesheets\/nested\/a_nested_stylesheet\.css/)
|
20
|
+
@links.should match(/stylesheets\/sassy\.css/)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not link to partials" do
|
24
|
+
@links.should_not match(/\_forms.css/)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should setup links for specified stylesheets" do
|
28
|
+
stylesheets(:sassy).should match(/stylesheets\/sassy\.css/)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "When using the stylesheet helper from a sub page" do
|
33
|
+
before do
|
34
|
+
@links = stylesheets
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should link relative to current page" do
|
38
|
+
@links.should match(/\.\.\/stylesheets/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe "Helpers:" do
|
5
|
+
include StaticMatic::Helpers::AssetsHelper
|
6
|
+
include StaticMatic::Helpers::CurrentPathHelper
|
7
|
+
include StaticMatic::Helpers::TagHelper
|
8
|
+
before do
|
9
|
+
setup_staticmatic
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should include custom helper" do
|
13
|
+
content = @staticmatic.generate_html_with_layout("index")
|
14
|
+
content.should match(/Hello, Steve!/)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/render_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "StaticMatic::Render" do
|
4
|
+
before do
|
5
|
+
setup_staticmatic
|
6
|
+
end
|
7
|
+
|
8
|
+
it "generate content with a layout" do
|
9
|
+
content = @staticmatic.generate_html_with_layout("index")
|
10
|
+
content.should match(/StaticMatic/)
|
11
|
+
content.should match(/This is some test content/)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "generate html with layout assigned in template" do
|
15
|
+
content = @staticmatic.generate_html_with_layout("layout_test")
|
16
|
+
content.should match(/Alternate Layout/)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "generate css" do
|
20
|
+
content = @staticmatic.generate_css("stylesheets/application")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "find source filename from path" do
|
24
|
+
@staticmatic.source_template_from_path("@base_dir/src/stylesheets/application.css")[1].should == "application"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "find layout from passed path" do
|
28
|
+
@staticmatic.determine_layout("test/projects").should == "projects"
|
29
|
+
end
|
30
|
+
|
31
|
+
context "handling scss" do
|
32
|
+
it "should generate css from scss" do
|
33
|
+
@staticmatic.generate_css("stylesheets/sassy").should match(/color\: \#3bbfce\;/)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should clear template variables" do
|
38
|
+
@staticmatic.generate_html("page_one")
|
39
|
+
@staticmatic.clear_template_variables!
|
40
|
+
output = @staticmatic.generate_html("page_two")
|
41
|
+
output.should match(/The variable is/)
|
42
|
+
output.should_not match(/hello/)
|
43
|
+
end
|
44
|
+
end
|
data/spec/rescue_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "StaticMatic::Rescue" do
|
4
|
+
before do
|
5
|
+
setup_staticmatic
|
6
|
+
end
|
7
|
+
|
8
|
+
it "catch haml template errors" do
|
9
|
+
output = @staticmatic.generate_html_with_layout("page_with_error")
|
10
|
+
output.should match(/StaticMatic::TemplateError/)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "catch sass template errors" do
|
14
|
+
output = @staticmatic.generate_css("stylesheets/css_with_error")
|
15
|
+
output.should match(/StaticMatic::TemplateError/)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "re-raise and catch partial errors" do
|
19
|
+
begin
|
20
|
+
@staticmatic.generate_html("page_with_partial_error")
|
21
|
+
rescue StaticMatic::TemplateError => template_error
|
22
|
+
template_error.filename.should match(/partials\/partial_with_error/)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "handle non-template errors" do
|
27
|
+
begin
|
28
|
+
raise Exception.new("This is an exception")
|
29
|
+
rescue Exception => e
|
30
|
+
output = @staticmatic.render_rescue_from_error(e)
|
31
|
+
end
|
32
|
+
|
33
|
+
output.should match(/Exception/)
|
34
|
+
output.should match(/This is an exception/)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
http_path = "http://a.test.host"
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Sub sub folder test
|
@@ -0,0 +1 @@
|
|
1
|
+
Sub sub folder test
|
@@ -0,0 +1 @@
|
|
1
|
+
An index of a sub folder
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 Sub dir test
|
@@ -0,0 +1 @@
|
|
1
|
+
My Menu
|
@@ -0,0 +1 @@
|
|
1
|
+
- bang!
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= "Hello World!" %>
|