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.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +16 -0
  3. data/Gemfile.lock +43 -0
  4. data/LICENSE +20 -0
  5. data/README.md +154 -0
  6. data/Rakefile +45 -0
  7. data/VERSION.yml +5 -0
  8. data/bin/staticmatic +142 -0
  9. data/lib/staticmatic.rb +22 -0
  10. data/lib/staticmatic/ambiguous_template_error.rb +19 -0
  11. data/lib/staticmatic/base.rb +149 -0
  12. data/lib/staticmatic/compass.rb +5 -0
  13. data/lib/staticmatic/compass/app_integration.rb +21 -0
  14. data/lib/staticmatic/compass/configuration_defaults.rb +44 -0
  15. data/lib/staticmatic/compass/installer.rb +15 -0
  16. data/lib/staticmatic/configuration.rb +56 -0
  17. data/lib/staticmatic/deployers/aws-s3.rb +108 -0
  18. data/lib/staticmatic/deployers/config/amazon.yml +7 -0
  19. data/lib/staticmatic/error.rb +17 -0
  20. data/lib/staticmatic/helpers.rb +12 -0
  21. data/lib/staticmatic/helpers/assets_helper.rb +116 -0
  22. data/lib/staticmatic/helpers/current_path_helper.rb +22 -0
  23. data/lib/staticmatic/helpers/form_helper.rb +23 -0
  24. data/lib/staticmatic/helpers/render_helper.rb +14 -0
  25. data/lib/staticmatic/helpers/tag_helper.rb +35 -0
  26. data/lib/staticmatic/helpers/url_helper.rb +59 -0
  27. data/lib/staticmatic/mixins/build.rb +41 -0
  28. data/lib/staticmatic/mixins/helpers.rb +15 -0
  29. data/lib/staticmatic/mixins/render.rb +110 -0
  30. data/lib/staticmatic/mixins/rescue.rb +12 -0
  31. data/lib/staticmatic/mixins/server.rb +7 -0
  32. data/lib/staticmatic/mixins/setup.rb +16 -0
  33. data/lib/staticmatic/server.rb +87 -0
  34. data/lib/staticmatic/template_error.rb +44 -0
  35. data/lib/staticmatic/templates/rescues/default.haml +7 -0
  36. data/lib/staticmatic/templates/rescues/template.haml +18 -0
  37. data/spec/base_spec.rb +13 -0
  38. data/spec/compass_integration_spec.rb +28 -0
  39. data/spec/helpers/asset_helper_spec.rb +41 -0
  40. data/spec/helpers/custom_helper_spec.rb +17 -0
  41. data/spec/render_spec.rb +44 -0
  42. data/spec/rescue_spec.rb +36 -0
  43. data/spec/sandbox/test_site/config/compass.rb +1 -0
  44. data/spec/sandbox/test_site/config/site.rb +0 -0
  45. data/spec/sandbox/test_site/site/sub_folder/another_sub_folder/index.html +1 -0
  46. data/spec/sandbox/test_site/site/sub_folder/another_sub_folder/index.html.html +1 -0
  47. data/spec/sandbox/test_site/site/sub_folder/index.html +1 -0
  48. data/spec/sandbox/test_site/src/_helpers/application_helper.rb +5 -0
  49. data/spec/sandbox/test_site/src/_layouts/alternate_layout.haml +3 -0
  50. data/spec/sandbox/test_site/src/_layouts/default.haml +7 -0
  51. data/spec/sandbox/test_site/src/_layouts/projects.haml +1 -0
  52. data/spec/sandbox/test_site/src/_partials/menu.haml +1 -0
  53. data/spec/sandbox/test_site/src/_partials/partial_with_error.haml +1 -0
  54. data/spec/sandbox/test_site/src/hello_world.erb +1 -0
  55. data/spec/sandbox/test_site/src/index.haml +5 -0
  56. data/spec/sandbox/test_site/src/layout_test.haml +2 -0
  57. data/spec/sandbox/test_site/src/page_one.haml +3 -0
  58. data/spec/sandbox/test_site/src/page_two.haml +2 -0
  59. data/spec/sandbox/test_site/src/page_with_error.haml +5 -0
  60. data/spec/sandbox/test_site/src/page_with_partial_error.haml +3 -0
  61. data/spec/sandbox/test_site/src/stylesheets/application.sass +5 -0
  62. data/spec/sandbox/test_site/src/stylesheets/css_with_error.sass +5 -0
  63. data/spec/sandbox/test_site/src/stylesheets/nested/a_nested_stylesheet.sass +0 -0
  64. data/spec/sandbox/test_site/src/stylesheets/partials/_forms.sass +2 -0
  65. data/spec/sandbox/test_site/src/stylesheets/sassy.scss +12 -0
  66. data/spec/server_spec.rb +11 -0
  67. data/spec/spec_helper.rb +14 -0
  68. data/spec/template_error_spec.rb +23 -0
  69. data/staticmatic.gemspec +158 -0
  70. data/staticmatic3.gemspec +164 -0
  71. data/website/Gemfile +1 -0
  72. data/website/config/site.rb +17 -0
  73. data/website/site/docs/compass_integration.html +70 -0
  74. data/website/site/docs/getting_started.html +49 -0
  75. data/website/site/docs/helpers.html +22 -0
  76. data/website/site/images/bycurve21.gif +0 -0
  77. data/website/site/images/curve21.jpg +0 -0
  78. data/website/site/images/homepage-build.jpg +0 -0
  79. data/website/site/images/homepage-previewing.jpg +0 -0
  80. data/website/site/images/homepage-templating.jpg +0 -0
  81. data/website/site/stylesheets/ie.css +5 -0
  82. data/website/site/stylesheets/print.css +372 -0
  83. data/website/site/stylesheets/screen.css +488 -0
  84. data/website/src/helpers/content_helper.rb +10 -0
  85. data/website/src/layouts/default.haml +15 -0
  86. data/website/src/pages/development.haml +9 -0
  87. data/website/src/pages/docs/_menu.haml +4 -0
  88. data/website/src/pages/docs/_requires_prerelease.haml +4 -0
  89. data/website/src/pages/docs/compass_integration.haml +54 -0
  90. data/website/src/pages/docs/getting_started.haml +31 -0
  91. data/website/src/pages/docs/helpers.haml +1 -0
  92. data/website/src/pages/index.haml +27 -0
  93. data/website/src/stylesheets/_base.scss +43 -0
  94. data/website/src/stylesheets/_defaults.scss +260 -0
  95. data/website/src/stylesheets/ie.scss +10 -0
  96. data/website/src/stylesheets/print.scss +33 -0
  97. data/website/src/stylesheets/screen.scss +73 -0
  98. 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,7 @@
