massimo 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Features
12
12
  * Uses familiar helper methods from [Padrino::Helpers](http://github.com/padrino/padrino-framework)
13
13
  * Supports custom helper methods like [Rails](http://rubyonrails.org/) and [Sinatra](http://www.sinatrarb.com/)
14
14
  * Concats javascripts using [Sprockets](http://getsprockets.org/)
15
- and then compresses them using whichever library you want.
15
+ and then compresses them using whichever library you want
16
16
  * Renders stylesheets using either [Sass](http://sass-lang.com/) or [Less](http://lesscss.org/)
17
17
  * Automatically creates pretty URLs
18
18
 
@@ -30,7 +30,8 @@ module Massimo
30
30
  CSS_COMPRESSORS = {
31
31
  :cssmin => Crush::CSSMin,
32
32
  :rainpress => Crush::Rainpress,
33
- :yui => Crush::YUI::CssCompressor
33
+ :yui => Crush::YUI::CssCompressor,
34
+ :sass => Crush::Sass::Engine
34
35
  }
35
36
 
36
37
  # Creates a new configuration. Takes either a hash of options
@@ -94,7 +95,7 @@ module Massimo
94
95
  #
95
96
  # @param [Hash] options The hash of options to use.
96
97
  def js_compressor_options=(options)
97
- self.js = options
98
+ self.js_options = options
98
99
  end
99
100
 
100
101
  # Sets up Massimo to compress CSS files. By default,
@@ -122,7 +123,7 @@ module Massimo
122
123
  #
123
124
  # @param [Hash] options The hash of options to use.
124
125
  def css_compressor_options=(options)
125
- self.css = options
126
+ self.css_options = options
126
127
  end
127
128
 
128
129
  # Get a full, expanded path for the given resource name. This is either set
@@ -150,7 +151,7 @@ module Massimo
150
151
  # this is how we get the options set for Haml or Sass during processing.
151
152
  def options_for(lib_name)
152
153
  return options_for("sass") if lib_name == "scss"
153
- send(lib_name) || {}
154
+ send("#{lib_name}_options") || send(lib_name) || {}
154
155
  end
155
156
  end
156
157
  end
data/lib/massimo/page.rb CHANGED
@@ -6,6 +6,16 @@ require 'yaml'
6
6
 
7
7
  module Massimo
8
8
  class Page < Resource
9
+ FRONT_MATTER_PARSER = /
10
+ (
11
+ \A\s* # Beginning of file
12
+ ^---\s*$\n* # Start YAML Block
13
+ (.*?)\n* # YAML data
14
+ ^---\s*$\n* # End YAML Block
15
+ )
16
+ (.*) # Rest of File
17
+ /mx
18
+
9
19
  def render
10
20
  output = super
11
21
 
@@ -54,32 +64,28 @@ module Massimo
54
64
  end
55
65
 
56
66
  def read_source
67
+ super
68
+
57
69
  case source_path.extname
58
70
  when '.yml', '.yaml'
59
- @meta_data = (YAML.load(source_path.read) || {}).symbolize_keys
71
+ @meta_data = load_yaml_data @content
60
72
  @content = @meta_data[:content] || ''
61
73
  else
62
- @line = nil
63
- @content = ''
64
- front_matter = false
65
- meta_data = ''
66
-
67
- source_path.open do |file|
68
- file.each do |line|
69
- if line =~ /\A---\s*\Z/
70
- front_matter = !front_matter
71
- else
72
- if front_matter
73
- meta_data << line
74
- else
75
- @line ||= file.lineno
76
- @content << line
77
- end
78
- end
79
- end
74
+ if FRONT_MATTER_PARSER.match @content
75
+ @line = $1.lines.count + 1
76
+ @meta_data = load_yaml_data $2
77
+ @content = $3
80
78
  end
79
+ end
81
80
 
82
- @meta_data = (YAML.load(meta_data) || {}).symbolize_keys
81
+ @meta_data ||= {}
82
+ end
83
+
84
+ def load_yaml_data(data)
85
+ begin
86
+ (YAML.load(data) || {}).symbolize_keys
87
+ rescue => e
88
+ raise "Error loading front matter from #{source_path}: #{e.message}"
83
89
  end
84
90
  end
85
91
 
@@ -1,3 +1,3 @@
1
1
  module Massimo
2
- VERSION = '0.10.0'
2
+ VERSION = '0.10.1'
3
3
  end
data/lib/massimo.rb CHANGED
File without changes
@@ -79,6 +79,11 @@ describe Massimo::Config do
79
79
 
80
80
  describe '#options_for' do
81
81
  it 'returns the options set for the given name' do
82
+ config = Massimo::Config.new(:sass_options => { :style => :compressed })
83
+ config.options_for(:sass).should == { :style => :compressed }
84
+ end
85
+
86
+ it 'returns the options set with the alternate syntax' do
82
87
  config = Massimo::Config.new(:sass => { :style => :compressed })
83
88
  config.options_for(:sass).should == { :style => :compressed }
84
89
  end
@@ -159,5 +159,28 @@ describe Massimo::Stylesheet do
159
159
  end
160
160
  end
161
161
  end
162
+
163
+ context 'using :sass' do
164
+ it 'compresses using Sass::Engine' do
165
+ Massimo.config.css_compressor = :sass
166
+ with_file 'stylesheets/main.css', code do
167
+ compressor = mock!.render { '' }
168
+ mock_module('Sass::Engine').new(code, :style => :compressed, :syntax => :scss) { compressor }
169
+ stylesheet.render
170
+ end
171
+ end
172
+
173
+ context 'with configuration' do
174
+ it 'passes configuration to Sass::Engine' do
175
+ Massimo.config.css_compressor = :sass
176
+ Massimo.config.css_compressor_options = { :cache => false }
177
+ with_file 'stylesheets/main.css', code do
178
+ compressor = mock!.render { '' }
179
+ mock_module('Sass::Engine').new(code, :style => :compressed, :syntax => :scss, :cache => false) { compressor }
180
+ stylesheet.render
181
+ end
182
+ end
183
+ end
184
+ end
162
185
  end
163
186
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: massimo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 10
9
- - 0
10
- version: 0.10.0
9
+ - 1
10
+ version: 0.10.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pete Browne