massimo 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/VERSION +1 -1
  2. data/bin/massimo +5 -3
  3. data/lib/massimo/cli.rb +101 -0
  4. data/lib/massimo/config.rb +56 -0
  5. data/lib/massimo/helpers.rb +12 -19
  6. data/lib/massimo/javascript.rb +18 -19
  7. data/lib/massimo/page.rb +63 -70
  8. data/lib/massimo/resource.rb +92 -0
  9. data/lib/massimo/server.rb +27 -0
  10. data/lib/massimo/site.rb +64 -101
  11. data/lib/massimo/stylesheet.rb +13 -35
  12. data/lib/massimo/view.rb +5 -32
  13. data/lib/massimo/watcher.rb +52 -0
  14. data/lib/massimo.rb +22 -31
  15. metadata +172 -117
  16. data/.document +0 -5
  17. data/.gitignore +0 -25
  18. data/Gemfile +0 -13
  19. data/Rakefile +0 -62
  20. data/lib/massimo/command.rb +0 -243
  21. data/lib/massimo/resource/base.rb +0 -74
  22. data/lib/massimo/resource/collection.rb +0 -56
  23. data/lib/massimo/resource/processing.rb +0 -67
  24. data/lib/massimo/templates.rb +0 -22
  25. data/massimo.gemspec +0 -135
  26. data/test/assertions.rb +0 -8
  27. data/test/helper.rb +0 -64
  28. data/test/source/config.yml +0 -4
  29. data/test/source/helpers/test_helper.rb +0 -5
  30. data/test/source/javascripts/_plugin.js +0 -1
  31. data/test/source/javascripts/application.js +0 -3
  32. data/test/source/javascripts/lib.js +0 -1
  33. data/test/source/lib/site.rb +0 -5
  34. data/test/source/pages/_skipped_page.haml +0 -0
  35. data/test/source/pages/about_us.erb +0 -5
  36. data/test/source/pages/erb.erb +0 -5
  37. data/test/source/pages/erb_with_layout.erb +0 -4
  38. data/test/source/pages/feed.haml +0 -6
  39. data/test/source/pages/haml.haml +0 -5
  40. data/test/source/pages/html.html +0 -4
  41. data/test/source/pages/index.erb +0 -4
  42. data/test/source/pages/markdown.markdown +0 -5
  43. data/test/source/pages/posts/first-post.haml +0 -1
  44. data/test/source/pages/with_extension.haml +0 -4
  45. data/test/source/pages/with_meta_data.haml +0 -7
  46. data/test/source/pages/with_title.haml +0 -4
  47. data/test/source/pages/with_url.haml +0 -4
  48. data/test/source/pages/without_extension.haml +0 -0
  49. data/test/source/pages/without_meta_data.haml +0 -1
  50. data/test/source/pages/without_title.haml +0 -1
  51. data/test/source/pages/without_url.haml +0 -1
  52. data/test/source/stylesheets/_base.sass +0 -2
  53. data/test/source/stylesheets/application.sass +0 -4
  54. data/test/source/stylesheets/basic.css +0 -3
  55. data/test/source/stylesheets/less_file.less +0 -5
  56. data/test/source/views/layouts/application.haml +0 -2
  57. data/test/source/views/with_helper.haml +0 -1
  58. data/test/source/views/with_locals.haml +0 -1
  59. data/test/source/views/without_locals.haml +0 -1
  60. data/test/test_helpers.rb +0 -25
  61. data/test/test_javascript.rb +0 -30
  62. data/test/test_page.rb +0 -142
  63. data/test/test_resource.rb +0 -70
  64. data/test/test_site.rb +0 -125
  65. data/test/test_stylesheet.rb +0 -40
  66. data/test/test_view.rb +0 -50
