massimo 0.3.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +70 -4
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/massimo/command.rb +26 -26
- data/lib/massimo/helpers.rb +9 -9
- data/lib/massimo/javascript.rb +9 -27
- data/lib/massimo/page.rb +28 -49
- data/lib/massimo/resource/base.rb +71 -0
- data/lib/massimo/resource/collection.rb +56 -0
- data/lib/massimo/resource/processing.rb +64 -0
- data/lib/massimo/site.rb +43 -103
- data/lib/massimo/stylesheet.rb +15 -22
- data/lib/massimo/templates.rb +4 -4
- data/lib/massimo/view.rb +5 -5
- data/lib/massimo.rb +27 -16
- data/massimo.gemspec +11 -7
- data/test/helper.rb +11 -5
- data/test/test_helpers.rb +25 -0
- data/test/test_page.rb +6 -0
- data/test/test_resource.rb +47 -4
- data/test/test_site.rb +19 -52
- data/test/test_view.rb +4 -0
- metadata +9 -5
- data/lib/massimo/resource.rb +0 -52
@@ -0,0 +1,64 @@
|
|
1
|
+
module Massimo
|
2
|
+
module Resource
|
3
|
+
module Processing
|
4
|
+
def self.included(base) # :nodoc:
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
# Determine if this Resource type is processable. By default this is `false`.
|
10
|
+
def processable?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
# This will override `processable?` to return `true`.
|
15
|
+
def processable!
|
16
|
+
def self.processable?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Process all the Resources in this Resource type's directory.
|
22
|
+
def process!
|
23
|
+
all(true).each(&:process!)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Writes the rendered body to the output file.
|
28
|
+
def process!
|
29
|
+
if self.class.processable?
|
30
|
+
# Make the full path to the directory of the output file
|
31
|
+
FileUtils.mkdir_p(output_path.dirname)
|
32
|
+
# write the filtered data to the output file
|
33
|
+
output_path.open("w") do |file|
|
34
|
+
file.write render
|
35
|
+
end
|
36
|
+
else
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
# Reads the source page file, and populates the `@meta_data` and
|
44
|
+
# `@body` attributes.
|
45
|
+
def read_source!
|
46
|
+
raise Massimo::MissingResource unless @source_path.exist?
|
47
|
+
# try to read it now
|
48
|
+
begin
|
49
|
+
@line = 1
|
50
|
+
@body = @source_path.read
|
51
|
+
rescue
|
52
|
+
raise Massimo::InvalidResource
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Determine the output file path
|
57
|
+
def output_path
|
58
|
+
@output_path ||= Pathname.new(
|
59
|
+
@source_path.to_s.sub(site.source_dir, site.output_dir)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/massimo/site.rb
CHANGED
@@ -5,60 +5,42 @@ module Massimo
|
|
5
5
|
# Default options. Overriden by values given when creating a Site.
|
6
6
|
DEFAULT_OPTIONS = {
|
7
7
|
:source => ".",
|
8
|
-
:output =>
|
8
|
+
:output => File.join(".", "public"),
|
9
9
|
:server_port => "1984"
|
10
10
|
}.freeze
|
11
11
|
|
12
|
-
SOURCE_DIRS = [ :pages, :views, :stylesheets, :javascripts, :helpers, :lib ].freeze # :nodoc:
|
13
|
-
|
14
12
|
attr_accessor :options, :helpers
|
15
13
|
|
16
14
|
# Setup the Site with the given options. These options may be overridden by the config file.
|
17
15
|
def setup(options = {})
|
18
16
|
@options = DEFAULT_OPTIONS.dup.merge(options.symbolize_keys)
|
17
|
+
reload
|
19
18
|
self
|
20
19
|
end
|
21
20
|
|
22
|
-
#
|
23
|
-
|
24
|
-
def process!
|
21
|
+
# Reload helpers and libs.
|
22
|
+
def reload
|
25
23
|
reload_helpers
|
26
24
|
reload_libs
|
27
|
-
|
28
|
-
stylesheets(true).each(&:process!)
|
29
|
-
javascripts(true).each(&:process!)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Get all the Pages in the pages dir.
|
33
|
-
def pages(reload = false)
|
34
|
-
return @pages if defined?(@pages) && !reload
|
35
|
-
page_paths = self.find_files_in(:pages)
|
36
|
-
@pages = page_paths.collect { |path| ::Massimo::Page.new(path) }
|
37
|
-
end
|
38
|
-
|
39
|
-
# Get all the Stylesheets in the stylesheets dir.
|
40
|
-
def stylesheets(reload = false)
|
41
|
-
return @stylesheets if defined?(@stylesheets) && !reload
|
42
|
-
stylesheet_paths = self.find_files_in(:stylesheets, [ :css, :sass, :less ])
|
43
|
-
@stylesheets = stylesheet_paths.collect { |path| ::Massimo::Stylesheet.new(path) }
|
25
|
+
reload_resources
|
44
26
|
end
|
45
27
|
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
28
|
+
# Processes all the Pages, Stylesheets, and Javascripts and outputs
|
29
|
+
# them to the output dir.
|
30
|
+
def process!
|
31
|
+
reload
|
32
|
+
Massimo.processable_resources.each(&:process!)
|
51
33
|
end
|
52
34
|
|
53
35
|
# Finds a view by the given name
|
54
36
|
def find_view(name, meta_data = {})
|
55
|
-
view_path = Dir.glob(
|
56
|
-
view_path &&
|
37
|
+
view_path = Dir.glob(dir_for(:views, "#{name}.*")).first
|
38
|
+
view_path && Massimo::View.new(view_path, meta_data)
|
57
39
|
end
|
58
40
|
|
59
41
|
# Finds a view then renders it with the given locals
|
60
42
|
def render_view(name, locals = {}, &block)
|
61
|
-
view =
|
43
|
+
view = find_view(name)
|
62
44
|
view && view.render(locals, &block)
|
63
45
|
end
|
64
46
|
|
@@ -78,107 +60,65 @@ module Massimo
|
|
78
60
|
|
79
61
|
# The path to the source dir
|
80
62
|
def source_dir(*path)
|
81
|
-
|
63
|
+
File.join(@options[:source], *path)
|
82
64
|
end
|
83
65
|
|
84
|
-
# Get
|
85
|
-
|
86
|
-
|
66
|
+
# Get the directory to the given resource type (pages, views, etc.).
|
67
|
+
# If the path has been manually set in the options, you will get that
|
68
|
+
# path. Otherwise you will get the path relative to the source directory.
|
69
|
+
def dir_for(type, *path)
|
70
|
+
if type_path = @options["#{type}_path".to_sym]
|
71
|
+
File.join(type_path, *path)
|
72
|
+
else
|
73
|
+
source_dir(type.to_s, *path)
|
74
|
+
end
|
87
75
|
end
|
88
76
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
77
|
+
# Get all the source directories as an array.
|
78
|
+
def all_source_dirs
|
79
|
+
Massimo.resources.collect(&:dir) + [ dir_for(:helpers), dir_for(:lib) ]
|
93
80
|
end
|
94
81
|
|
95
82
|
# The path to the output dir
|
96
83
|
def output_dir(*path)
|
97
|
-
|
84
|
+
File.join(@options[:output], *path)
|
98
85
|
end
|
99
86
|
|
100
87
|
protected
|
101
|
-
|
102
|
-
# Get the directory to the given resource type (pages, views, etc.).
|
103
|
-
# If the path has been manually set in the options, you will get that
|
104
|
-
# path. Otherwise you will get the path relative to the source directory.
|
105
|
-
def dir_for(type, *path)
|
106
|
-
if type_path = @options["#{type}_path".to_sym]
|
107
|
-
::File.join(type_path, *path)
|
108
|
-
else
|
109
|
-
self.source_dir(type.to_s, *path)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Find all the files in the given resouce type's directory, optionally
|
114
|
-
# selecting only those with the given extensions. This will return
|
115
|
-
# an array with the full path to the files.
|
116
|
-
def find_files_in(type, extensions = nil)
|
117
|
-
# the directory where these files will be found
|
118
|
-
type_dir = self.dir_for(type)
|
119
|
-
|
120
|
-
# By default get the file list from the options
|
121
|
-
files = @options[type] && @options[type].dup
|
122
|
-
|
123
|
-
unless files && files.is_a?(::Array)
|
124
|
-
# If files aren't listed in the options, get them
|
125
|
-
# from the given block
|
126
|
-
glob = (extensions.nil? || extensions.empty?) ? "*" : "*.{#{extensions.join(",")}}"
|
127
|
-
files = ::Dir.glob(::File.join(type_dir, "**", glob))
|
128
|
-
|
129
|
-
# normalize the files by removing the directory from the path
|
130
|
-
files.collect! { |file| file.gsub("#{type_dir}/", "") }
|
131
|
-
|
132
|
-
# reject the files in the skip_files option, which can
|
133
|
-
# either be an array or a Proc.
|
134
|
-
if skip_files = @options["skip_#{type}".to_sym]
|
135
|
-
files.reject! do |file|
|
136
|
-
case skip_files
|
137
|
-
when ::Array
|
138
|
-
skip_files.include?(file)
|
139
|
-
else ::Proc
|
140
|
-
skip_files.call(file)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
# Reject all files that begin with _ (like partials) and directories
|
147
|
-
files.reject! { |file| ::File.basename(file) =~ /^_/ }
|
148
|
-
|
149
|
-
# now add the directory back to the path
|
150
|
-
files.collect! { |file| ::File.join(type_dir, file) }
|
151
|
-
|
152
|
-
# And make sure we don't find directories
|
153
|
-
files.reject! { |file| ::File.directory?(file) }
|
154
|
-
files
|
155
|
-
end
|
156
88
|
|
157
89
|
# Reload the Helpers instance with the helper modules
|
158
90
|
def reload_helpers
|
159
|
-
@helpers =
|
91
|
+
@helpers = Helpers.new(helper_modules.compact)
|
160
92
|
end
|
161
93
|
|
162
94
|
# Reload all the files in the source lib dir.
|
163
95
|
def reload_libs
|
164
|
-
reload_files
|
96
|
+
reload_files Dir.glob(dir_for(:lib, "**", "*.rb"))
|
97
|
+
end
|
98
|
+
|
99
|
+
# Load methods for listing all available files for each Resource type.
|
100
|
+
def reload_resources
|
101
|
+
class_eval do
|
102
|
+
# Define methods for getting all of the files for each Resource Type
|
103
|
+
Massimo.processable_resources.each do |type|
|
104
|
+
define_method(type.name.to_s.pluralize) do |*args|
|
105
|
+
type.all(*args)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
165
109
|
end
|
166
110
|
|
167
111
|
# Find all the helper modules
|
168
112
|
def helper_modules
|
169
|
-
reload_files
|
113
|
+
reload_files Dir.glob(dir_for(:helpers, "*.rb"))
|
170
114
|
end
|
171
115
|
|
172
116
|
# Relod the given file by removing their constants and loading the file again.
|
173
117
|
# Return an Array of the reloaded Constants.
|
174
118
|
def reload_files(files)
|
175
119
|
files.collect do |file|
|
176
|
-
class_name = ::File.basename(file).gsub(::File.extname(file), "").classify
|
177
|
-
# Unload the constant if it already exists
|
178
|
-
::Object.class_eval { remove_const(class_name) if const_defined?(class_name) }
|
179
|
-
# Load the constant
|
180
120
|
load(file)
|
181
|
-
|
121
|
+
class_name = File.basename(file).gsub(File.extname(file), "").classify
|
182
122
|
class_name.constantize rescue nil
|
183
123
|
end
|
184
124
|
end
|
data/lib/massimo/stylesheet.rb
CHANGED
@@ -1,26 +1,18 @@
|
|
1
1
|
module Massimo
|
2
|
-
class Stylesheet < Resource
|
2
|
+
class Stylesheet < Massimo::Resource::Base
|
3
|
+
processable!
|
4
|
+
|
3
5
|
# Render the css based on the type of resource
|
4
6
|
def render
|
5
7
|
case resource_type.to_sym
|
6
|
-
when :css
|
7
|
-
@body.to_s
|
8
8
|
when :sass
|
9
|
-
require "sass" unless defined?
|
10
|
-
|
9
|
+
require "sass" unless defined?(Sass)
|
10
|
+
Sass::Files.tree_for(@source_path, sass_options).render
|
11
11
|
when :less
|
12
|
-
require "less" unless defined?
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# Writes the rendered css to the output file.
|
18
|
-
def process!
|
19
|
-
# Make the full path to the directory of the output file
|
20
|
-
::FileUtils.mkdir_p(self.output_path.dirname)
|
21
|
-
# write the filtered data to the output file
|
22
|
-
self.output_path.open("w") do |file|
|
23
|
-
file.write self.render
|
12
|
+
require "less" unless defined?(Less)
|
13
|
+
Less.parse(@body)
|
14
|
+
else
|
15
|
+
@body.to_s
|
24
16
|
end
|
25
17
|
end
|
26
18
|
|
@@ -28,9 +20,10 @@ module Massimo
|
|
28
20
|
|
29
21
|
# Determine the output file path
|
30
22
|
def output_path
|
31
|
-
@output_path ||=
|
32
|
-
sub(
|
33
|
-
sub(/#{@source_path.extname}$/, ".css")
|
23
|
+
@output_path ||= Pathname.new(@source_path.to_s.
|
24
|
+
sub(site.source_dir, site.output_dir). # move to output dir
|
25
|
+
sub(/#{@source_path.extname}$/, ".css") # replace extension with .css
|
26
|
+
)
|
34
27
|
end
|
35
28
|
|
36
29
|
# Gets the Sass options, with Site options merged in.
|
@@ -38,8 +31,8 @@ module Massimo
|
|
38
31
|
options = {
|
39
32
|
:style => site.production? ? :compressed : :nested
|
40
33
|
}
|
41
|
-
options.merge!(
|
42
|
-
options.merge(:css_filename =>
|
34
|
+
options.merge!(site.options[:sass]) if site.options[:sass].is_a?(Hash)
|
35
|
+
options.merge(:css_filename => output_path)
|
43
36
|
end
|
44
37
|
|
45
38
|
end
|
data/lib/massimo/templates.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module Tilt
|
2
|
-
register :html,
|
3
|
-
register :php,
|
2
|
+
register :html, Tilt::ERBTemplate
|
3
|
+
register :php, Tilt::ERBTemplate
|
4
4
|
|
5
5
|
# My Markdown implementation.
|
6
6
|
class MarkdownTemplate < Template
|
7
7
|
def compile!
|
8
|
-
@erb_engine =
|
8
|
+
@erb_engine = Tilt::ERBTemplate.new { data }
|
9
9
|
end
|
10
10
|
|
11
11
|
def evaluate(scope, locals, &block)
|
12
12
|
# First evaluate the code using ERB
|
13
13
|
erb_output = @erb_engine.render(scope, locals, &block)
|
14
14
|
# Then evaluate the code using the RDiscountTemplate
|
15
|
-
|
15
|
+
Tilt::RDiscountTemplate.new { erb_output }.render
|
16
16
|
end
|
17
17
|
end
|
18
18
|
register :markdown, MarkdownTemplate
|
data/lib/massimo/view.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Massimo
|
2
|
-
class View < Resource
|
2
|
+
class View < Massimo::Resource::Base
|
3
3
|
attr_reader :meta_data
|
4
4
|
|
5
5
|
# Creates a new page associated with the given file path.
|
@@ -8,15 +8,15 @@ module Massimo
|
|
8
8
|
super(source_path)
|
9
9
|
end
|
10
10
|
|
11
|
-
# Renders the page using the
|
11
|
+
# Renders the page using the appropriate Tilt Template
|
12
12
|
def render(locals = {}, &block)
|
13
|
-
template =
|
14
|
-
template.render(
|
13
|
+
template = Tilt.new(file_name, @line || 1, options_for_resource_type) { @body }
|
14
|
+
template.render(site.helpers, @meta_data.merge(locals), &block)
|
15
15
|
end
|
16
16
|
|
17
17
|
protected
|
18
18
|
|
19
|
-
# All undefined methods are sent to the meta_data hash.
|
19
|
+
# All undefined methods are sent to the `@meta_data` hash.
|
20
20
|
def method_missing(method, *args, &block)
|
21
21
|
if method.to_s.match(/(.*)\=$/) && args.length == 1
|
22
22
|
@meta_data[$1.to_sym] = args.first
|
data/lib/massimo.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
libdir = ::File.dirname(__FILE__)
|
2
|
-
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
3
|
-
|
4
1
|
# Rubygems
|
5
2
|
require "rubygems"
|
6
3
|
|
@@ -15,24 +12,38 @@ require "jsmin"
|
|
15
12
|
require "tilt"
|
16
13
|
|
17
14
|
# Internal
|
18
|
-
|
19
|
-
require "massimo
|
20
|
-
require "massimo
|
21
|
-
require "massimo
|
22
|
-
require "massimo/view"
|
23
|
-
require "massimo/page"
|
24
|
-
require "massimo/stylesheet"
|
25
|
-
require "massimo/javascript"
|
15
|
+
lib_dir = File.dirname(__FILE__)
|
16
|
+
require File.join(lib_dir, "massimo", "helpers")
|
17
|
+
require File.join(lib_dir, "massimo", "templates")
|
18
|
+
require File.join(lib_dir, "massimo", "site")
|
26
19
|
|
27
20
|
module Massimo
|
28
|
-
VERSION =
|
21
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), "..", "VERSION")) # :nodoc:
|
29
22
|
|
30
|
-
MissingResource =
|
31
|
-
InvalidResource =
|
23
|
+
MissingResource = Class.new(StandardError) # :nodoc:
|
24
|
+
InvalidResource = Class.new(StandardError) # :nodoc:
|
32
25
|
|
33
|
-
#
|
26
|
+
# This will create an instance of Massimo::Site the first time it is called.
|
27
|
+
# Everytime it's called afterwords, without options, it returns the same
|
28
|
+
# instance.
|
34
29
|
def self.Site(options = {})
|
35
30
|
return @site if defined?(@site) && options.empty?
|
36
|
-
@site =
|
31
|
+
@site = Massimo::Site.instance.setup(options)
|
32
|
+
end
|
33
|
+
|
34
|
+
# All the avaiable Resource types
|
35
|
+
def self.resources
|
36
|
+
@resources ||= []
|
37
|
+
end
|
38
|
+
|
39
|
+
# All the Resource types that are processable.
|
40
|
+
def self.processable_resources
|
41
|
+
resources.select { |resource| resource.processable? }
|
37
42
|
end
|
38
43
|
end
|
44
|
+
|
45
|
+
require File.join(lib_dir, "massimo", "resource", "base")
|
46
|
+
require File.join(lib_dir, "massimo", "view")
|
47
|
+
require File.join(lib_dir, "massimo", "page")
|
48
|
+
require File.join(lib_dir, "massimo", "stylesheet")
|
49
|
+
require File.join(lib_dir, "massimo", "javascript")
|
data/massimo.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{massimo}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Peter Browne"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-09}
|
13
13
|
s.default_executable = %q{massimo}
|
14
14
|
s.description = %q{Massimo builds HTML, Javascript, and CSS Files from your source.}
|
15
|
-
s.email = %q{
|
15
|
+
s.email = %q{me@petebrowne.com}
|
16
16
|
s.executables = ["massimo"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
@@ -31,7 +31,9 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/massimo/helpers.rb",
|
32
32
|
"lib/massimo/javascript.rb",
|
33
33
|
"lib/massimo/page.rb",
|
34
|
-
"lib/massimo/resource.rb",
|
34
|
+
"lib/massimo/resource/base.rb",
|
35
|
+
"lib/massimo/resource/collection.rb",
|
36
|
+
"lib/massimo/resource/processing.rb",
|
35
37
|
"lib/massimo/site.rb",
|
36
38
|
"lib/massimo/stylesheet.rb",
|
37
39
|
"lib/massimo/templates.rb",
|
@@ -71,6 +73,7 @@ Gem::Specification.new do |s|
|
|
71
73
|
"test/source/views/with_helper.haml",
|
72
74
|
"test/source/views/with_locals.haml",
|
73
75
|
"test/source/views/without_locals.haml",
|
76
|
+
"test/test_helpers.rb",
|
74
77
|
"test/test_javascript.rb",
|
75
78
|
"test/test_page.rb",
|
76
79
|
"test/test_resource.rb",
|
@@ -88,6 +91,7 @@ Gem::Specification.new do |s|
|
|
88
91
|
"test/helper.rb",
|
89
92
|
"test/source/helpers/test_helper.rb",
|
90
93
|
"test/source/lib/site.rb",
|
94
|
+
"test/test_helpers.rb",
|
91
95
|
"test/test_javascript.rb",
|
92
96
|
"test/test_page.rb",
|
93
97
|
"test/test_resource.rb",
|
@@ -104,7 +108,7 @@ Gem::Specification.new do |s|
|
|
104
108
|
s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
|
105
109
|
s.add_development_dependency(%q<yard>, [">= 0.5.2"])
|
106
110
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
|
107
|
-
s.add_runtime_dependency(%q<sinatra_more>, [">= 0.3.
|
111
|
+
s.add_runtime_dependency(%q<sinatra_more>, [">= 0.3.29"])
|
108
112
|
s.add_runtime_dependency(%q<directory_watcher>, [">= 1.3.1"])
|
109
113
|
s.add_runtime_dependency(%q<sprockets>, [">= 1.0.2"])
|
110
114
|
s.add_runtime_dependency(%q<jsmin>, [">= 1.0.1"])
|
@@ -112,7 +116,7 @@ Gem::Specification.new do |s|
|
|
112
116
|
s.add_dependency(%q<shoulda>, [">= 2.10.2"])
|
113
117
|
s.add_dependency(%q<yard>, [">= 0.5.2"])
|
114
118
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
115
|
-
s.add_dependency(%q<sinatra_more>, [">= 0.3.
|
119
|
+
s.add_dependency(%q<sinatra_more>, [">= 0.3.29"])
|
116
120
|
s.add_dependency(%q<directory_watcher>, [">= 1.3.1"])
|
117
121
|
s.add_dependency(%q<sprockets>, [">= 1.0.2"])
|
118
122
|
s.add_dependency(%q<jsmin>, [">= 1.0.1"])
|
@@ -121,7 +125,7 @@ Gem::Specification.new do |s|
|
|
121
125
|
s.add_dependency(%q<shoulda>, [">= 2.10.2"])
|
122
126
|
s.add_dependency(%q<yard>, [">= 0.5.2"])
|
123
127
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
124
|
-
s.add_dependency(%q<sinatra_more>, [">= 0.3.
|
128
|
+
s.add_dependency(%q<sinatra_more>, [">= 0.3.29"])
|
125
129
|
s.add_dependency(%q<directory_watcher>, [">= 1.3.1"])
|
126
130
|
s.add_dependency(%q<sprockets>, [">= 1.0.2"])
|
127
131
|
s.add_dependency(%q<jsmin>, [">= 1.0.1"])
|
data/test/helper.rb
CHANGED
@@ -9,8 +9,7 @@ require "assertions"
|
|
9
9
|
require "rr"
|
10
10
|
|
11
11
|
# Load Massimo
|
12
|
-
|
13
|
-
require "massimo"
|
12
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "massimo")
|
14
13
|
|
15
14
|
class Test::Unit::TestCase
|
16
15
|
include Assertions
|
@@ -33,7 +32,7 @@ class Test::Unit::TestCase
|
|
33
32
|
|
34
33
|
#
|
35
34
|
def site(options = {})
|
36
|
-
@site = Massimo::Site({
|
35
|
+
@site = ::Massimo::Site({
|
37
36
|
:source => source_dir,
|
38
37
|
:output => output_dir,
|
39
38
|
:sass => { :cache => false }
|
@@ -42,13 +41,20 @@ class Test::Unit::TestCase
|
|
42
41
|
|
43
42
|
#
|
44
43
|
def page(*path)
|
45
|
-
@page ||= Massimo::Page.new(source_dir("pages", *path))
|
44
|
+
@page ||= ::Massimo::Page.new(source_dir("pages", *path))
|
46
45
|
end
|
47
46
|
|
48
47
|
#
|
49
48
|
def view(*path)
|
50
49
|
return @view if defined?(@view)
|
51
50
|
meta_data = path.extract_options!
|
52
|
-
@view = Massimo::View.new(source_dir("views", *path), meta_data)
|
51
|
+
@view = ::Massimo::View.new(source_dir("views", *path), meta_data)
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
def source_page_paths
|
56
|
+
@source_page_paths ||= Pathname.glob(source_dir("pages", "**", "*")).
|
57
|
+
reject { |p| p.basename.to_s =~ /^_/ || File.directory?(p) }.
|
58
|
+
collect { |p| p.basename }
|
53
59
|
end
|
54
60
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helper")
|
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
|
data/test/test_page.rb
CHANGED
@@ -104,11 +104,17 @@ class TestPage < Test::Unit::TestCase
|
|
104
104
|
end
|
105
105
|
|
106
106
|
end
|
107
|
+
|
107
108
|
context "with layouts" do
|
108
109
|
|
109
110
|
should "filter the content from the page file correctly" do
|
110
111
|
assert_equal "<title>ERB With Layout</title>\n<body><h1>ERB With Layout</h1></body>\n", page("erb_with_layout.erb").render
|
111
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
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
data/test/test_resource.rb
CHANGED
@@ -6,22 +6,65 @@ class TestResource < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
should "raise an error when reading a non-existent resource" do
|
8
8
|
assert_raise Massimo::MissingResource do
|
9
|
-
Massimo::Resource.new("some/non-existent/file")
|
9
|
+
Massimo::Resource::Base.new("some/non-existent/file")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
should "raise an error when reading an invalid resource" do
|
14
14
|
assert_raise Massimo::InvalidResource do
|
15
|
-
Massimo::Resource.new(source_dir("views", "layouts"))
|
15
|
+
Massimo::Resource::Base.new(source_dir("views", "layouts"))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
should "have a method to get the resource's type (extension)" do
|
20
|
-
assert_equal Massimo::Resource.new(source_dir("pages", "about_us.erb")).resource_type, "erb"
|
20
|
+
assert_equal Massimo::Resource::Base.new(source_dir("pages", "about_us.erb")).resource_type, "erb"
|
21
21
|
end
|
22
22
|
|
23
23
|
should "render the resource files data" do
|
24
|
-
assert_equal Massimo::Resource.new(source_dir("pages", "without_meta_data.haml")).render, "%h1 A Page without meta_data"
|
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
|
25
68
|
end
|
26
69
|
end
|
27
70
|
end
|