ebot-hiking 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +8 -0
- data/bin/go_hiking +20 -0
- data/hiking.gemspec +37 -0
- data/public/hiking.rb +173 -0
- data/test/test_hiking.rb +24 -0
- metadata +76 -0
data/README
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
This program utilizes the camping micro-framework
|
2
|
+
to create a web based xpath interpreter.
|
3
|
+
|
4
|
+
Pastie at http://pastie.org/pastes/212350
|
5
|
+
|
6
|
+
Author:: Ed Botzum (mailto:blog@edbotz.us)
|
7
|
+
Copyright:: Copyright (c) 2008 edbotz.us
|
8
|
+
License:: Distributes under the same terms as Ruby
|
data/bin/go_hiking
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'hiking'
|
4
|
+
require 'webrick/httpserver'
|
5
|
+
require 'camping/webrick'
|
6
|
+
|
7
|
+
puts ''
|
8
|
+
puts '** Start your hike down the xpath at http://localhost:5501 **'
|
9
|
+
puts '** End your hike down the xpath with Ctrl+C **'
|
10
|
+
puts ''
|
11
|
+
|
12
|
+
s = WEBrick::HTTPServer.new :BindAddress => "0.0.0.0", :Port => 5501
|
13
|
+
s.mount "/", WEBrick::CampingHandler, Hiking
|
14
|
+
|
15
|
+
# This lets Ctrl+C shut down your server
|
16
|
+
trap(:INT) do
|
17
|
+
s.shutdown
|
18
|
+
end
|
19
|
+
|
20
|
+
s.start
|
data/hiking.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{hiking}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ed Botzum"]
|
9
|
+
s.date = %q{2008-11-10}
|
10
|
+
s.default_executable = %q{go_hiking}
|
11
|
+
s.description = %q{A tiny xpath application written with the camping microframework.}
|
12
|
+
s.email = %q{contact@edbotz.us}
|
13
|
+
s.executables = ["go_hiking"]
|
14
|
+
s.extra_rdoc_files = ["bin/go_hiking", "README"]
|
15
|
+
s.files = ["bin/go_hiking", "Manifest", "public/hiking.rb", "Rakefile", "README", "test/test_hiking.rb", "hiking.gemspec"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://github.com/ebot/hiking}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hiking", "--main", "README"]
|
19
|
+
s.require_paths = ["public"]
|
20
|
+
s.rubyforge_project = %q{hiking}
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
|
+
s.summary = %q{A tiny xpath application written with the camping microframework.}
|
23
|
+
s.test_files = ["test/test_hiking.rb"]
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 2
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
s.add_development_dependency(%q<camping>, [">= 0", "= 1.5.0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<camping>, [">= 0", "= 1.5.0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<camping>, [">= 0", "= 1.5.0"])
|
36
|
+
end
|
37
|
+
end
|
data/public/hiking.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'camping'
|
4
|
+
require "rexml/document"
|
5
|
+
|
6
|
+
include REXML
|
7
|
+
|
8
|
+
Camping.goes :Hiking
|
9
|
+
|
10
|
+
module Hiking::Controllers
|
11
|
+
class Index < R '/'
|
12
|
+
def get
|
13
|
+
@xml = input.xml
|
14
|
+
@xpath = input.xpath
|
15
|
+
|
16
|
+
unless @xml == nil
|
17
|
+
doc = Document.new input.xml
|
18
|
+
@results = XPath.match doc, input.xpath
|
19
|
+
else
|
20
|
+
@xml = "<test>\r\n<item number=\"1\">First Item</item>\r\n</test>"
|
21
|
+
end
|
22
|
+
|
23
|
+
render :index
|
24
|
+
end
|
25
|
+
|
26
|
+
def post
|
27
|
+
get
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Style < R '/style.css'
|
32
|
+
def get
|
33
|
+
@headers["Content-Type"] = "text/css; charset=utf-8"
|
34
|
+
@body = %{
|
35
|
+
body {
|
36
|
+
background-color: black;
|
37
|
+
color: white;
|
38
|
+
font-family: Courier New;
|
39
|
+
font-size: small;
|
40
|
+
}
|
41
|
+
h1 {
|
42
|
+
color: green;
|
43
|
+
font-size: 175%;
|
44
|
+
margin: 0; padding: 10px;
|
45
|
+
border-bottom: solid 1px white;
|
46
|
+
}
|
47
|
+
div.content {
|
48
|
+
padding: 10px 0px 0px 10px;
|
49
|
+
}
|
50
|
+
h2 {
|
51
|
+
color: green;
|
52
|
+
font-size: 150%;
|
53
|
+
border-bottom: solid 1px white;
|
54
|
+
width: 250px;
|
55
|
+
}
|
56
|
+
strong {
|
57
|
+
color: yellow;
|
58
|
+
font-size: 115%
|
59
|
+
}
|
60
|
+
input, textarea, button {
|
61
|
+
border: solid 1px white;
|
62
|
+
background-color: #4B4B4B;
|
63
|
+
color: white;
|
64
|
+
}
|
65
|
+
button {cursor: pointer;}
|
66
|
+
a {
|
67
|
+
color:white;
|
68
|
+
text-decoration:underline;
|
69
|
+
}
|
70
|
+
a:link {
|
71
|
+
color:white;
|
72
|
+
text-decoration:underline;
|
73
|
+
}
|
74
|
+
a:visited {
|
75
|
+
color:white;
|
76
|
+
text-decoration:underline;
|
77
|
+
}
|
78
|
+
a:active {
|
79
|
+
color:white;
|
80
|
+
text-decoration:none;
|
81
|
+
}
|
82
|
+
a:hover {
|
83
|
+
color:yellow;
|
84
|
+
text-decoration: underline;
|
85
|
+
}
|
86
|
+
div.footer {
|
87
|
+
padding: 5px 0px 5px 10px;
|
88
|
+
margin-top: 5px;
|
89
|
+
border-top: solid 1px gray;
|
90
|
+
text-align: center;
|
91
|
+
font-style: italic;
|
92
|
+
font-size: 90%;
|
93
|
+
color: lightgray;
|
94
|
+
clear: both;
|
95
|
+
}
|
96
|
+
div.results {
|
97
|
+
float: right;
|
98
|
+
margin-top: -20px;
|
99
|
+
margin-right: 20px;
|
100
|
+
display: inline;
|
101
|
+
}
|
102
|
+
* html div.results {
|
103
|
+
margin-top: -3px;
|
104
|
+
}
|
105
|
+
div.query_form {
|
106
|
+
float: left;
|
107
|
+
width: 800px;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
module Hiking::Views
|
115
|
+
def layout
|
116
|
+
html do
|
117
|
+
head do
|
118
|
+
title 'Hiking - An XPATH Interpreter'
|
119
|
+
link :rel => 'stylesheet', :type => 'text/css',
|
120
|
+
:href => '/style.css', :media => 'screen'
|
121
|
+
end
|
122
|
+
body do
|
123
|
+
h1.header 'Hiking - An XPATH Interpreter'
|
124
|
+
div.content do
|
125
|
+
self << yield
|
126
|
+
end
|
127
|
+
div.footer do
|
128
|
+
p do
|
129
|
+
span 'Created by '
|
130
|
+
a(:href => 'http://edbotz.us') {'Ed Botzum'}
|
131
|
+
span ' with '
|
132
|
+
a(:href => 'http://camping.rubyforge.org/') {'Camping'}
|
133
|
+
span ' on JUN 03 2008.'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def index
|
141
|
+
div.query_form do
|
142
|
+
form :action => '/', :method => 'post', :name => 'query' do
|
143
|
+
fieldset do
|
144
|
+
p do
|
145
|
+
strong 'XPATH Statement: '
|
146
|
+
br
|
147
|
+
input :type => 'text', :name => 'xpath', :id => 'xpath',
|
148
|
+
:size => '108', :value => @xpath
|
149
|
+
span ' '
|
150
|
+
button(:type => 'submit') {'Query'}
|
151
|
+
end
|
152
|
+
|
153
|
+
p do
|
154
|
+
strong 'XML: '
|
155
|
+
br
|
156
|
+
textarea @xml, :name => 'xml', :id => 'xml', :rows => '15',
|
157
|
+
:cols => '90'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
div.results do
|
164
|
+
h2 'Results: '
|
165
|
+
textarea @results, :name => 'results', :id => 'results',
|
166
|
+
:rows => '19', :cols => '30'
|
167
|
+
end
|
168
|
+
|
169
|
+
script <<-END, :language => "JavaScript1.2"
|
170
|
+
document.getElementById('xpath').focus();
|
171
|
+
END
|
172
|
+
end
|
173
|
+
end
|
data/test/test_hiking.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mosquito'
|
3
|
+
require File.dirname(__FILE__) + "/../public/hiking"
|
4
|
+
|
5
|
+
class TestHiking < Camping::WebTest
|
6
|
+
test_xml = '<test><item number="1">First Item</item></test>'
|
7
|
+
|
8
|
+
test "should get index" do
|
9
|
+
get
|
10
|
+
assert_response :success
|
11
|
+
assert_match_body %r{<test>\r\n<item number=\"1\">First Item</item>\r\n</test>}
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should parse xml" do
|
15
|
+
post '/',
|
16
|
+
:xml => test_xml,
|
17
|
+
:xpath => "/test/item/@number",
|
18
|
+
:body => "Body"
|
19
|
+
|
20
|
+
assert_response :success
|
21
|
+
|
22
|
+
assert_match_body %r{<textarea name=\"results\" cols=\"30\" rows=\"19\" id=\"results\">1</textarea>}
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ebot-hiking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed Botzum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-10 00:00:00 -08:00
|
13
|
+
default_executable: go_hiking
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: camping
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
- - "="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.5.0
|
26
|
+
version:
|
27
|
+
description: A tiny xpath application written with the camping microframework.
|
28
|
+
email: contact@edbotz.us
|
29
|
+
executables:
|
30
|
+
- go_hiking
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- bin/go_hiking
|
35
|
+
- README
|
36
|
+
files:
|
37
|
+
- bin/go_hiking
|
38
|
+
- Manifest
|
39
|
+
- public/hiking.rb
|
40
|
+
- Rakefile
|
41
|
+
- README
|
42
|
+
- test/test_hiking.rb
|
43
|
+
- hiking.gemspec
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/ebot/hiking
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --line-numbers
|
49
|
+
- --inline-source
|
50
|
+
- --title
|
51
|
+
- Hiking
|
52
|
+
- --main
|
53
|
+
- README
|
54
|
+
require_paths:
|
55
|
+
- public
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "1.2"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: hiking
|
71
|
+
rubygems_version: 1.2.0
|
72
|
+
signing_key:
|
73
|
+
specification_version: 2
|
74
|
+
summary: A tiny xpath application written with the camping microframework.
|
75
|
+
test_files:
|
76
|
+
- test/test_hiking.rb
|