madride 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,4 +5,4 @@ Install dependencies and start server:
5
5
  bundle install
6
6
  bundle exec madride --with bootstrap --data data.yml -- assets pages
7
7
 
8
- Now you can open http://0.0.0.0:3000/index.html in your browser
8
+ Now you can open http://0.0.0.0:3000/ in your browser
@@ -0,0 +1,13 @@
1
+ doctype
2
+ html[lang="en"]
3
+ head
4
+ meta[charset="utf-8"]
5
+ title Madride Demo
6
+ meta[name="viewport" content="width=device-width, initial-scale=1.0"]
7
+ meta[name="description" content=""]
8
+ meta[name="author" content=""]
9
+ link[href="/app.css" rel="stylesheet"]
10
+ style[type="text/css"] body { margin-top: 30px; }
11
+
12
+ body
13
+ .container == yield
@@ -0,0 +1,45 @@
1
+ //= layout _default
2
+ .hero-unit
3
+ h1#madride Hello, world!
4
+ p
5
+ | This is a template for a simple marketing or informational website.
6
+ | It includes a large callout called the hero unit and three
7
+ | supporting pieces of content. Use it as a starting point to create
8
+ | something more unique.
9
+ p
10
+ a.btn.btn-primary.btn-large Learn more »
11
+
12
+ .row
13
+ .span4
14
+ h2 Heading
15
+ p
16
+ | Donec id elit non mi porta gravida at eget metus. Fusce dapibus,
17
+ | tellus ac cursus commodo, tortor mauris condimentum nibh, ut
18
+ | fermentum massa justo sit amet risus. Etiam porta sem malesuada
19
+ | magna mollis euismod. Donec sed odio dui.
20
+ p
21
+ a.btn[href="#"] View details »
22
+ .span4
23
+ h2 Heading
24
+ p
25
+ | Donec id elit non mi porta gravida at eget metus. Fusce dapibus,
26
+ | tellus ac cursus commodo, tortor mauris condimentum nibh, ut
27
+ | fermentum massa justo sit amet risus. Etiam porta sem malesuada
28
+ | magna mollis euismod. Donec sed odio dui.
29
+ p
30
+ a.btn[href="#"] View details »
31
+ .span4
32
+ h2 Heading
33
+ p
34
+ | Donec sed odio dui. Cras justo odio, dapibus ac facilisis in,
35
+ | egestas eget quam. Vestibulum id ligula porta felis euismod
36
+ | semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris
37
+ | condimentum nibh, ut fermentum massa justo sit amet risus.
38
+ p
39
+ a.btn[href="#"] View details »
40
+ hr
41
+ footer
42
+ p
43
+ ' This is a demo of madride.
44
+ ' Based on a <a href="#{bootstrap_demo_url}">Basic marketing site</a>
45
+ ' example of Bootstrap from Twitter.
@@ -0,0 +1,62 @@
1
+ require 'sprockets/context'
2
+
3
+
4
+ module Madride
5
+ class Context < Sprockets::Context
6
+ def self.locals
7
+ @locals ||= {}
8
+ end
9
+
10
+
11
+ def locals
12
+ self.class.locals
13
+ end
14
+
15
+
16
+ def layout= path
17
+ depend_on_asset path
18
+ @layout = path
19
+ end
20
+
21
+
22
+ def evaluate(path, options = {}, &block)
23
+ pathname = resolve(path)
24
+ attributes = environment.attributes_for(pathname)
25
+ processors = options[:processors] || attributes.processors
26
+
27
+ if options[:data]
28
+ result = options[:data]
29
+ else
30
+ if environment.respond_to?(:default_external_encoding)
31
+ mime_type = environment.mime_types(pathname.extname)
32
+ encoding = environment.encoding_for_mime_type(mime_type)
33
+ result = Sprockets::Utils.read_unicode(pathname, encoding)
34
+ else
35
+ result = Sprockets::Utils.read_unicode(pathname)
36
+ end
37
+ end
38
+
39
+ processors.each do |processor|
40
+ begin
41
+ template = processor.new(pathname.to_s) { result }
42
+ result = template.render(self, locals){ options[:yield] }
43
+ rescue Exception => e
44
+ annotate_exception! e
45
+ raise
46
+ end
47
+ end
48
+
49
+ if @layout
50
+ begin
51
+ layout = self.class.new(environment, @layout, resolve(@layout))
52
+ result = layout.evaluate(@layout, :yield => result)
53
+ rescue Exception => e
54
+ annotate_exception! e
55
+ raise
56
+ end
57
+ end
58
+
59
+ result
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,11 @@
1
+ require "sprockets/directive_processor"
2
+
3
+ module Madride
4
+ class DirectiveProcessor < Sprockets::DirectiveProcessor
5
+ protected
6
+
7
+ def process_layout_directive path
8
+ context.layout = path
9
+ end
10
+ end
11
+ end
@@ -3,7 +3,8 @@ require "tilt/haml"
3
3
 
