markaby 0.6.10 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ = 0.7.0
2
+
3
+ * Sinatra 1.0 support
4
+ * Full Tilt 1.0+ support, including "yield" support for layouts
5
+
1
6
  = 0.6.10
2
7
 
3
8
  * Rails fixes for form_for + content_for
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{markaby}
8
- s.version = "0.6.10"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["_why", "Tim Fletcher", "John Barton", "spox", "smtlaissezfaire"]
12
- s.date = %q{2010-08-13}
12
+ s.date = %q{2010-08-15}
13
13
  s.description = %q{Tim Fletcher and _why's ruby driven HTML templating system}
14
14
  s.email = %q{scott@railsnewbie.com}
15
15
  s.extra_rdoc_files = [
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/markaby/rails/current.rb",
34
34
  "lib/markaby/rails/deprecated.rb",
35
35
  "lib/markaby/rails/rails_builder.rb",
36
+ "lib/markaby/sinatra.rb",
36
37
  "lib/markaby/tags.rb",
37
38
  "lib/markaby/tilt.rb",
38
39
  "spec/markaby/builder_spec.rb",
@@ -46,6 +47,7 @@ Gem::Specification.new do |s|
46
47
  "spec/markaby/rails/views/markaby/_partial_child_with_locals.mab",
47
48
  "spec/markaby/rails/views/markaby/access_to_helpers.mab",
48
49
  "spec/markaby/rails/views/markaby/broken.mab",
50
+ "spec/markaby/rails/views/markaby/commented_out_template.mab",
49
51
  "spec/markaby/rails/views/markaby/correct_template_values.mab",
50
52
  "spec/markaby/rails/views/markaby/double_output.mab",
51
53
  "spec/markaby/rails/views/markaby/form_for.mab",
@@ -66,6 +68,14 @@ Gem::Specification.new do |s|
66
68
  "spec/markaby/rails/views/markaby/yielding_with_content_for.mab",
67
69
  "spec/markaby/rails_spec.rb",
68
70
  "spec/markaby/rails_version_spec.rb",
71
+ "spec/markaby/sinatra/app.rb",
72
+ "spec/markaby/sinatra/sinatra_spec.rb",
73
+ "spec/markaby/sinatra/views/helpers.mab",
74
+ "spec/markaby/sinatra/views/layout.mab",
75
+ "spec/markaby/sinatra/views/markaby_template.mab",
76
+ "spec/markaby/sinatra/views/scope_instance_variables.mab",
77
+ "spec/markaby/sinatra/views/simple_html.mab",
78
+ "spec/markaby/sinatra/views/variables.mab",
69
79
  "spec/markaby/tilt/erb.erb",
70
80
  "spec/markaby/tilt/locals.mab",
71
81
  "spec/markaby/tilt/markaby.mab",
@@ -90,6 +100,8 @@ Gem::Specification.new do |s|
90
100
  "spec/markaby/rails/spec_helper.rb",
91
101
  "spec/markaby/rails_spec.rb",
92
102
  "spec/markaby/rails_version_spec.rb",
103
+ "spec/markaby/sinatra/app.rb",
104
+ "spec/markaby/sinatra/sinatra_spec.rb",
93
105
  "spec/markaby/tilt_spec.rb",
94
106
  "spec/spec_helper.rb"
95
107
  ]
@@ -5,7 +5,7 @@ It is an alternative to ERb which weaves the two languages together.
5
5
  Also a replacement for templating languages which use primitive languages
6
6
  that blend with HTML.
7
7
 
8
- == Using Markaby as a Rails plugin
8
+ == Using Markaby as a Rails plugin / gem
9
9
 
10
10
  Write Rails templates in pure Ruby. Example layout:
11
11
 
@@ -18,23 +18,37 @@ Write Rails templates in pure Ruby. Example layout:
18
18
  body do
19
19
  p flash[:notice], :style => "color: green"
20
20
 
21
- self << content_for_layout
21
+ div.signup! do
22
+ form_for @user do |f|
23
+ f.text_field :email
24
+ end
25
+ end
26
+
27
+ yield
22
28
  end
23
29
  end
24
30
 
25
- Markaby supports many versions of rails:
31
+ Markaby templates end in .mab
32
+
33
+ Markaby supports many versions of rails, including the latest rails:
26
34
 
27
35
  1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 2.2.0,
28
36
  2.2.1, 2.2.2, 2.2.3, 2.3.1, 2.3.2, 2.3.2.1,
29
37
  2.3.3, 2.3.3.1, 2.3.4, 2.3.5, 2.3.6, 2.3.7,
30
38
  2.3.8
31
39
 
32
- Install it as a plugin:
40
+ Rails 3.0 support is planned.
41
+
42
+ === Install it as a plugin
33
43
 
34
44
  script/plugin install git://github.com/markaby/markaby.git
35
45
 
46
+ === Install it as a gem
47
+
48
+ gem install markaby
49
+
36
50
  If you are loading it in a different way (from a gem), make sure
37
- it's on the LOAD_PATH, and add the following in
51
+ it's on the $LOAD_PATH, and add the following in
38
52
  an initializer (config/initializers/markaby.rb will work):
39
53
 
40
54
  require 'markaby'
@@ -42,6 +56,25 @@ an initializer (config/initializers/markaby.rb will work):
42
56
 
43
57
  Markaby::Rails.load
44
58
 
59
+ Or, you could try config.gem, but that's now known as a bad idea.
60
+
61
+
62
+ == Using Markaby with Sinatra (1.0+)
63
+
64
+ require 'markaby/sinatra'
65
+
66
+ get '/foo' do
67
+ mab :my_template # my_template.mab in the sinatra view path
68
+ end
69
+
70
+ If you are looking for sinatra support pre 0.7, see http://github.com/sbfaulkner/sinatra-markaby
71
+
72
+
73
+ == Using Markaby with other frameworks
74
+
75
+ Markaby has a Tilt module, so in principle, any web framework that supports
76
+ Tilt can/will also support Markaby.
77
+
45
78
 
46
79
  == Using Markaby as a Ruby class
47
80
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.10
1
+ 0.7.0
@@ -7,9 +7,11 @@ module Markaby
7
7
 
8
8
  def compile(template, local_assigns={})
9
9
  <<-CODE
10
- handler = Markaby::Rails::TemplateHandler.new
11
- handler.view = self
12
- handler.render(lambda { #{template.source} }, local_assigns)
10
+ __template_handler = Markaby::Rails::TemplateHandler.new
11
+ __template_handler.view = self
12
+ __template_handler.render(lambda {
13
+ #{template.source}
14
+ }, local_assigns)
13
15
  CODE
14
16
  end
15
17
 
@@ -41,7 +43,30 @@ module Markaby
41
43
  end
42
44
  end
43
45
 
44
- module CaptureHelper
46
+ module Helpers
47
+ # allow fragments to act as strings. url_for has a
48
+ # case statment in it:
49
+ #
50
+ # case options
51
+ # when String
52
+ # ...
53
+ #
54
+ # which essential is doing the following:
55
+ #
56
+ # String === options
57
+ #
58
+ # That assertion fails with Markaby::Fragments, which are essential
59
+ # builder/string fragments.
60
+ #
61
+ def url_for(options={})
62
+ case options
63
+ when Markaby::Fragment
64
+ super(options.to_s)
65
+ else
66
+ super
67
+ end
68
+ end
69
+
45
70
  def capture(*args, &block)
46
71
  if output_buffer.kind_of?(Markaby::Builder)
47
72
  output_buffer.capture(&block)
@@ -53,34 +78,8 @@ module Markaby
53
78
  end
54
79
  end
55
80
 
56
- # allow fragments to act as strings. url_for has a
57
- # nasty case statment in it:
58
- #
59
- # case options
60
- # when String
61
- # ...
62
- #
63
- # which essential is doing the following:
64
- #
65
- # String === options
66
- #
67
- ActionView::Helpers::UrlHelper.class_eval do
68
- alias_method :url_for_aliased_by_markaby, :url_for
69
-
70
- def url_for(options={})
71
- options ||= {}
72
-
73
- url = case options
74
- when Markaby::Fragment
75
- url_for_aliased_by_markaby(options.to_s)
76
- else
77
- url_for_aliased_by_markaby(options)
78
- end
79
- end
80
- end
81
-
82
81
  ActionView::Base.class_eval do
83
- include Markaby::Rails::CaptureHelper
82
+ include Markaby::Rails::Helpers
84
83
  end
85
84
 
86
85
  ActionView::Template.register_template_handler(:mab, Markaby::Rails::TemplateHandler)
@@ -0,0 +1,18 @@
1
+ require 'markaby/tilt'
2
+ require 'sinatra'
3
+
4
+ module Sinatra
5
+ class Base
6
+ # sinatra's #render looks for options in Sinatra::Application
7
+ # by asking if it responds_to?(:mab)
8
+ # Unfortunately, if the the mab kernel method is included,
9
+ # Sinatra::Application will respond_to? it.
10
+ set :mab, {}
11
+ end
12
+
13
+ module Templates
14
+ def mab(template, options={}, locals={})
15
+ render :mab, template, options, locals
16
+ end
17
+ end
18
+ end
@@ -1,12 +1,33 @@
1
+ require 'markaby'
1
2
  require 'tilt'
2
3
 
3
4
  module Markaby
4
5
  module Tilt
5
6
  class Template < ::Tilt::Template
7
+ class TiltBuilder < Markaby::Builder
8
+ def __capture_markaby_tilt__(&block)
9
+ __run_markaby_tilt__ do
10
+ text capture(&block)
11
+ end
12
+ end
13
+ end
14
+
6
15
  def evaluate(scope, locals, &block)
7
- builder = Markaby::Builder.new({}, scope)
16
+ builder = TiltBuilder.new({}, scope)
8
17
  builder.locals = locals
9
- builder.instance_eval(data, __FILE__, __LINE__)
18
+
19
+ if block
20
+ builder.instance_eval <<-CODE, __FILE__, __LINE__
21
+ def __run_markaby_tilt__
22
+ #{data}
23
+ end
24
+ CODE
25
+
26
+ builder.__capture_markaby_tilt__(&block)
27
+ else
28
+ builder.instance_eval(data, __FILE__, __LINE__)
29
+ end
30
+
10
31
  builder.to_s
11
32
  end
12
33
 
@@ -17,5 +38,5 @@ end
17
38
 
18
39
  module Tilt
19
40
  MarkabyTemplate = Markaby::Tilt::Template
20
- register "mab", MarkabyTemplate
41
+ register :mab, MarkabyTemplate
21
42
  end
@@ -0,0 +1 @@
1
+ # <!-- raise an ruby error -->
@@ -116,6 +116,9 @@ if RUNNING_RAILS
116
116
  def routes
117
117
  end
118
118
 
119
+ def commented_out_template
120
+ end
121
+
119
122
  def render_with_yielding
120
123
  render :layout => "layout.mab",
121
124
  :template => "markaby/yielding"
@@ -255,6 +258,14 @@ if RUNNING_RAILS
255
258
  assert_equal expected_output, @response.body
256
259
  end
257
260
 
261
+ def test_commented_out_template_cant_raise_errors
262
+ get :commented_out_template
263
+ assert_response :success
264
+
265
+ expected_output = ""
266
+ assert_equal expected_output, @response.body
267
+ end
268
+
258
269
  if Rails::VERSION::MAJOR >= 2
259
270
  def test_renders_form_for_properly
260
271
  get :renders_form_for
@@ -0,0 +1,49 @@
1
+ set :views, lambda { File.join(File.dirname(__FILE__), "views") }
2
+
3
+ get '/empty_action' do
4
+ "hi there"
5
+ end
6
+
7
+ get '/markaby_template' do
8
+ mab :markaby_template
9
+ end
10
+
11
+ get '/simple_html' do
12
+ mab :simple_html
13
+ end
14
+
15
+ get '/variables' do
16
+ mab :variables, {}, :name => "Scott Taylor"
17
+ end
18
+
19
+ get '/variables_with_locals' do
20
+ mab :variables, :locals => { :name => "Scott Taylor" }
21
+ end
22
+
23
+ get '/scope_instance_variables' do
24
+ @name = "Scott Taylor"
25
+ mab :variables
26
+ end
27
+
28
+ template :layout_index do
29
+ 'div.title "Hello World!"'
30
+ end
31
+
32
+ get "/named_template" do
33
+ mab :layout_index
34
+ end
35
+
36
+ get "/layout" do
37
+ @display_layout = true
38
+ mab :layout_index
39
+ end
40
+
41
+ helpers do
42
+ def chunky
43
+ "bacon"
44
+ end
45
+ end
46
+
47
+ get "/helpers" do
48
+ mab :helpers
49
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+ require File.expand_path(File.dirname(__FILE__) + "/app")
3
+ require 'rack/test'
4
+
5
+ describe "sinatra integration" do
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ @app ||= Sinatra::Application
10
+ end
11
+
12
+ it "should render an empty" do
13
+ get '/empty_action'
14
+ last_response.should be_ok
15
+ end
16
+
17
+ it "should render an empty markaby template" do
18
+ get '/markaby_template'
19
+ last_response.should be_ok
20
+ last_response.body.should == ""
21
+ end
22
+
23
+ it "should render a template with html in it" do
24
+ get '/simple_html'
25
+ last_response.should be_ok
26
+ last_response.body.should == "<ul><li>hi</li><li>there</li></ul>"
27
+ end
28
+
29
+ it "should be able to pass variables" do
30
+ get '/variables'
31
+ last_response.should be_ok
32
+ last_response.body.should == '<p class="name">Scott Taylor</p>'
33
+ end
34
+
35
+ it "should be able to pass variables through locals" do
36
+ get '/variables_with_locals'
37
+ last_response.should be_ok
38
+ last_response.body.should == '<p class="name">Scott Taylor</p>'
39
+ end
40
+
41
+ it "should have scope to instance variables" do
42
+ get '/scope_instance_variables'
43
+ last_response.should be_ok
44
+ last_response.body.should == '<p class="name">Scott Taylor</p>'
45
+ end
46
+
47
+ it "should be able to use named templates" do
48
+ get "/named_template"
49
+ last_response.should be_ok
50
+ last_response.body.should == '<div class="title">Hello World!</div>'
51
+ end
52
+
53
+ it "should be able to use a layout with :layout" do
54
+ get '/layout'
55
+ last_response.should be_ok
56
+ last_response.body.should == '<html><div class="title">Hello World!</div></html>'
57
+ end
58
+
59
+ it "should be able to access helpers in a template" do
60
+ get '/helpers'
61
+ last_response.should be_ok
62
+ last_response.body.should == "<li>bacon</li>"
63
+ end
64
+ end
@@ -0,0 +1 @@
1
+ li chunky
@@ -0,0 +1,7 @@
1
+ if @display_layout
2
+ html do
3
+ yield
4
+ end
5
+ else
6
+ yield
7
+ end
@@ -0,0 +1,3 @@
1
+ p :class => "name" do
2
+ @name
3
+ end
@@ -0,0 +1,4 @@
1
+ ul do
2
+ li "hi"
3
+ li "there"
4
+ end
@@ -0,0 +1,3 @@
1
+ p :class => "name" do
2
+ name
3
+ end
@@ -1,6 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
- require 'markaby/tilt'
3
- require 'erb'
4
2
 
5
3
  module Markaby
6
4
  describe Tilt, "templates" do
@@ -36,15 +34,6 @@ module Markaby
36
34
  tilt.render.should == "<html></html>"
37
35
  end
38
36
 
39
- it "should evaluate a block in the scope given" do
40
- pending do
41
- scope = mock 'scope object', :foo => "bar"
42
-
43
- tilt = ::Tilt::MarkabyTemplate.new { li foo }
44
- tilt.render(scope).should == "<li>bar</li>"
45
- end
46
- end
47
-
48
37
  it "should evaluate a template file in the scope given" do
49
38
  scope = mock 'scope object', :foo => "bar"
50
39
 
@@ -58,14 +47,14 @@ module Markaby
58
47
  end
59
48
 
60
49
  it "should yield to the block given" do
61
- pending do
62
- tilt = ::Tilt::MarkabyTemplate.new("tilt/yielding.mab", &@block)
63
- output = tilt.render(Object.new, {}) do
64
- text("Joe")
65
- end
50
+ tilt = ::Tilt::MarkabyTemplate.new("tilt/yielding.mab", &@block)
51
+ eval_scope = Markaby::Builder.new
66
52
 
67
- output.should == "Hey Joe"
53
+ output = tilt.render(Object.new, {}) do
54
+ text("Joe")
68
55
  end
56
+
57
+ output.should == "Hey Joe"
69
58
  end
70
59
 
71
60
  it "should be able to render two templates in a row" do
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'test/unit'
3
2
  require 'spec'
4
3
  require 'spec/interop/test'
@@ -9,6 +8,9 @@ require 'markaby'
9
8
  require 'markaby/kernel_method'
10
9
  require 'markaby/rails'
11
10
 
11
+ require 'markaby/sinatra'
12
+ require 'erb'
13
+
12
14
  module MarkabyTestHelpers
13
15
  def link_to(obj)
14
16
  %{<a href="">#{obj}</a>}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markaby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 10
10
- version: 0.6.10
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - _why
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-08-13 00:00:00 -04:00
22
+ date: 2010-08-15 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ files:
64
64
  - lib/markaby/rails/current.rb
65
65
  - lib/markaby/rails/deprecated.rb
66
66
  - lib/markaby/rails/rails_builder.rb
67
+ - lib/markaby/sinatra.rb
67
68
  - lib/markaby/tags.rb
68
69
  - lib/markaby/tilt.rb
69
70
  - spec/markaby/builder_spec.rb
@@ -77,6 +78,7 @@ files:
77
78
  - spec/markaby/rails/views/markaby/_partial_child_with_locals.mab
78
79
  - spec/markaby/rails/views/markaby/access_to_helpers.mab
79
80
  - spec/markaby/rails/views/markaby/broken.mab
81
+ - spec/markaby/rails/views/markaby/commented_out_template.mab
80
82
  - spec/markaby/rails/views/markaby/correct_template_values.mab
81
83
  - spec/markaby/rails/views/markaby/double_output.mab
82
84
  - spec/markaby/rails/views/markaby/form_for.mab
@@ -97,6 +99,14 @@ files:
97
99
  - spec/markaby/rails/views/markaby/yielding_with_content_for.mab
98
100
  - spec/markaby/rails_spec.rb
99
101
  - spec/markaby/rails_version_spec.rb
102
+ - spec/markaby/sinatra/app.rb
103
+ - spec/markaby/sinatra/sinatra_spec.rb
104
+ - spec/markaby/sinatra/views/helpers.mab
105
+ - spec/markaby/sinatra/views/layout.mab
106
+ - spec/markaby/sinatra/views/markaby_template.mab
107
+ - spec/markaby/sinatra/views/scope_instance_variables.mab
108
+ - spec/markaby/sinatra/views/simple_html.mab
109
+ - spec/markaby/sinatra/views/variables.mab
100
110
  - spec/markaby/tilt/erb.erb
101
111
  - spec/markaby/tilt/locals.mab
102
112
  - spec/markaby/tilt/markaby.mab
@@ -149,5 +159,7 @@ test_files:
149
159
  - spec/markaby/rails/spec_helper.rb
150
160
  - spec/markaby/rails_spec.rb
151
161
  - spec/markaby/rails_version_spec.rb
162
+ - spec/markaby/sinatra/app.rb
163
+ - spec/markaby/sinatra/sinatra_spec.rb
152
164
  - spec/markaby/tilt_spec.rb
153
165
  - spec/spec_helper.rb