markababy 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ Markaby's little sister
2
+ =======================
3
+
4
+
5
+ Installation
6
+ ------------
7
+
8
+ $ gem install markababy
9
+
10
+
11
+ Example
12
+ -------
13
+
14
+ Usage is similar to [Markaby](http://en.wikipedia.org/wiki/Markaby),
15
+ and easy to use directly from a Ruby script:
16
+
17
+ ```ruby
18
+ require 'markababy'
19
+
20
+ Markababy.markup do
21
+ html do
22
+ head { title 'Boats.com' }
23
+ body do
24
+ h1 'Boats.com has great deals'
25
+ ul do
26
+ li '$49 for a canoe'
27
+ li '$39 for a raft'
28
+ li '$29 for a huge boot that floats and can fit 5 people'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ ```
34
+
35
+ Use `Markababy.capture` if you want to capture the output as a string
36
+ instead of printing it to `$stdout`.
37
+
38
+
39
+ Rails template usage
40
+ --------------------
41
+
42
+ To use Markababy within a Rails 3 app: add markababy as a dependency to your
43
+ Gemfile; do the bundle dance; then change the extension on your template files
44
+ from .erb to .rb and you can start writing your templates in Ruby! Controller
45
+ instance variables and helpers will be available as methods.
46
+
47
+
48
+ Less is more
49
+ ------------
50
+
51
+ Some differences from Markaby:
52
+
53
+ * No auto-stringification
54
+ * No element classes or IDs
55
+ * No validation
56
+ * No XHTML
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'rake/testtask'
2
2
 
3
- Rake::TestTask.new do |t|
3
+ task :default => :spec
4
+
5
+ Rake::TestTask.new(:spec) do |t|
4
6
  t.test_files = FileList['spec/*_spec.rb']
7
+ t.warning = true
5
8
  end
data/lib/markababy.rb CHANGED
@@ -3,7 +3,7 @@ require 'cgi'
3
3
 
4
4
  module Markababy
5
5
  def self.capture(options = {}, &block)
6
- [].tap { |output| markup(options.merge(output: output), &block) }.join
6
+ [].tap { |output| markup(options.merge(:output => output), &block) }.join
7
7
  end
8
8
 
9
9
  def self.markup(options = {}, &block)
@@ -1,3 +1,11 @@
1
+ unless defined?(BasicObject)
2
+ require 'backports/basic_object'
3
+
4
+ class BasicObject
5
+ undef_method :p
6
+ end
7
+ end
8
+
1
9
  module Markababy
2
10
  class Builder < BasicObject
3
11
  def initialize(options, &block)
@@ -12,8 +20,18 @@ module Markababy
12
20
  instance_eval(&block)
13
21
  end
14
22
 
23
+ if ::Object.new.respond_to?(:respond_to_missing?)
24
+ def context_responds_to?(name)
25
+ @context.respond_to?(name)
26
+ end
27
+ else
28
+ def context_responds_to?(name)
29
+ @context.respond_to?(name) || (@context.respond_to?(:respond_to_missing?) && @context.respond_to_missing?(name))
30
+ end
31
+ end
32
+
15
33
  def method_missing(sym, *args, &block)
16
- if !@context.nil? && @context.respond_to?(sym)
34
+ if @context && context_responds_to?(sym)
17
35
  return @context.send(sym, *args, &block)
18
36
  end
19
37
 
@@ -3,7 +3,7 @@ module Markababy
3
3
  def initialize(controller)
4
4
  @controller = controller
5
5
 
6
- @ivars = @controller.instance_variables - @controller.class.new.instance_variables
6
+ @ivars = (@controller.instance_variables - @controller.class.new.instance_variables).map(&:to_sym)
7
7
  end
8
8
 
9
9
  def respond_to_missing?(sym, include_private = false)
@@ -2,7 +2,7 @@ module Markababy
2
2
  module RailsTemplateHandler
3
3
  def self.call(template)
4
4
  "self.output_buffer = ''\n" +
5
- "Markababy.capture(output: self.output_buffer, context: Markababy::RailsTemplateContext.new(self)) do\n" +
5
+ "Markababy.capture(:output => self.output_buffer, :context => Markababy::RailsTemplateContext.new(self)) do\n" +
6
6
  "#{template.source}\n" +
7
7
  "end\n"
8
8
  end
data/markababy.gemspec CHANGED
@@ -1,13 +1,21 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'markababy'
3
- s.version = '1.2.0'
3
+ s.version = '1.3.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
7
7
  s.homepage = 'http://github.com/timcraft/markababy'
8
8
  s.description = 'Markaby\'s little sister'
9
9
  s.summary = 'See description'
10
- s.files = Dir.glob('{lib,spec}/**/*') + %w(README.txt Rakefile markababy.gemspec)
10
+ s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md Rakefile markababy.gemspec)
11
11
  s.add_development_dependency('rails', ['>= 3.0.3'])
