Skip to content

Commit

Permalink
Introduce support for Ruby 2.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Feb 13, 2015
1 parent 0f43c2e commit c5cee43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ sudo: false
cache: bundler
script: 'bundle exec rake test:coverage --trace'
rvm:
- 2.0
- 2.1
- 2.2
- jruby-head
- rbx-2

matrix:
allow_failures:
- rvm: jruby-head
- rvm: rbx-2
14 changes: 11 additions & 3 deletions lib/lotus/helpers/html_helper/html_builder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'lotus/utils' # RUBY_VERSION >= '2.2'
require 'lotus/utils/escape'
require 'lotus/helpers/html_helper/empty_html_node'
require 'lotus/helpers/html_helper/html_node'
Expand Down Expand Up @@ -269,9 +270,16 @@ def nested?
#
# @since x.x.x
# @api private
def resolve(&blk)
@context = blk.binding.receiver
instance_exec(&blk)
if RUBY_VERSION >= '2.2' && !Utils.jruby?
def resolve(&blk)
@context = blk.binding.receiver
instance_exec(&blk)
end
else
def resolve(&blk)
@context = eval 'self', blk.binding
instance_exec(&blk)
end
end

# Forward missing methods to the current context.
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ def div_with_attr
html.div(id: 'container')
end

# RUBY_VERSION >= '2.2'
# def div_with_data_attr
# html.div('data-where': 'up')
# end
def div_with_data_attr
html.div('data-where': 'up')
html.div(:'data-where' => 'up')
end

def div_with_attrs
Expand Down
8 changes: 6 additions & 2 deletions test/html_helper/html_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@

describe '<meta>' do
it 'generates HTML4 content type' do
result = @builder.meta('http-equiv': 'Content-Type', content: 'text/html; charset=utf-8').to_s
# RUBY_VERSION >= 2.2
# result = @builder.meta('http-equiv': 'Content-Type', content: 'text/html; charset=utf-8').to_s
result = @builder.meta(:'http-equiv' => 'Content-Type', content: 'text/html; charset=utf-8').to_s
result.must_equal %(<meta http-equiv="Content-Type" content="text/html; charset=utf-8">)
end

Expand All @@ -136,7 +138,9 @@
end

it 'generates a page refresh' do
result = @builder.meta('http-equiv': 'refresh', content: '23;url=http://lotusrb.org').to_s
# RUBY_VERSION >= 2.2
# result = @builder.meta('http-equiv': 'refresh', content: '23;url=http://lotusrb.org').to_s
result = @builder.meta(:'http-equiv' => 'refresh', content: '23;url=http://lotusrb.org').to_s
result.must_equal %(<meta http-equiv="refresh" content="23;url=http://lotusrb.org">)
end
end
Expand Down

0 comments on commit c5cee43

Please sign in to comment.