4
4
 
5
5
  require "madride/templates/slim"
6
- require "madride/context_patch"
6
+ require "madride/context"
7
+ require "madride/directive_processor"
7
8
 
8
9
 
9
10
  module Madride
@@ -11,20 +12,20 @@ module Madride
11
12
  def initialize *args
12
13
  super
13
14
 
15
+ @context_class = Class.new(Context)
16
+
17
+ # unregister .htm and register .html instead
18
+ register_mime_type nil, '.htm'
19
+ register_mime_type 'text/html', '.html'
20
+
14
21
  register_engine '.slim', SlimTemplate
15
22
  register_engine '.haml', Tilt::HamlTemplate
16
23
 
17
- # text/html extension is .htm, so we need to reassign aliases map manually
18
-
19
- @trail.alias_extension '.slim', '.html'
20
- @trail.alias_extension '.haml', '.html'
21
- @trail.alias_extension '.htm', '.html'
24
+ register_preprocessor 'text/html', DirectiveProcessor
22
25
 
23
26
  Madride.paths.each do |path|
24
27
  append_path path
25
28
  end
26
-
27
- @context_class.send(:include, ContextPatch)
28
29
  end
29
30
 
30
31
 
@@ -1,3 +1,3 @@
1
1
  module Madride
2
- VERSION = "1.0.7"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -46,5 +46,16 @@ module Madride
46
46
  asset.should_not be_nil
47
47
  asset.to_s.should match(%r{<title>\s*Simple Page\s*</title>})
48
48
  end
49
+
50
+
51
+ it "should use default layout if layouts path provided" do
52
+ env = environment
53
+ env.append_path "layouts"
54
+ env.locals.merge! YAML.load_file fixtures_path('data.yml').to_s
55
+
56
+ asset = env["video/index.html"]
57
+ asset.should_not be_nil
58
+ asset.to_s.should match(%r{<title>\s*Default Layout\s*</title>})
59
+ end
49
60
  end
50
61
  end
@@ -2,3 +2,8 @@ bands:
2
2
  - pennywise
3
3
  - dead kennedys
4
4
  - the sex pistols
5
+
6
+ movies:
7
+ - el mariachi
8
+ - desperado
9
+ - once upon a time in mexico
@@ -0,0 +1,6 @@
1
+ html
2
+ head
3
+ title Default Layout
4
+
5
+ body
6
+ == yield
@@ -0,0 +1,4 @@
1
+ //= layout _simple
2
+ h1 List of Videos
3
+ - for title in movies
4
+ h2 title
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madride
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -159,9 +159,11 @@ files:
159
159
  - example/README.md
160
160
  - example/assets/app.css
161
161
  - example/data.yml
162
- - example/pages/index.html.slim
162
+ - example/pages/_default.slim
163
+ - example/pages/index.slim
163
164
  - lib/madride.rb
164
- - lib/madride/context_patch.rb
165
+ - lib/madride/context.rb
166
+ - lib/madride/directive_processor.rb
165
167
  - lib/madride/environment.rb
166
168
  - lib/madride/templates/slim.rb
167
169
  - lib/madride/version.rb
@@ -172,11 +174,13 @@ files:
172
174
  - spec/fixtures/assets/app.js
173
175
  - spec/fixtures/assets/madride.js
174
176
  - spec/fixtures/data.yml
177
+ - spec/fixtures/layouts/_simple.slim
175
178
  - spec/fixtures/pages/about/index.html.slim
176
179
  - spec/fixtures/pages/index.html.slim
177
180
  - spec/fixtures/pages/music.html.slim
178
181
  - spec/fixtures/pages/music/bands.html.slim
179
182
  - spec/fixtures/pages/simple.slim
183
+ - spec/fixtures/pages/video/index.html.slim
180
184
  - spec/server_spec.rb
181
185
  - spec/spec_helper.rb
182
186
  homepage: https://github.com/madride/madride
@@ -193,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
197
  version: '0'
194
198
  segments:
195
199
  - 0
196
- hash: -393285937
200
+ hash: 316891443
197
201
  required_rubygems_version: !ruby/object:Gem::Requirement
198
202
  none: false
199
203
  requirements:
@@ -202,13 +206,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
206
  version: '0'
203
207
  segments:
204
208
  - 0
205
- hash: -393285937
209
+ hash: 316891443
206
210
  requirements: []