12
12
  s.require_path = 'lib'
13
+
14
+ unless defined?(BasicObject)
15
+ s.add_dependency('backports', '~> 2.8.2')
16
+ end
17
+
18
+ if RUBY_VERSION == '1.8.7'
19
+ s.add_development_dependency('minitest', '>= 4.2.0')
20
+ end
13
21
  end
@@ -20,14 +20,14 @@ class DummyController < AbstractController::Base
20
20
  def index
21
21
  @message = 'Controller says hello!'
22
22
 
23
- render template: 'index'
23
+ render :template => 'index'
24
24
  end
25
25
  end
26
26
 
27
- describe DummyController do
28
- it 'should return the correct markup' do
27
+ describe 'Rendering the DummyController index template' do
28
+ it 'returns the correct markup' do
29
29
  output = '<html><head><title>Controller says hello!</title></head><body><p>12,345,678</p></body></html>'
30
30
 
31
- DummyController.new.index.must_equal output
31
+ DummyController.new.index.must_equal(output)
32
32
  end
33
33
  end
@@ -8,56 +8,60 @@ class ExampleContext
8
8
  end
9
9
  end
10
10
 
11
- describe Markababy do
12
- it 'should render tags without attributes or content correctly' do
11
+ describe 'Markababy' do
12
+ it 'renders tags without attributes or content' do
13
13
  Markababy.capture { br }.must_equal '<br>'
14
14
  end
15
15
 
16
- it 'should render tags with content correctly' do
16
+ it 'renders tags with content' do
17
17
  Markababy.capture { title 'Untitled' }.must_equal '<title>Untitled</title>'
18
18
  end
19
19
 
20
- it 'should escape content correctly' do
20
+ it 'escapes content' do
21
21
  Markababy.capture { h1 'Apples & Oranges' }.must_equal '<h1>Apples &amp; Oranges</h1>'
22
22
  end
23
23
 
24
- it 'should render tags with an attribute hash correctly' do
25
- Markababy.capture { input type: :text, size: 40 }.must_equal '<input type="text" size="40">'
24
+ it 'renders tags with an attribute hash' do
25
+ output = Markababy.capture { input :type => :text, :size => 40 }
26
+
27
+ output.must_match(/<input .+>/)
28
+ output.must_match(/ type="text"/)
29
+ output.must_match(/ size="40"/)
26
30
  end
27
31
 
28
- it 'should render tags with an attribute array correctly' do
29
- Markababy.capture { input [{type: :text}, :disabled] }.must_equal '<input type="text" disabled>'
32
+ it 'renders tags with an attribute array' do
33
+ Markababy.capture { input [{:type => :text}, :disabled] }.must_equal '<input type="text" disabled>'
30
34
  end
31
35
 
32
- it 'should render tags with attributes and content correctly' do
33
- Markababy.capture { div 'O hai', class: 'name' }.must_equal '<div class="name">O hai</div>'
36
+ it 'renders tags with attributes and content' do
37
+ Markababy.capture { div 'O hai', :class => 'name' }.must_equal '<div class="name">O hai</div>'
34
38
  end
35
39
 
36
- it 'should render nested tags correctly' do
40
+ it 'renders nested tags' do
37
41
  Markababy.capture { h1 { span 'Chunky bacon!' } }.must_equal '<h1><span>Chunky bacon!</span></h1>'
38
42
  end
39
43
 
40
- it 'should allow output target to be specified' do
44
+ it 'provides an option for specifying the output target' do
41
45
  output = []
42
46
 