@@ -1,5 +0,0 @@
1
- class Massimo::Site
2
- def new_method
3
- "working"
4
- end
5
- end
File without changes
@@ -1,5 +0,0 @@
1
- ---
2
- title: About
3
- layout: false
4
- ---
5
- <h1>An <%= "HTML" %> Page</h1>
@@ -1,5 +0,0 @@
1
- ---
2
- title: ERB
3
- layout: false
4
- ---
5
- <h1><%= title %></h1>
@@ -1,4 +0,0 @@
1
- ---
2
- title: ERB With Layout
3
- ---
4
- <h1><%= title %></h1>
@@ -1,6 +0,0 @@
1
- ---
2
- extension: .rss
3
- layout: false
4
- ---
5
- %rss
6
- %title RSS Feed
@@ -1,5 +0,0 @@
1
- ---
2
- title: Haml
3
- layout: false
4
- ---
5
- %h1= title
@@ -1,4 +0,0 @@
1
- ---
2
- layout: false
3
- ---
4
- <h1>HTML</h1>
@@ -1,4 +0,0 @@
1
- ---
2
- title: Home
3
- ---
4
- <h1><%= title %></h1>
@@ -1,5 +0,0 @@
1
- ---
2
- title: Markdown
3
- layout: false
4
- ---
5
- # <%= title %>
@@ -1 +0,0 @@
1
- %h1 First Post
@@ -1,4 +0,0 @@
1
- ---
2
- extension: .rss
3
- ---
4
- %h1 A Page with filter extension.
@@ -1,7 +0,0 @@
1
- ---
2
- title: A Page with a title
3
- tags:
4
- - tag_1
5
- - tag_2
6
- ---
7
- %h1 A Page with a title
@@ -1,4 +0,0 @@
1
- ---
2
- title: A Title
3
- ---
4
- %h1 A Page with a title
@@ -1,4 +0,0 @@
1
- ---
2
- url: /page-with-url
3
- ---
4
- %h1 A Page with a URL
File without changes
@@ -1 +0,0 @@
1
- %h1 A Page without meta_data
@@ -1 +0,0 @@
1
- %h1 A Page without a title
@@ -1 +0,0 @@
1
- %h1 A Page without a URL
@@ -1,2 +0,0 @@
1
- body
2
- font-size: 12px
@@ -1,4 +0,0 @@
1
- @import base.sass
2
-
3
- #header
4
- font-size: 36px
@@ -1,3 +0,0 @@
1
- body {
2
- font-size: 12px;
3
- }
@@ -1,5 +0,0 @@
1
- @brand_color: #4D926F;
2
-
3
- #header {
4
- color: @brand_color;
5
- }
@@ -1,2 +0,0 @@
1
- %title= page.title
2
- %body= yield
@@ -1 +0,0 @@
1
- %p= test_method
@@ -1 +0,0 @@
1
- %h1= title
@@ -1 +0,0 @@
1
- %h1 A Partial
data/test/test_helpers.rb DELETED
@@ -1,25 +0,0 @@
1
- require File.expand_path("../helper", __FILE__)
2
-
3
- class TestHelpers < Test::Unit::TestCase
4
- context "A Site's Helpers" do
5
- setup do
6
- @helpers = site().helpers
7
- end
8
-
9
- should "include sinatra_more's helper methods" do
10
- assert @helpers.class.include?(SinatraMore::OutputHelpers)
11
- assert @helpers.class.include?(SinatraMore::TagHelpers)
12
- assert @helpers.class.include?(SinatraMore::AssetTagHelpers)
13
- assert @helpers.class.include?(SinatraMore::FormHelpers)
14
- assert @helpers.class.include?(SinatraMore::FormatHelpers)
15
- end
16
-
17
- should "have a method for accessing the Site" do
18
- assert_equal @site, @helpers.site
19
- end
20
-
21
- should "have a method for rendering views like partials" do
22
- assert_equal "<h1>Testing</h1>\n", @helpers.render("with_locals", :title => "Testing")
23
- end
24
- end
25
- end
@@ -1,30 +0,0 @@
1
- require File.expand_path("../helper", __FILE__)
2
-
3
- class TestJavascript < Test::Unit::TestCase
4
- context "A Site" do
5
- setup { site() }
6
-
7
- should "concat js using Sprockets" do
8
- javascript = Massimo::Javascript.new(source_dir("javascripts", "application.js"))
9
- assert_equal %{var plugin = "plugin";\n\nvar application = "application";\n}, javascript.render
10
- end
11
-
12
- context "processing Javascripts" do
13
- should "output the js file to the javascripts dir" do
14
- Massimo::Javascript.new(source_dir("javascripts", "application.js")).process!
15
- assert_equal %{var plugin = "plugin";\n\nvar application = "application";\n}, File.read(output_dir("javascripts", "application.js"))
16
- end
17
-
18
- teardown { clear_output }
19
- end
20
- end
21
-
22
- context "A Production Site" do
23
- setup { site(:production => true) }
24
-
25
- should "minify js" do
26
- javascript = Massimo::Javascript.new(source_dir("javascripts", "application.js"))
27
- assert_equal %{\nvar plugin="plugin";var application="application";}, javascript.render
28
- end
29
- end
30
- end
data/test/test_page.rb DELETED
@@ -1,142 +0,0 @@
1
- require File.expand_path("../helper", __FILE__)
2
-
3
- class TestPage < Test::Unit::TestCase
4
- context "A Site" do
5
- setup { site() }
6
-
7
-
8
- context "Page without meta_data" do
9
- setup { page("without_meta_data.haml") }
10
-
11
- should "return a non-empty hash when calling meta_data" do
12
- assert_instance_of Hash, @page.meta_data
13
- assert !@page.meta_data.empty?
14
- end
15
- end
16
-
17
- context "Page with meta_data" do
18
- setup { page("with_meta_data.haml") }
19
-
20
- should "return a non-empty hash when calling meta_data" do
21
- assert_instance_of Hash, @page.meta_data
22
- assert !@page.meta_data.empty?
23
- end
24
-
25
- should "be able to access meta_data directly through methods on the Page" do
26
- assert_instance_of Array, @page.tags
27
- end
28
-
29
- should "be able to write new meta_data dynamically" do
30
- @page.new_tag = "test"
31
- assert_equal "test", @page.new_tag
32
- end
33
- end
34
-
35
- context "Page with title" do
36
- setup { page("with_title.haml") }
37
-
38
- should "fetch the title from the meta_data" do
39
- assert_equal "A Title", @page.title
40
- end
41
- end
42
-
43
- context "Page without title" do
44
- setup { page("without_title.haml") }
45
-
46
- should "create the title from the file name" do
47
- assert_equal "Without Title", @page.title
48
- end
49
- end
50
-
51
- context "Page with extension" do
52
- setup { page("with_extension.haml") }
53
-
54
- should "fetch the extension from the meta_data" do
55
- assert_equal ".rss", @page.extension
56
- end
57
- end
58
-
59
- context "Page without extension" do
60
- setup { page("without_extension.haml") }
61
-
62
- should "default to .html" do
63
- assert_equal ".html", @page.extension
64
- end
65
- end
66
-
67
- context "Page with URL" do
68
- setup { page("with_url.haml") }
69
-
70
- should "fetch the extension from the meta_data" do
71
- assert_equal "/page-with-url", @page.url
72
- end
73
- end
74
-
75
- context "Page without URL" do
76
- setup { page("without_url.haml") }
77
-
78
- should "default to .html" do
79
- assert_equal "/without-url", @page.url
80
- end
81
- end
82
-
83
- should "fetch the body from the page file" do
84
- assert_equal %{<h1>An <%= "HTML" %> Page</h1>}, page("about_us.erb").body
85
- end
86
-
87
- context "rendering Pages" do
88
- context "without layouts" do
89
-
90
- should "render erb content from the page file correctly" do
91
- assert_equal "<h1>ERB</h1>", page("erb.erb").render
92
- end
93
-
94
- should "render haml content from the page file correctly" do
95
- assert_equal "<h1>Haml</h1>\n", page("haml.haml").render
96
- end
97
-
98
- should "render markdown content from the page file correctly" do
99
- assert_equal "<h1>Markdown</h1>\n", page("markdown.markdown").render
100
- end
101
-
102
- should "render html content from the page file correctly" do
103
- assert_equal "<h1>HTML</h1>", page("html.html").render
104
- end
105
-
106
- end
107
-
108
- context "with layouts" do
109
-
110
- should "filter the content from the page file correctly" do
111
- assert_equal "<title>ERB With Layout</title>\n<body><h1>ERB With Layout</h1></body>\n", page("erb_with_layout.erb").render
112
- end
113
-
114
- should "render the page without a layout when calling #to_s" do
115
- page("erb_with_layout.erb")
116
- assert_equal @page.render(false), @page.to_s
117
- end
118
- end
119
- end
120
-
121
- context "processing Pages" do
122
-
123
- should "write the filtered body to a new file in the output dir" do
124
- page("index.erb").process!
125
- assert_equal File.read(output_dir("index.html")), page.render
126
- end
127
-
128
- should "write the filtered body to a new file using the extension in the meta_data" do
129
- page("feed.haml").process!
130
- assert_equal File.read(output_dir("feed.rss")), page.render(false)
131
- end
132
-
133
- should "write the filtered body to a new file with a pretty URL scheme in the output dir" do
134
- page("about_us.erb").process!
135
- assert_equal File.read(output_dir("about-us", "index.html")), page.render(false)
136
- end
137
-
138
- teardown { clear_output }
139
-
140
- end
141
- end
142
- end
@@ -1,70 +0,0 @@
1
- require File.expand_path("../helper", __FILE__)
2
-
3
- class TestResource < Test::Unit::TestCase
4
- context "A site" do
5
- setup { site() }
6
-
7
- should "raise an error when reading a non-existent resource" do
8
- assert_raise Massimo::MissingResource do
9
- Massimo::Resource::Base.new("some/non-existent/file")
10
- end
11
- end
12
-
13
- should "raise an error when reading an invalid resource" do
14
- assert_raise Massimo::InvalidResource do
15
- Massimo::Resource::Base.new(source_dir("views", "layouts"))
16
- end
17
- end
18
-
19
- should "have a method to get the resource's type (extension)" do
20
- assert_equal Massimo::Resource::Base.new(source_dir("pages", "about_us.erb")).resource_type, "erb"
21
- end
22
-
23
- should "render the resource files data" do
24
- assert_equal Massimo::Resource::Base.new(source_dir("pages", "without_meta_data.haml")).render, "%h1 A Page without meta_data"
25
- end
26
-
27
- context "with unprocessable Resources" do
28
- should "not process resources when process! is called" do
29
- assert Massimo::View.processable? == false
30
- assert view("with_locals.haml").process! == false
31
- end
32
- end
33
-
34
- context "with Resource collections" do
35
- should "find only the pages set in the :pages option" do
36
- only_pages = %w{about_us.erb feed.haml index.erb}
37
- site(:pages => only_pages)
38
- page_paths = Massimo::Page.all(true).collect { |page| page.source_path.basename }
39
- assert_equal_arrays only_pages, page_paths
40
- end
41
-
42
- should "skip pages set in the :skip_pages option (as an Array)" do
43
- site(:skip_pages => %w{about_us.erb erb.erb erb_with_layout.erb feed.haml posts/first-post.haml haml.haml html.html index.erb markdown.markdown})
44
- page_paths = Massimo::Page.all(true).collect { |page| page.source_path.basename }
45
- assert_equal_arrays [
46
- "with_extension.haml",
47
- "with_meta_data.haml",
48
- "with_title.haml",
49
- "with_url.haml",
50
- "without_extension.haml",
51
- "without_meta_data.haml",
52
- "without_title.haml",
53
- "without_url.haml"
54
- ], page_paths
55
- end
56
-
57
- should "skip pages set in the :skip_pages option (as a Proc)" do
58
- site(:skip_pages => lambda { |file| file.include?("with") })
59
- page_paths = Massimo::Page.all(true).collect { |page| page.source_path.basename }
60
- assert_equal_arrays %w{about_us.erb erb.erb feed.haml first-post.haml haml.haml html.html index.erb markdown.markdown}, page_paths
61
- end
62
-
63
- should "not skip any pages when :skip_pages is set incorrectly" do
64
- site(:skip_pages => 15)
65
- page_paths = Massimo::Page.all(true).collect { |page| page.source_path.basename }
66
- assert_equal_arrays source_page_paths, page_paths
67
- end
68
- end
69
- end
70
- end
data/test/test_site.rb DELETED
@@ -1,125 +0,0 @@
1
- require File.expand_path("../helper", __FILE__)
2
-
3
- class TestSite < Test::Unit::TestCase
4
-
5
- should "store configuration options" do
6
- @site = Massimo::Site(
7
- :source => source_dir,
8
- :output => output_dir
9
- )
10
- assert_equal source_dir, @site.options[:source]
11
- assert_equal output_dir, @site.options[:output]
12
- end
13
-
14
- should "use default options unless specified" do
15
- @site = Massimo::Site(:source => source_dir)
16
- assert_equal source_dir, @site.options[:source]
17
- assert_equal Massimo::Site::DEFAULT_OPTIONS[:output], @site.options[:output]
18
- end
19
-
20
- should "have refresh the configuration if new options are set" do
21
- Massimo::Site(:source => source_dir, :output => "/the/wrong/dir")
22
- @site = Massimo::Site(:source => source_dir)
23
- assert_equal Massimo::Site::DEFAULT_OPTIONS[:output], @site.options[:output]
24
- end
25
-
26
- should "have methods for determining the environment" do
27
- @site = Massimo::Site(:source => source_dir)
28
- assert @site.development?
29
- @site = Massimo::Site(:source => source_dir, :environment => :development)
30
- assert @site.development?
31
- @site = Massimo::Site(:source => source_dir, :environment => :production)
32
- assert @site.production?
33
- end
34
-
35
- context "Site#dir_for" do
36
- should "get the default path to directories" do
37
- @site = Massimo::Site(:source => source_dir)
38
- assert_equal source_dir("pages"), @site.dir_for(:pages)
39
- end
40
-
41
- should "get the specified path to directories from the options" do
42
- @site = Massimo::Site(:source => source_dir, :pages_path => source_dir("my_pages"))
43
- assert_equal source_dir("my_pages"), @site.dir_for(:pages)
44
- end
45
-
46
- should "get paths to files" do
47
- @site = Massimo::Site(:source => source_dir)
48
- assert_equal source_dir("random", "file.jpg"), @site.dir_for(:random, "file.jpg")
49
- end
50
- end
51
-
52
- context "Site#all_source_dirs" do
53
- should "get the directories of all the resources, libs, and helpers" do
54
- assert_equal [
55
- "./test/source/views",
56
- "./test/source/pages",
57
- "./test/source/stylesheets",
58
- "./test/source/javascripts",
59
- "./test/source/helpers",
60
- "./test/source/lib" ],
61
- site.all_source_dirs
62
- end
63
-
64
- should "include new resource directories" do
65
- class Post < Massimo::Page; end
66
- assert site.all_source_dirs.include?("./test/source/posts")
67
- end
68
-
69
- teardown do
70
- Massimo.resources.delete_if { |resource| resource.name == "post" }
71
- end
72
- end
73
-
74
- context "A Normal Site" do
75
- setup { site() }
76
-
77
- should "have a source_dir method" do
78
- assert_equal source_dir("some", "path"), @site.source_dir("some", "path")
79
- end
80
-
81
- should "have a output_dir method" do
82
- assert_equal output_dir("some", "path"), @site.output_dir("some", "path")
83
- end
84
-
85
- should "render a view by name" do
86
- assert_equal "<h1>Title</h1>\n", @site.render_view("with_locals", :title => "Title")
87
- end
88
-
89
- should "find all the pages in the pages dir" do
90
- page_paths = @site.pages.collect { |page| page.source_path.basename }
91
- assert_equal_arrays source_page_paths, page_paths
92
- end
93
-
94
- should "add helpers from the helpers directory" do
95
- assert_equal "<p>working</p>\n", @site.render_view("with_helper")
96
- end
97
-
98
- should "require the lib directory for further customization" do
99
- assert_equal "working", @site.new_method
100
- end
101
-
102
- context "processing Sites" do
103
- setup { @site.process! }
104
-
105
- should "process each page in the pages dir" do
106
- output_page_paths = Dir.glob(output_dir("**", "*.{html,rss}"))
107
- assert_equal source_page_paths.length, output_page_paths.length
108
- end
109
-
110
- should "process each stylesheet file in the stylesheets dir" do
111
- assert File.exist?(output_dir("stylesheets", "application.css"))
112
- assert File.exist?(output_dir("stylesheets", "less_file.css"))
113
- assert File.exist?(output_dir("stylesheets", "basic.css"))
114
- end
115
-
116
- should "process each javascript file in the javascripts dir" do
117
- assert File.exist?(output_dir("javascripts", "application.js"))
118
- assert File.exist?(output_dir("javascripts", "lib.js"))
119
- end
120
-
121
- teardown { clear_output }
122
- end
123
- end
124
-
125
- end
@@ -1,40 +0,0 @@
1
- require File.expand_path("../helper", __FILE__)
2
-
3
- class TestStylesheet < Test::Unit::TestCase
4
- context "A Site" do
5
- setup { site() }
6
-
7
- should "render CSS stylesheets" do
8
- stylesheet = Massimo::Stylesheet.new(source_dir("stylesheets", "basic.css"))
9
- assert_equal "body {\n font-size: 12px;\n}", stylesheet.render
10
- end
11
-
12
- should "render Sass stylesheets" do
13
- stylesheet = Massimo::Stylesheet.new(source_dir("stylesheets", "application.sass"))
14
- assert_equal "body {\n font-size: 12px; }\n\n#header {\n font-size: 36px; }\n", stylesheet.render
15
- end
16
-
17
- should "render Less stylesheets" do
18
- stylesheet = Massimo::Stylesheet.new(source_dir("stylesheets", "less_file.less"))
19
- assert_equal "#header { color: #4d926f; }\n", stylesheet.render
20
- end
21
-
22
- context "processing Stylesheets" do
23
- should "output the css file to the stylesheets dir" do
24
- Massimo::Stylesheet.new(source_dir("stylesheets", "application.sass")).process!
25
- assert_equal "body {\n font-size: 12px; }\n\n#header {\n font-size: 36px; }\n", File.read(output_dir("stylesheets", "application.css"))
26
- end
27
-
28
- teardown { clear_output }
29
- end
30
- end
31
-
32
- context "A Production Site" do
33
- setup { site(:production => true)}
34
-
35
- should "should compress Sass stylesheets" do
36
- stylesheet = Massimo::Stylesheet.new(source_dir("stylesheets", "application.sass"))
37
- assert_equal "body{font-size:12px}#header{font-size:36px}\n", stylesheet.render
38
- end
39
- end
40
- end
data/test/test_view.rb DELETED
@@ -1,50 +0,0 @@
1
- require File.expand_path("../helper", __FILE__)
2
-
3
- class TestView < Test::Unit::TestCase
4
- context "A View with options" do
5
- setup do
6
- site(:haml => { :format => :xhtml })
7
- view("without_locals.haml")
8
- end
9
-
10
- should "render through Tilt with the Site's options for the resource type" do
11
- tilt = {}
12
- stub(tilt).render
13
- mock(Tilt).new(@view.file_name, 1, :format => :xhtml) { tilt }
14
- @view.render
15
- end
16
- end
17
-
18
- context "View without locals" do
19
- setup { view("without_locals.haml") }
20
-
21
- should "fetch the body from the view file" do
22
- assert_equal "%h1 A Partial", @view.body
23
- end
24
-
25
- should "render the content from the view file correctly" do
26
- assert_equal "<h1>A Partial</h1>\n", @view.render
27
- end
28
- end
29
-
30
- context "View with locals" do
31
- setup { view("with_locals.haml", :title => "A Partial") }
32
-
33
- should "render the content from the page file correctly" do
34
- assert_equal "<h1>A Partial</h1>\n", @view.render
35
- end
36
-
37
- should "be able to access meta_data directly" do
38
- assert_equal "A Partial", @view.title
39
- end
40
-
41
- should "be able to write new meta_data dynamically" do
42
- @view.new_data = "test"
43
- assert_equal "test", @view.new_data
44
- end
45
-
46
- should "still return nil when accessing non-existent meta_data properties" do
47
- assert_nil @view.non_existent_prop
48
- end
49
- end
50
- end