kuntoaji-harmony 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/Manifest +13 -0
- data/README.md +162 -0
- data/Rakefile +41 -0
- data/docs.watchr +25 -0
- data/harmony.gemspec +25 -0
- data/lib/harmony.rb +4 -0
- data/lib/harmony/page.rb +125 -0
- data/lib/harmony/version.rb +3 -0
- data/specs.watchr +36 -0
- data/test/harmony_test.rb +8 -0
- data/test/page_test.rb +101 -0
- data/test/test_helper.rb +13 -0
- metadata +133 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright © 2009 Martin Aumont (mynyml)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/Manifest
ADDED
data/README.md
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
Harmony
|
2
|
+
=======
|
3
|
+
|
4
|
+
.,ad88888888baa,
|
5
|
+
,d8P""" ""9888ba.
|
6
|
+
.a8" ,ad88888888888a
|
7
|
+
aP' ,88888888888888888a
|
8
|
+
,8" ,88888888888888888888,
|
9
|
+
,8' (888888888( )888888888,
|
10
|
+
,8' `8888888888888888888888
|
11
|
+
8) `888888888888888888888,
|
12
|
+
8 "8888888888888888888)
|
13
|
+
8 `888888888888888888)
|
14
|
+
8) "8888888888888888
|
15
|
+
(b "88888888888888'
|
16
|
+
`8, (8) 8888888888888)
|
17
|
+
"8a ,888888888888)
|
18
|
+
V8, d88888888888"
|
19
|
+
`8b, ,d8888888888P'
|
20
|
+
`V8a, ,ad8888888888P'
|
21
|
+
""88888888888888888P"
|
22
|
+
""""""""""""
|
23
|
+
|
24
|
+
Summary
|
25
|
+
-------
|
26
|
+
|
27
|
+
Harmony provides a simple DSL to execute javascript + DOM code within ruby.
|
28
|
+
|
29
|
+
Examples
|
30
|
+
--------
|
31
|
+
|
32
|
+
### Simple Javascript Parsing
|
33
|
+
|
34
|
+
require 'harmony'
|
35
|
+
|
36
|
+
page = Harmony::Page.new(<<-HTML)
|
37
|
+
<html>
|
38
|
+
<head>
|
39
|
+
<title>Foo</title>
|
40
|
+
</head>
|
41
|
+
<body></body>
|
42
|
+
</html>
|
43
|
+
HTML
|
44
|
+
|
45
|
+
page.execute_js("1+1") #=> 2
|
46
|
+
page.execute_js("document.title") #=> "Foo"
|
47
|
+
|
48
|
+
The Page object's `#execute_js` method (aliased as `#x` for convenience) takes a
|
49
|
+
string of javascript code, executes it and returns the last statement's value
|
50
|
+
(just like a ruby method).
|
51
|
+
|
52
|
+
### Javascript Unit Tests
|
53
|
+
|
54
|
+
One interesting use of Harmony is to test your javascript code within your ruby
|
55
|
+
application's own tests (test/unit, minitest, RSpec, nanotest, etc). Which
|
56
|
+
consequently means that you can now run browser-less, fully command-line
|
57
|
+
based, DOM-javascript tests.
|
58
|
+
|
59
|
+
require 'test/unit'
|
60
|
+
require 'harmony'
|
61
|
+
|
62
|
+
class JavascriptTest < Test::Unit::TestCase
|
63
|
+
def setup
|
64
|
+
@page = Harmony::Page.new
|
65
|
+
@page.load('public/javascripts/foo.js')
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_foo
|
69
|
+
assert_equal "world", @page.execute_js(<<-JS)
|
70
|
+
foo = new Foo;
|
71
|
+
foo.hello();
|
72
|
+
JS
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
### DOM Handling
|
77
|
+
|
78
|
+
Don't be affraid to throw in your favorite client-side js framework, like
|
79
|
+
JQuery or Prototype. And notice that scripts linked to in `<script>` tags will
|
80
|
+
automatically get pulled in.
|
81
|
+
|
82
|
+
require 'harmony'
|
83
|
+
|
84
|
+
page = Harmony::Page.new(<<-HTML)
|
85
|
+
<html>
|
86
|
+
<head>
|
87
|
+
<script src="javascripts/jquery.js" type="text/javascript"></script>
|
88
|
+
</head>
|
89
|
+
<body>
|
90
|
+
<div id="widget">ohaie</div>
|
91
|
+
</body>
|
92
|
+
</html>
|
93
|
+
HTML
|
94
|
+
|
95
|
+
page.execute_js("$('#widget').innerHTML") #=> "ohaie"
|
96
|
+
|
97
|
+
### Fetching Documents
|
98
|
+
|
99
|
+
Use `Harmony::Page.fetch(uri)` to create a page from a remote document.
|
100
|
+
|
101
|
+
require 'harmony'
|
102
|
+
|
103
|
+
page = Harmony::Page.fetch('http://example.com')
|
104
|
+
page.execute_js('document.title') #=> "Example Web Page"
|
105
|
+
|
106
|
+
`fetch` also accepts "file://" uris.
|
107
|
+
|
108
|
+
Install
|
109
|
+
-------
|
110
|
+
|
111
|
+
# There's a gem dependency bug in rubygems currently, so we'll have to
|
112
|
+
# install some dependencies manually. This will be fixed soon.
|
113
|
+
gem install stackdeck
|
114
|
+
gem install johnson -v "2.0.0.pre3"
|
115
|
+
|
116
|
+
gem install harmony
|
117
|
+
|
118
|
+
See Also
|
119
|
+
--------
|
120
|
+
|
121
|
+
* [holygrail][20]: Harmony plugin for Rails tests
|
122
|
+
|
123
|
+
Acknowledgement
|
124
|
+
---------------
|
125
|
+
|
126
|
+
Harmony is a thin DSL wrapper around three **amazing** libs, [Johnson][1],
|
127
|
+
[env.js][30] and [Envjs][2] . The authors of those libs have been doing a huge
|
128
|
+
amount of great work for quite a while, so please go recommend them on
|
129
|
+
WorkingWithRails right now and/or follow them on github:
|
130
|
+
|
131
|
+
[jbarnette][3], [tenderlove][4], [smparkes][5], [wycats][6], [matthewd][7], [thatcher][8], [jeresig][9]
|
132
|
+
|
133
|
+
Special thanks go to [smparkes][10] for his patient help, and for providing the
|
134
|
+
last puzzle pieces that made [everything][12] [work][11] [together][13].
|
135
|
+
|
136
|
+
Links
|
137
|
+
-----
|
138
|
+
* code: <http://github.com/mynyml/harmony>
|
139
|
+
* docs: <http://yardoc.org/docs/mynyml-harmony>
|
140
|
+
* wiki: <http://wiki.github.com/mynyml/harmony>
|
141
|
+
* bugs: <http://github.com/mynyml/harmony/issues>
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
YinYang ASCII art is © Normand Veilleux (nveilleuATemr1.emrDOTca)
|
146
|
+
|
147
|
+
|
148
|
+
[1]: http://github.com/jbarnette/johnson/
|
149
|
+
[2]: http://env-js.appspot.com/
|
150
|
+
[3]: http://www.workingwithrails.com/person/10668-john-barnette
|
151
|
+
[4]: http://github.com/tenderlove/
|
152
|
+
[5]: http://www.workingwithrails.com/person/11739-steven-parkes
|
153
|
+
[6]: http://www.workingwithrails.com/person/1805-yehuda-katz
|
154
|
+
[7]: http://www.workingwithrails.com/person/6221-matthew-draper
|
155
|
+
[8]: http://github.com/thatcher/
|
156
|
+
[9]: http://ejohn.org/
|
157
|
+
[10]: http://github.com/smparkes/
|
158
|
+
[11]: http://github.com/smparkes/env-js/commit/49abe259813a505b0761e6d31dde671344b5bc87#L0R279
|
159
|
+
[12]: http://groups.google.com/group/envjs/msg/4ac719f7db7912f5
|
160
|
+
[13]: http://gemcutter.org/gems/envjs
|
161
|
+
[20]: http://github.com/mynyml/holygrail
|
162
|
+
[30]: http://github.com/thatcher/env-js
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
def gem_opt
|
5
|
+
defined?(Gem) ? "-rubygems" : ""
|
6
|
+
end
|
7
|
+
|
8
|
+
# --------------------------------------------------
|
9
|
+
# Tests
|
10
|
+
# --------------------------------------------------
|
11
|
+
task(:default => "test:all")
|
12
|
+
|
13
|
+
namespace(:test) do
|
14
|
+
|
15
|
+
desc "Run all tests"
|
16
|
+
task(:all) do
|
17
|
+
exit system("ruby #{gem_opt} -I.:lib:test -e'%w( #{Dir['test/**/*_test.rb'].join(' ')} ).each {|p| require p }'")
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run all tests on multiple ruby versions (requires rvm)"
|
21
|
+
task(:portability) do
|
22
|
+
versions = %w( 1.8.6 1.8.7 )
|
23
|
+
versions.each do |version|
|
24
|
+
system <<-BASH
|
25
|
+
bash -c 'source ~/.rvm/scripts/rvm;
|
26
|
+
rvm use #{version};
|
27
|
+
echo "--------- #{version} ----------";
|
28
|
+
rake -s test:all'
|
29
|
+
BASH
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# --------------------------------------------------
|
35
|
+
# Docs
|
36
|
+
# --------------------------------------------------
|
37
|
+
desc "Generate YARD Documentation"
|
38
|
+
task :yardoc do
|
39
|
+
require 'yard'
|
40
|
+
YARD::CLI::Yardoc.run *%w( --no-private --no-highlight -o doc/yard --readme README.md --markup markdown - LICENSE )
|
41
|
+
end
|
data/docs.watchr
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Run me with:
|
2
|
+
# $ watchr docs.watchr
|
3
|
+
|
4
|
+
require 'yard'
|
5
|
+
# --------------------------------------------------
|
6
|
+
# Rules
|
7
|
+
# --------------------------------------------------
|
8
|
+
watch( 'lib/.*\.rb' ) { yard }
|
9
|
+
watch( 'README.md' ) { yard }
|
10
|
+
|
11
|
+
# --------------------------------------------------
|
12
|
+
# Signal Handling
|
13
|
+
# --------------------------------------------------
|
14
|
+
Signal.trap('QUIT') { yard } # Ctrl-\
|
15
|
+
Signal.trap('INT' ) { abort("\n") } # Ctrl-C
|
16
|
+
|
17
|
+
# --------------------------------------------------
|
18
|
+
# Helpers
|
19
|
+
# --------------------------------------------------
|
20
|
+
def yard
|
21
|
+
print "Updating yardocs... "; STDOUT.flush
|
22
|
+
YARD::CLI::Yardoc.run *%w( --no-private --no-highlight -o doc/yard --readme README.md --markup markdown - LICENSE )
|
23
|
+
print "done\n"
|
24
|
+
end
|
25
|
+
|
data/harmony.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "harmony/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "kuntoaji-harmony"
|
7
|
+
s.version = Harmony::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["mynyml", "Kunto Aji Kristianto"]
|
10
|
+
s.email = ["mynyml@gmail.com", "kunto.aji.kr@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/kuntoaji/harmony"
|
12
|
+
s.summary = %q{Javascript + DOM in your ruby, the simple way}
|
13
|
+
s.description = %q{Javascript + DOM in your ruby, the simple way. Kuntoaji's version.}
|
14
|
+
|
15
|
+
#s.rubyforge_project = ""
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'johnson', '2.0.0.pre3'
|
23
|
+
s.add_dependency 'envjs', '0.3.7'
|
24
|
+
s.add_development_dependency 'minitest'
|
25
|
+
end
|
data/lib/harmony.rb
ADDED
data/lib/harmony/page.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
require 'johnson/tracemonkey'
|
5
|
+
require 'envjs/runtime'
|
6
|
+
|
7
|
+
module Harmony
|
8
|
+
class Page
|
9
|
+
|
10
|
+
# Window factory
|
11
|
+
#
|
12
|
+
# @private
|
13
|
+
module Window #:nodoc:
|
14
|
+
extend self
|
15
|
+
|
16
|
+
# Cache the initial runtime. Parsing env.js (done automatically when
|
17
|
+
# Envjs::Runtime is extended) takes a while, so we only want to do this
|
18
|
+
# once.
|
19
|
+
#
|
20
|
+
# @private
|
21
|
+
BASE_RUNTIME = Johnson::Runtime.new
|
22
|
+
BASE_RUNTIME.extend(Envjs::Runtime)
|
23
|
+
|
24
|
+
def from_uri(uri)
|
25
|
+
BASE_RUNTIME.evaluate("window.open('#{uri}')")
|
26
|
+
end
|
27
|
+
|
28
|
+
def from_document(document)
|
29
|
+
Tempfile.open('harmony') {|f| f << document; @path = f.path }
|
30
|
+
from_uri("file://#{@path}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def blank
|
34
|
+
from_uri('about:blank')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create page from remote document.
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
#
|
42
|
+
# Page.fetch('http://montrealrb.org')
|
43
|
+
# Page.fetch('http://localhost:3000')
|
44
|
+
# Page.fetch('file:///home/mynyml/www/foo/index.html')
|
45
|
+
#
|
46
|
+
# @param [String] uri
|
47
|
+
# uri to fetch document from
|
48
|
+
#
|
49
|
+
# @return [Page]
|
50
|
+
# new page object preloaded with fetched document
|
51
|
+
#
|
52
|
+
def self.fetch(uri)
|
53
|
+
page = new
|
54
|
+
page.instance_variable_set(:@window, Window.from_uri(uri))
|
55
|
+
page
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create new page containing given document.
|
59
|
+
#
|
60
|
+
# @param [String] document
|
61
|
+
# HTML document. Defaults to an "about:blank" window, with the basic
|
62
|
+
# structure: `<html><head><title></title></head><body></body></html>`
|
63
|
+
#
|
64
|
+
def initialize(document=nil)
|
65
|
+
@window = Window.from_document(document) if document
|
66
|
+
end
|
67
|
+
|
68
|
+
# Load one or more javascript files in page's context
|
69
|
+
#
|
70
|
+
# @param [#to_s, #to_s, ...] paths
|
71
|
+
# paths to js file
|
72
|
+
# @return [Page] self
|
73
|
+
#
|
74
|
+
def load(*paths)
|
75
|
+
paths.flatten.each do |path|
|
76
|
+
path.to_s.map {|f|
|
77
|
+
window.evaluate(File.read(f).gsub(/\A#!.*$/, ''), f, 1)
|
78
|
+
}.last
|
79
|
+
end
|
80
|
+
self
|
81
|
+
end
|
82
|
+
|
83
|
+
# Evaluate Javascript code within this page's context.
|
84
|
+
#
|
85
|
+
# @param [String] code
|
86
|
+
# javascript code to execute
|
87
|
+
#
|
88
|
+
# @return [Object]
|
89
|
+
# last javascript statement's value, cast to a ruby object
|
90
|
+
#
|
91
|
+
def execute_js(code)
|
92
|
+
window.evaluate(code)
|
93
|
+
end
|
94
|
+
alias :x :execute_js
|
95
|
+
|
96
|
+
# DOM document's `window` object. Equivalent to the return value of
|
97
|
+
# `page.execute_js('window')`
|
98
|
+
#
|
99
|
+
# @return [Object]
|
100
|
+
# window DOM object
|
101
|
+
#
|
102
|
+
def window
|
103
|
+
@window ||= Window.blank
|
104
|
+
end
|
105
|
+
|
106
|
+
# Convenience method, equivalent to the return value of
|
107
|
+
# `page.execute_js('window.document')`
|
108
|
+
#
|
109
|
+
# @return [Object]
|
110
|
+
# document DOM object
|
111
|
+
#
|
112
|
+
def document
|
113
|
+
window.document
|
114
|
+
end
|
115
|
+
|
116
|
+
# Page as html document
|
117
|
+
#
|
118
|
+
# @return [String] html
|
119
|
+
#
|
120
|
+
def to_html
|
121
|
+
document.innerHTML
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
data/specs.watchr
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Run me with:
|
2
|
+
# $ watchr specs.watchr
|
3
|
+
|
4
|
+
# --------------------------------------------------
|
5
|
+
# Rules
|
6
|
+
# --------------------------------------------------
|
7
|
+
watch( '^test.*/.*_test\.rb' ) {|m| ruby m[0] }
|
8
|
+
watch( '^lib/(.*)\.rb' ) {|m| ruby "test/#{m[1]}_test.rb" }
|
9
|
+
watch( '^lib/harmony/(.*)\.rb' ) {|m| ruby "test/#{m[1]}_test.rb" }
|
10
|
+
watch( '^test/test_helper\.rb' ) { ruby tests }
|
11
|
+
|
12
|
+
# --------------------------------------------------
|
13
|
+
# Signal Handling
|
14
|
+
# --------------------------------------------------
|
15
|
+
Signal.trap('QUIT') { ruby tests } # Ctrl-\
|
16
|
+
Signal.trap('INT' ) { abort("\n") } # Ctrl-C
|
17
|
+
|
18
|
+
# --------------------------------------------------
|
19
|
+
# Helpers
|
20
|
+
# --------------------------------------------------
|
21
|
+
def ruby(*paths)
|
22
|
+
run "ruby #{gem_opt} -I.:lib:test -e'%w( #{paths.flatten.join(' ')} ).each {|p| require p }'"
|
23
|
+
end
|
24
|
+
|
25
|
+
def tests
|
26
|
+
Dir['test/**/*_test.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
def run( cmd )
|
30
|
+
puts cmd
|
31
|
+
system cmd
|
32
|
+
end
|
33
|
+
|
34
|
+
def gem_opt
|
35
|
+
defined?(Gem) ? "-rubygems" : ""
|
36
|
+
end
|
data/test/page_test.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class PageTest < MiniTest::Unit::TestCase
|
4
|
+
include Harmony
|
5
|
+
|
6
|
+
PAGE = Page.new
|
7
|
+
|
8
|
+
test "api" do
|
9
|
+
assert_respond_to Page, :fetch
|
10
|
+
assert_respond_to Page, :new
|
11
|
+
assert_respond_to PAGE, :window
|
12
|
+
assert_respond_to PAGE, :document
|
13
|
+
assert_respond_to PAGE, :execute_js
|
14
|
+
assert_respond_to PAGE, :x
|
15
|
+
assert_respond_to PAGE, :to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
test "document shortcut" do
|
19
|
+
assert_equal PAGE.window.document, PAGE.document
|
20
|
+
end
|
21
|
+
|
22
|
+
test "executes javascript" do
|
23
|
+
assert_equal 7, PAGE.x('5+2')
|
24
|
+
end
|
25
|
+
|
26
|
+
test "excutes DOM-accessing javascript" do
|
27
|
+
page = Page.new(<<-HTML)
|
28
|
+
<html>
|
29
|
+
<head>
|
30
|
+
<title>Harmony</title>
|
31
|
+
</head>
|
32
|
+
<body>
|
33
|
+
<div></div>
|
34
|
+
<div></div>
|
35
|
+
</body>
|
36
|
+
</html>
|
37
|
+
HTML
|
38
|
+
assert_equal 'Harmony', page.document.title
|
39
|
+
assert_equal 2, page.x(<<-JS)
|
40
|
+
document.getElementsByTagName('div').length
|
41
|
+
JS
|
42
|
+
end
|
43
|
+
|
44
|
+
test "fetches remote document" do
|
45
|
+
path = tempfile(<<-HTML)
|
46
|
+
<html><head><title>foo</title></head><body></body></html>
|
47
|
+
HTML
|
48
|
+
page = Page.fetch("file://#{path}")
|
49
|
+
assert_equal 'foo', page.document.title
|
50
|
+
end
|
51
|
+
|
52
|
+
test "default window" do
|
53
|
+
assert_empty Page.new.document.title
|
54
|
+
end
|
55
|
+
|
56
|
+
test "cast to html" do
|
57
|
+
assert_equal "<html><head><title></title></head><body></body></html>", Page.new.to_html
|
58
|
+
end
|
59
|
+
|
60
|
+
test "loads javascript file" do
|
61
|
+
path = tempfile(<<-HTML)
|
62
|
+
function foo() { return 'bar' };
|
63
|
+
HTML
|
64
|
+
page = Page.new.load(path)
|
65
|
+
assert_equal 'bar', page.x('foo()')
|
66
|
+
end
|
67
|
+
|
68
|
+
test "can load multiple files as array" do
|
69
|
+
paths = []
|
70
|
+
paths << tempfile(<<-HTML)
|
71
|
+
function foo() { return 'bar' };
|
72
|
+
HTML
|
73
|
+
paths << tempfile(<<-HTML)
|
74
|
+
function moo() { return 'boo' };
|
75
|
+
HTML
|
76
|
+
|
77
|
+
page = Page.new.load(paths)
|
78
|
+
assert_equal 'bar', page.x('foo()')
|
79
|
+
assert_equal 'boo', page.x('moo()')
|
80
|
+
end
|
81
|
+
|
82
|
+
test "can load multiple files as splat" do
|
83
|
+
paths = []
|
84
|
+
paths << tempfile(<<-HTML)
|
85
|
+
function foo() { return 'bar' };
|
86
|
+
HTML
|
87
|
+
paths << tempfile(<<-HTML)
|
88
|
+
function moo() { return 'boo' };
|
89
|
+
HTML
|
90
|
+
|
91
|
+
page = Page.new.load(*paths)
|
92
|
+
assert_equal 'bar', page.x('foo()')
|
93
|
+
assert_equal 'boo', page.x('moo()')
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
def tempfile(content)
|
98
|
+
Tempfile.open('abc') {|f| f << content; @__path = f.path }
|
99
|
+
@__path
|
100
|
+
end
|
101
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
begin require 'ruby-debug'; rescue LoadError; end
|
4
|
+
begin require 'redgreen' ; rescue LoadError; end
|
5
|
+
begin require 'phocus' ; rescue LoadError; end
|
6
|
+
|
7
|
+
require 'lib/harmony'
|
8
|
+
|
9
|
+
class MiniTest::Unit::TestCase
|
10
|
+
def self.test(name, &block)
|
11
|
+
define_method("test_#{name}".gsub(/\s/,'_'), &block)
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kuntoaji-harmony
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 6
|
10
|
+
version: 0.5.6
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- mynyml
|
14
|
+
- Kunto Aji Kristianto
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-02-03 00:00:00 +07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: johnson
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - "="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: -223651601
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
- pre
|
36
|
+
- 3
|
37
|
+
version: 2.0.0.pre3
|
38
|
+
type: :runtime
|
39
|
+
version_requirements: *id001
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: envjs
|
42
|
+
prerelease: false
|
43
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - "="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 29
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
- 3
|
52
|
+
- 7
|
53
|
+
version: 0.3.7
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id002
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: minitest
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id003
|
70
|
+
description: Javascript + DOM in your ruby, the simple way. Kuntoaji's version.
|
71
|
+
email:
|
72
|
+
- mynyml@gmail.com
|
73
|
+
- kunto.aji.kr@gmail.com
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files: []
|
79
|
+
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE
|
84
|
+
- Manifest
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- docs.watchr
|
88
|
+
- harmony.gemspec
|
89
|
+
- lib/harmony.rb
|
90
|
+
- lib/harmony/page.rb
|
91
|
+
- lib/harmony/version.rb
|
92
|
+
- specs.watchr
|
93
|
+
- test/harmony_test.rb
|
94
|
+
- test/page_test.rb
|
95
|
+
- test/test_helper.rb
|
96
|
+
has_rdoc: true
|
97
|
+
homepage: http://github.com/kuntoaji/harmony
|
98
|
+
licenses: []
|
99
|
+
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.4.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Javascript + DOM in your ruby, the simple way
|
130
|
+
test_files:
|
131
|
+
- test/harmony_test.rb
|
132
|
+
- test/page_test.rb
|
133
|
+
- test/test_helper.rb
|