43
- Markababy.markup(output: output) { hr }
47
+ Markababy.markup(:output => output) { hr }
44
48
 
45
49
  output.join.must_equal '<hr>'
46
50
  end
47
51
 
48
- it 'should allow context for method lookup to be specified' do
49
- output = Markababy.capture(context: ExampleContext.new) { h1 baconize('Super chunky') }
52
+ it 'provides an option for specifying the method lookup context' do
53
+ output = Markababy.capture(:context => ExampleContext.new) { h1 baconize('Super chunky') }
50
54
 
51
55
  output.must_equal '<h1>Super chunky bacon!</h1>'
52
56
  end
53
57
 
54
- it 'should provide a method for rendering text content' do
58
+ it 'provides an method for rendering text content inside a tag' do
55
59
  output = Markababy.capture { h1 { text 'Hello '; strong 'World' } }
56
60
 
57
61
  output.must_equal '<h1>Hello <strong>World</strong></h1>'
58
62
  end
59
63
 
60
- it 'should respect the html_safe? method' do
64
+ it 'does not escape content that has been marked as html safe' do
61
65
  Markababy.capture { text 'Hello&nbsp;World'.html_safe }.must_equal 'Hello&nbsp;World'
62
66
 
63
67
  output = Markababy.capture { h1 'Hello <strong>World</strong>'.html_safe }
@@ -65,13 +69,13 @@ describe Markababy do
65
69
  output.must_equal '<h1>Hello <strong>World</strong></h1>'
66
70
  end
67
71
 
68
- it 'should provide an option for including a doctype declaration' do
69
- output = Markababy.capture(doctype: true) { html { body { p 'INSERT CONTENT HERE' } } }
72
+ it 'provides an option for including a doctype declaration' do
73
+ output = Markababy.capture(:doctype => true) { html { body { p 'INSERT CONTENT HERE' } } }
70
74
 
71
75
  output.must_equal "<!DOCTYPE html>\n<html><body><p>INSERT CONTENT HERE</p></body></html>"
72
76
  end
73
77
 
74
- it 'should provide access to constants' do
78
+ it 'provides access to constants' do
75
79
  Something = Class.new
76
80
 
77
81
  Markababy.capture { h1 Something }.must_equal('<h1>Something</h1>')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markababy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-02 00:00:00.000000000Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &10049430 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: 3.0.3
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *10049430
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.3
25
30
  description: Markaby's little sister
26
31
  email:
27
32
  - mail@timcraft.com
@@ -37,7 +42,7 @@ files:
37
42
  - spec/markababy_rails_spec.rb
38
43
  - spec/markababy_spec.rb
39
44
  - spec/views/index.html.rb
40
- - README.txt
45
+ - README.md
41
46
  - Rakefile
42
47
  - markababy.gemspec
43
48
  homepage: http://github.com/timcraft/markababy
@@ -60,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
65
  version: '0'
61
66
  requirements: []
62
67
  rubyforge_project:
63
- rubygems_version: 1.8.10
68
+ rubygems_version: 1.8.24
64
69
  signing_key:
65
70
  specification_version: 3
66
71
  summary: See description
data/README.txt DELETED
@@ -1,37 +0,0 @@
1
- Markaby's little sister.
2
-
3
- Usage is similar to Markaby, and easy to use directly from a Ruby script:
4
-
5
- require 'markababy'
6
-
7
- Markababy.markup do
8
- html do
9
- head { title 'Boats.com' }
10
- body do
11
- h1 'Boats.com has great deals'
12
- ul do
13
- li '$49 for a canoe'
14
- li '$39 for a raft'
15
- li '$29 for a huge boot that floats and can fit 5 people'
16
- end
17
- end
18
- end
19
- end
20
-
21
- Use Markababy.capture if you want to capture the output as a string instead
22
- of printing it to $stdout.
23
-
24
- To use Markababy within a Rails 3 app, first add it to your Gemfile:
25
-
26
- gem 'markababy'
27
-
28
- Then change the extension on your template files from .erb to .rb, and you
29
- can start writing your templates in Ruby! Controller instance variables and
30
- helpers will be available as methods.
31
-
32
- Some differences from Markaby:
33
-
34
- * No auto-stringification
35
- * No element classes or IDs
36
- * No validation
37
- * No XHTML