1
+ module StaticMatic::ServerMixin
2
+ def preview
3
+ puts "StaticMatic Preview Server"
4
+ puts "Ctrl+C to exit"
5
+ StaticMatic::Server.start(self)
6
+ end
7
+ 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,7 @@
1
+ %h1= @exception.class.name
2
+
3
+ %p= @exception.message.gsub /\n/, '<br />'
4
+
5
+ %h2 Stack Trace
6
+
7
+ = @exception.backtrace.join("<br/>")
@@ -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/>")
@@ -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
@@ -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
@@ -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
+ An index of a sub folder
@@ -0,0 +1,5 @@
1
+ module ApplicationHelper
2
+ def greet(name)
3
+ "Hello, #{name}!"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ %h1 Alternate Layout
2
+
3
+ = yield
@@ -0,0 +1,7 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title StaticMatic
5
+ = stylesheets
6
+ %body
7
+ = yield
@@ -0,0 +1 @@
1
+ %h1 Sub dir test
@@ -0,0 +1 @@
1
+ <%= "Hello World!" %>
@@ -0,0 +1,5 @@
1
+ %h1 StaticMatic!
2
+
3
+ %p This is some test content
4
+
5
+ = greet("Steve")
@@ -0,0 +1,2 @@
1
+ - @layout = "alternate_layout"
2
+ %p This is a layout test