hexp 0.0.1.pre2 → 0.0.1.pre3

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/Rakefile CHANGED
@@ -9,5 +9,7 @@ gem.define
9
9
 
10
10
  desc "Push gem to rubygems.org"
11
11
  task :push => :gem do
12
+ sh "git tag v#{Hexp::VERSION}"
13
+ sh "git push --tags"
12
14
  sh "gem push pkg/hexp-#{Hexp::VERSION}.gem"
13
15
  end
data/examples/filter.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # The filter method is currently removed again, it needs to be redone using
2
+ # depth-first rather than breadth first, and will probably be renamed to
3
+ # rewrite.
4
+
1
5
  $:.unshift('/home/arne/github/hexp/lib')
2
6
  require 'hexp/h'
3
7
 
@@ -0,0 +1,78 @@
1
+ require 'hexp/h'
2
+
3
+ # Here's an example of using bare-bones Hexp together with Rails. A lot of this
4
+ # boilerplate would have to be wrapped/hidden, but it's a start.
5
+ #
6
+ # An interesting thing to note is that by overriding content_tag we can make other
7
+ # view helpers like link_to return Hexp objects rather than strings.
8
+
9
+ class UsersController < ApplicationController
10
+ def index
11
+ render :inline => UserIndexPage.new(User.all).to_html
12
+ end
13
+ end
14
+
15
+ class UserIndexPage # < Hexp::Rails::Widget perhaps?
16
+ include ActionView::Helpers::UrlHelper
17
+ include ActionDispatch::Routing::UrlFor
18
+ include Rails.application.routes.url_helpers
19
+
20
+ delegate :to_html, to: :to_hexp
21
+ attr_reader :users
22
+
23
+ def initialize(users)
24
+ @users = users
25
+ end
26
+
27
+ def to_hexp
28
+ H[:div, [
29
+ [:h1, "Listing users"],
30
+ [:table, [
31
+ [:thead, [
32
+ [:tr, headings.map{|h| [:th, h]}]
33
+ ]
34
+ ],
35
+ [:tbody, users.map do |user|
36
+ H[:tr,
37
+ fields_for(user).map do |field|
38
+ [:td, [field]]
39
+ end
40
+ ]
41
+ end
42
+ ]
43
+ ]
44
+ ]
45
+ ]
46
+ ]
47
+ end
48
+
49
+ def headings
50
+ ['Name', 'Email', nil, nil, nil]
51
+ end
52
+
53
+ def fields_for(user)
54
+ [ user.name,
55
+ user.email,
56
+ link_to('Show', user),
57
+ link_to('Edit', edit_user_path(user)),
58
+ link_to('Destroy', user, method: :delete, data: { confirm: 'Are you sure?' })
59
+ ]
60
+ end
61
+
62
+ def content_tag(tag, content, attrs)
63
+ H[tag, attrs, content]
64
+ end
65
+
66
+ # NullController to satisfy UrlHelper
67
+ def controller
68
+ Class.new do
69
+ def respond_to?(*args)
70
+ false
71
+ end
72
+
73
+ def method_missing(*args)
74
+ return self
75
+ end
76
+ end.new
77
+ end
78
+ end
data/hexp.gemspec CHANGED
@@ -16,5 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = `git ls-files -- spec`.split($/)
17
17
  gem.extra_rdoc_files = %w[README.md]
18
18
 
19
+ gem.add_dependency 'nokogiri', '~> 1.5.9'
19
20
  gem.add_dependency 'ice_nine', '~> 0.7.0'
21
+ gem.add_dependency 'equalizer', '~> 0.0.5'
20
22
  end
data/lib/hexp.rb CHANGED
@@ -23,3 +23,5 @@ require 'hexp/list'
23
23
  require 'hexp/dom'
24
24
 
25
25
  require 'hexp/nokogiri/equality'
26
+
27
+ require 'hexp/h'
data/lib/hexp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hexp
2
- VERSION = '0.0.1.pre2'
2
+ VERSION = '0.0.1.pre3'
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Constructing literal hexps' do
4
+ it do
5
+ H[:p].should == Hexp::Node.new(:p, {}, [])
6
+ end
7
+
8
+ it do
9
+ H[:p, "foo"].should == Hexp::Node.new(:p, {}, ["foo"])
10
+ end
11
+
12
+ end
@@ -4,14 +4,14 @@ describe Hexp::Node, 'pp' do
4
4
  subject { object.pp }
5
5
 
6
6
  context 'with no attributes or children' do
7
- let(:object) { Hexp::Node[:p, {}] }
8
- it { should == 'Hexp::Node[:p]'}
7
+ let(:object) { H[:p, {}] }
8
+ it { should == 'H[:p]'}
9
9
  end
10
10
 
11
11
  context 'with a single child' do
12
- let(:object) { Hexp::Node[:p, [ [:abbr, {title: 'YAGNI'}, "You ain't gonna need it"] ]] }
13
- it { should == %q^Hexp::Node[:p, [
14
- Hexp::Node[:abbr, {"title"=>"YAGNI"}, [
12
+ let(:object) { H[:p, [ [:abbr, {title: 'YAGNI'}, "You ain't gonna need it"] ]] }
13
+ it { should == %q^H[:p, [
14
+ H[:abbr, {"title"=>"YAGNI"}, [
15
15
  "You ain't gonna need it"]]]]^.gsub(' '*22, '')
16
16
  }
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre2
4
+ version: 0.0.1.pre3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-01 00:00:00.000000000 Z
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.5.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.5.9
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: ice_nine
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -27,6 +43,22 @@ dependencies:
27
43
  - - ~>
28
44
  - !ruby/object:Gem::Version
29
45
  version: 0.7.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: equalizer
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.5
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.5
30
62
  description: HTML expressions
31
63
  email:
32
64
  - arne@arnebrasseur.net
@@ -50,6 +82,7 @@ files:
50
82
  - config/reek.yml
51
83
  - config/yardstick.yml
52
84
  - examples/filter.rb
85
+ - examples/hexp_rails.rb
53
86
  - hexp.gemspec
54
87
  - lib/hexp.rb
55
88
  - lib/hexp/dom.rb
@@ -62,6 +95,7 @@ files:
62
95
  - lib/hexp/nokogiri/equality.rb
63
96
  - lib/hexp/text_node.rb
64
97
  - lib/hexp/version.rb
98
+ - spec/integration/literal_syntax_spec.rb
65
99
  - spec/shared_helper.rb
66
100
  - spec/spec_helper.rb
67
101
  - spec/unit/hexp/node/domize_spec.rb
@@ -86,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
120
  version: '0'
87
121
  segments:
88
122
  - 0
89
- hash: 4219632061257453794
123
+ hash: -105489159819991926
90
124
  required_rubygems_version: !ruby/object:Gem::Requirement
91
125
  none: false
92
126
  requirements:
@@ -100,6 +134,7 @@ signing_key:
100
134
  specification_version: 3
101
135
  summary: HTML expressions
102
136
  test_files:
137
+ - spec/integration/literal_syntax_spec.rb
103
138
  - spec/shared_helper.rb
104
139
  - spec/spec_helper.rb
105
140
  - spec/unit/hexp/node/domize_spec.rb