207
211
  rubyforge_project:
208
212
  rubygems_version: 1.8.23
209
213
  signing_key:
210
214
  specification_version: 3
211
- summary: madride-1.0.7
215
+ summary: madride-1.1.0
212
216
  test_files:
213
217
  - spec/.gitkeep
214
218
  - spec/environment_spec.rb
@@ -216,10 +220,12 @@ test_files:
216
220
  - spec/fixtures/assets/app.js
217
221
  - spec/fixtures/assets/madride.js
218
222
  - spec/fixtures/data.yml
223
+ - spec/fixtures/layouts/_simple.slim
219
224
  - spec/fixtures/pages/about/index.html.slim
220
225
  - spec/fixtures/pages/index.html.slim
221
226
  - spec/fixtures/pages/music.html.slim
222
227
  - spec/fixtures/pages/music/bands.html.slim
223
228
  - spec/fixtures/pages/simple.slim
229
+ - spec/fixtures/pages/video/index.html.slim
224
230
  - spec/server_spec.rb
225
231
  - spec/spec_helper.rb
@@ -1,57 +0,0 @@
1
- doctype
2
- html[lang="en"]
3
- head
4
- meta[charset="utf-8"]
5
- title Madride Demo
6
- meta[name="viewport" content="width=device-width, initial-scale=1.0"]
7
- meta[name="description" content=""]
8
- meta[name="author" content=""]
9
- link[href="/app.css" rel="stylesheet"]
10
- style[type="text/css"] body { margin-top: 30px; }
11
-
12
- body
13
- .container
14
- .hero-unit
15
- h1#madride Hello, world!
16
- p
17
- | This is a template for a simple marketing or informational website.
18
- | It includes a large callout called the hero unit and three
19
- | supporting pieces of content. Use it as a starting point to create
20
- | something more unique.
21
- p
22
- a.btn.btn-primary.btn-large Learn more »
23
-
24
- .row
25
- .span4
26
- h2 Heading
27
- p
28
- | Donec id elit non mi porta gravida at eget metus. Fusce dapibus,
29
- | tellus ac cursus commodo, tortor mauris condimentum nibh, ut
30
- | fermentum massa justo sit amet risus. Etiam porta sem malesuada
31
- | magna mollis euismod. Donec sed odio dui.
32
- p
33
- a.btn[href="#"] View details »
34
- .span4
35
- h2 Heading
36
- p
37
- | Donec id elit non mi porta gravida at eget metus. Fusce dapibus,
38
- | tellus ac cursus commodo, tortor mauris condimentum nibh, ut
39
- | fermentum massa justo sit amet risus. Etiam porta sem malesuada
40
- | magna mollis euismod. Donec sed odio dui.
41
- p
42
- a.btn[href="#"] View details »
43
- .span4
44
- h2 Heading
45
- p
46
- | Donec sed odio dui. Cras justo odio, dapibus ac facilisis in,
47
- | egestas eget quam. Vestibulum id ligula porta felis euismod
48
- | semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris
49
- | condimentum nibh, ut fermentum massa justo sit amet risus.
50
- p
51
- a.btn[href="#"] View details »
52
- hr
53
- footer
54
- p
55
- ' This is a demo of madride.
56
- ' Based on a <a href="#{bootstrap_demo_url}">Basic marketing site</a>
57
- ' example of Bootstrap from Twitter.
@@ -1,48 +0,0 @@
1
- module Madride
2
- module ContextPatch
3
- def self.included(base)
4
- base.send(:include, InstanceMethods)
5
-
6
- base.class_eval do
7
- @locals = {}
8
-
9
- class << self
10
- attr_reader :locals
11
- end
12
- end
13
- end
14
-
15
-
16
- module InstanceMethods
17
- def evaluate(path, options = {})
18
- pathname = resolve(path)
19
- attributes = environment.attributes_for(pathname)
20
- processors = options[:processors] || attributes.processors
21
-
22
- if options[:data]
23
- result = options[:data]
24
- else
25
- if environment.respond_to?(:default_external_encoding)
26
- mime_type = environment.mime_types(pathname.extname)
27
- encoding = environment.encoding_for_mime_type(mime_type)
28
- result = Sprockets::Utils.read_unicode(pathname, encoding)
29
- else
30
- result = Sprockets::Utils.read_unicode(pathname)
31
- end
32
- end
33
-
34
- processors.each do |processor|
35
- begin
36
- template = processor.new(pathname.to_s) { result }
37
- result = template.render(self, self.class.locals)
38
- rescue Exception => e
39
- annotate_exception! e
40
- raise
41
- end
42
- end
43
-
44
- result
45
- end
46
- end
47
- end
48
- end