gorp 0.17.0 → 0.18.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/gorp.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gorp}
5
- s.version = "0.17.0"
5
+ s.version = "0.18.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sam Ruby"]
9
- s.date = %q{2009-12-31}
9
+ s.date = %q{2010-01-01}
10
10
  s.description = %q{ Enables the creation of scenarios that involve creating a rails project,
11
11
  starting and stoppping of servers, generating projects, editing files,
12
12
  issuing http requests, running of commands, etc. Output is captured as
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
16
16
  assertions based on selections (typically CSS) against the generated HTML.
17
17
  }
18
18
  s.email = %q{rubys@intertwingly.net}
19
- s.extra_rdoc_files = ["README", "lib/gorp.rb", "lib/gorp/edit.rb", "lib/gorp/env.rb", "lib/gorp/net.rb", "lib/gorp/rails.rb", "lib/gorp/test.rb", "lib/version.rb"]
20
- s.files = ["Manifest", "README", "Rakefile", "gorp.gemspec", "lib/gorp.rb", "lib/gorp/edit.rb", "lib/gorp/env.rb", "lib/gorp/net.rb", "lib/gorp/rails.rb", "lib/gorp/test.rb", "lib/version.rb"]
19
+ s.extra_rdoc_files = ["README", "lib/gorp.rb", "lib/gorp/commands.rb", "lib/gorp/edit.rb", "lib/gorp/env.rb", "lib/gorp/net.rb", "lib/gorp/output.rb", "lib/gorp/rails.env", "lib/gorp/rails.rb", "lib/gorp/test.rb", "lib/gorp/xml.rb", "lib/version.rb"]
20
+ s.files = ["Manifest", "README", "Rakefile", "gorp.gemspec", "lib/gorp.rb", "lib/gorp/commands.rb", "lib/gorp/edit.rb", "lib/gorp/env.rb", "lib/gorp/net.rb", "lib/gorp/output.rb", "lib/gorp/rails.env", "lib/gorp/rails.rb", "lib/gorp/test.rb", "lib/gorp/xml.rb", "lib/version.rb"]
21
21
  s.homepage = %q{http://github.com/rubys/gorp}
22
22
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Gorp", "--main", "README"]
23
23
  s.require_paths = ["lib"]
data/lib/gorp.rb CHANGED
@@ -4,15 +4,15 @@
4
4
  # You have been warned.
5
5
 
6
6
  require 'fileutils'
7
- require 'open3'
8
7
  require 'builder'
9
- require 'time'
10
8
 
11
9
  require 'gorp/env'
10
+ require 'gorp/commands'
12
11
  require 'gorp/edit'
13
12
  require 'gorp/output'
14
13
  require 'gorp/net'
15
14
  require 'gorp/rails'
15
+ require 'gorp/xml'
16
16
 
17
17
  require 'rbconfig'
18
18
  $ruby = File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])
@@ -44,245 +44,6 @@ RUNFILE = File.join($WORK, 'status.run')
44
44
  open(RUNFILE,'w') {|running| running.puts(Process.pid)}
45
45
  at_exit { FileUtils.rm_f RUNFILE }
46
46
 
47
- def overview message
48
- $x.p message.gsub(/(^|\n)\s+/, ' ').strip, :class=>'overview'
49
- end
50
-
51
- def desc message
52
- $x.p message, :class=>'desc'
53
- end
54
-
55
- def log type, message
56
- type = type.to_s.ljust(5).upcase
57
- STDOUT.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] #{type} #{message}")
58
- end
59
-
60
- def head number, title
61
- $section = "#{number} #{title}"
62
- log '====>', $section
63
-
64
- $x.a(:class => 'toc', :id => "section-#{number}") {$x.h2 $section}
65
- $toc.li {$toc.a $section, :href => "#section-#{number}"}
66
- end
67
-
68
- def issue text, options={}
69
- log :issue, text
70
-
71
- $issue+=1
72
- $x.p :class => 'issue', :id => "issue-#{$issue}" do
73
- $x.text! text
74
- if options[:ticket]
75
- $x.text! ' ('
76
- $x.a "ticket #{options[:ticket]}", :href=>
77
- 'https://rails.lighthouseapp.com/projects/8994/tickets/' +
78
- options[:ticket].to_s
79
- $x.text! ')'
80
- end
81
- end
82
- $todos.li do
83
- section = $section.split(' ').first
84
- $todos.a "Section #{section}:", :href => "#section-#{$section}"
85
- $todos.a "#{text}", :href => "#issue-#{$issue}"
86
- end
87
- end
88
-
89
- def db statement, hilight=[]
90
- log :db, statement
91
- $x.pre "sqlite3> #{statement}", :class=>'stdin'
92
- cmd = "sqlite3 --line db/development.sqlite3 #{statement.inspect}"
93
- popen3 cmd, hilight
94
- end
95
-
96
- def ruby args
97
- cmd "ruby #{args}"
98
- end
99
-
100
- def console script
101
- open('tmp/irbrc','w') {|file| file.write('IRB.conf[:PROMPT_MODE]=:SIMPLE')}
102
- cmd "echo #{script.inspect} | IRBRC=tmp/irbrc ruby script/console"
103
- FileUtils.rm_rf 'tmp/irbrc'
104
- end
105
-
106
- def cmd args, hilight=[]
107
- log :cmd, args
108
- $x.pre args, :class=>'stdin'
109
- if args == 'rake db:migrate'
110
- Dir.chdir 'db/migrate' do
111
- date = '20100301000000'
112
- Dir['[0-9]*'].sort_by {|file| file=~/201003/?file:'x'+file}.each do |file|
113
- file =~ /^([0-9]*)_(.*)$/
114
- FileUtils.mv file, "#{date}_#{$2}" unless $1 == date.next!
115
- $x.pre "mv #{file} #{date}_#{$2}" unless $1 == date
116
- end
117
- end
118
- end
119
- args += ' -C' if args == 'ls -p'
120
- popen3 args, hilight
121
- end
122
-
123
- def popen3 args, hilight=[]
124
- Open3.popen3(args) do |pin, pout, perr|
125
- terr = Thread.new do
126
- $x.pre perr.readline.chomp, :class=>'stderr' until perr.eof?
127
- end
128
- pin.close
129
- until pout.eof?
130
- line = pout.readline
131
- if hilight.any? {|pattern| line.include? pattern}
132
- outclass='hilight'
133
- elsif line =~ /\x1b\[\d/
134
- line.gsub! /\x1b\[1m\x1b\[3\dm(.*?)\x1b\[0m/, '\1'
135
- outclass = 'logger'
136
- else
137
- outclass='stdout'
138
- end
139
-
140
- if line.strip.size == 0
141
- $x.pre ' ', :class=>outclass
142
- else
143
- $x.pre line.chomp, :class=>outclass
144
- end
145
- end
146
- terr.join
147
- end
148
- end
149
-
150
- def irb file
151
- $x.pre "irb #{file}", :class=>'stdin'
152
- log :irb, file
153
- cmd = "irb -f -rubygems -r ./config/boot --prompt-mode simple #{$CODE}/#{file}"
154
- Open3.popen3(cmd) do |pin, pout, perr|
155
- terr = Thread.new do
156
- until perr.eof?
157
- line = perr.readline.chomp
158
- line.gsub! /\x1b\[4(;\d+)*m(.*?)\x1b\[0m/, '\2'
159
- line.gsub! /\x1b\[0(;\d+)*m(.*?)\x1b\[0m/, '\2'
160
- line.gsub! /\x1b\[0(;\d+)*m/, ''
161
- $x.pre line, :class=>'stderr'
162
- end
163
- end
164
- pin.close
165
- prompt = nil
166
- until pout.eof?
167
- line = pout.readline
168
- if line =~ /^([?>]>)\s*#\s*(START|END):/
169
- prompt = $1
170
- elsif line =~ /^([?>]>)\s+$/
171
- $x.pre ' ', :class=>'irb'
172
- prompt ||= $1
173
- elsif line =~ /^([?>]>)(.*)\n/
174
- prompt ||= $1
175
- $x.pre prompt + $2, :class=>'irb'
176
- prompt = nil
177
- elsif line =~ /^\w+(::\w+)*: /
178
- $x.pre line.chomp, :class=>'stderr'
179
- elsif line =~ /^\s+from [\/.:].*:\d+:in `\w.*'\s*$/
180
- $x.pre line.chomp, :class=>'stderr'
181
- else
182
- $x.pre line.chomp, :class=>'stdout'
183
- end
184
- end
185
- terr.join
186
- end
187
- end
188
-
189
- # pluggable XML parser support
190
- begin
191
- raise LoadError if ARGV.include? 'rexml'
192
- require 'nokogiri'
193
- def xhtmlparse(text)
194
- Nokogiri::HTML(text)
195
- end
196
- Comment=Nokogiri::XML::Comment
197
- rescue LoadError
198
- require 'rexml/document'
199
-
200
- HTML_VOIDS = %w(area base br col command embed hr img input keygen link meta
201
- param source)
202
-
203
- def xhtmlparse(text)
204
- begin
205
- require 'htmlentities'
206
- text.gsub! '&', '&'
207
- text.gsub! '<', '<'
208
- text.gsub! '>', '>'
209
- text.gsub! ''', '''
210
- text.gsub! '"', '"'
211
- text.force_encoding('utf-8') if text.respond_to? :force_encoding
212
- text = HTMLEntities.new.decode(text)
213
- rescue LoadError
214
- end
215
- doc = REXML::Document.new(text)
216
- doc.get_elements('//*[not(* or text())]').each do |e|
217
- e.text='' unless HTML_VOIDS.include? e.name
218
- end
219
- doc
220
- end
221
-
222
- class REXML::Element
223
- def has_attribute? name
224
- self.attributes.has_key? name
225
- end
226
-
227
- def at xpath
228
- self.elements[xpath]
229
- end
230
-
231
- def search xpath
232
- self.elements.to_a(xpath)
233
- end
234
-
235
- def content=(string)
236
- self.text=string
237
- end
238
-
239
- def [](index)
240
- if index.instance_of? String
241
- self.attributes[index]
242
- else
243
- super(index)
244
- end
245
- end
246
-
247
- def []=(index, value)
248
- if index.instance_of? String
249
- self.attributes[index] = value
250
- else
251
- super(index, value)
252
- end
253
- end
254
- end
255
-
256
- module REXML::Node
257
- def before(node)
258
- self.parent.insert_before(self, node)
259
- end
260
-
261
- def add_previous_sibling(node)
262
- self.parent.insert_before(self, node)
263
- end
264
-
265
- def to_xml
266
- self.to_s
267
- end
268
- end
269
-
270
- # monkey patch for Ruby 1.8.6
271
- doc = REXML::Document.new '<doc xmlns="ns"><item name="foo"/></doc>'
272
- if not doc.root.elements["item[@name='foo']"]
273
- class REXML::Element
274
- def attribute( name, namespace=nil )
275
- prefix = nil
276
- prefix = namespaces.index(namespace) if namespace
277
- prefix = nil if prefix == 'xmlns'
278
- attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
279
- end
280
- end
281
- end
282
-
283
- Comment = REXML::Comment
284
- end
285
-
286
47
  def secsplit section
287
48
  section.to_s.split('.').map {|n| n.to_i}
288
49
  end
@@ -0,0 +1,164 @@
1
+ require 'fileutils'
2
+ require 'open3'
3
+ require 'time'
4
+
5
+ module Gorp
6
+ module Commands
7
+ def overview message
8
+ $x.p message.gsub(/(^|\n)\s+/, ' ').strip, :class=>'overview'
9
+ end
10
+
11
+ def desc message
12
+ $x.p message, :class=>'desc'
13
+ end
14
+
15
+ def log type, message
16
+ type = type.to_s.ljust(5).upcase
17
+ STDOUT.puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] #{type} #{message}")
18
+ end
19
+
20
+ def head number, title
21
+ $section = "#{number} #{title}"
22
+ log '====>', $section
23
+
24
+ $x.a(:class => 'toc', :id => "section-#{number}") {$x.h2 $section}
25
+ $toc.li {$toc.a $section, :href => "#section-#{number}"}
26
+ end
27
+
28
+ def issue text, options={}
29
+ log :issue, text
30
+
31
+ $issue+=1
32
+ $x.p :class => 'issue', :id => "issue-#{$issue}" do
33
+ $x.text! text
34
+ if options[:ticket]
35
+ $x.text! ' ('
36
+ $x.a "ticket #{options[:ticket]}", :href=>
37
+ 'https://rails.lighthouseapp.com/projects/8994/tickets/' +
38
+ options[:ticket].to_s
39
+ $x.text! ')'
40
+ end
41
+ end
42
+ $todos.li do
43
+ section = $section.split(' ').first
44
+ $todos.a "Section #{section}:", :href => "#section-#{$section}"
45
+ $todos.a "#{text}", :href => "#issue-#{$issue}"
46
+ end
47
+ end
48
+
49
+ def db statement, hilight=[]
50
+ log :db, statement
51
+ $x.pre "sqlite3> #{statement}", :class=>'stdin'
52
+ cmd = "sqlite3 --line db/development.sqlite3 #{statement.inspect}"
53
+ popen3 cmd, hilight
54
+ end
55
+
56
+ def ruby args
57
+ cmd "ruby #{args}"
58
+ end
59
+
60
+ def rake args
61
+ cmd "rake #{args}"
62
+ end
63
+
64
+ def console script
65
+ open('tmp/irbrc','w') {|fh| fh.write('IRB.conf[:PROMPT_MODE]=:SIMPLE')}
66
+ cmd "echo #{script.inspect} | IRBRC=tmp/irbrc ruby script/console"
67
+ FileUtils.rm_rf 'tmp/irbrc'
68
+ end
69
+
70
+ def cmd args, hilight=[]
71
+ x = $x
72
+ log :cmd, args
73
+ $x = Builder::XmlMarkup.new(:indent => 2) if block_given?
74
+ $x.pre args, :class=>'stdin'
75
+ if args == 'rake db:migrate'
76
+ Dir.chdir 'db/migrate' do
77
+ date = '20100301000000'
78
+ Dir['[0-9]*'].sort_by {|fn| fn=~/201003/ ? fn : 'x'+fn}.each do |file|
79
+ file =~ /^([0-9]*)_(.*)$/
80
+ FileUtils.mv file, "#{date}_#{$2}" unless $1 == date.next!
81
+ $x.pre "mv #{file} #{date}_#{$2}" unless $1 == date
82
+ end
83
+ end
84
+ end
85
+ args += ' -C' if args == 'ls -p'
86
+ popen3 args, hilight
87
+ if block_given?
88
+ p $x.target!
89
+ @raw = $x.target!
90
+ @selected = HTML::Document.new(@raw).root.children
91
+ yield
92
+ end
93
+ ensure
94
+ $x = x
95
+ end
96
+
97
+ def popen3 args, hilight=[]
98
+ Open3.popen3(args) do |pin, pout, perr|
99
+ terr = Thread.new do
100
+ $x.pre perr.readline.chomp, :class=>'stderr' until perr.eof?
101
+ end
102
+ pin.close
103
+ until pout.eof?
104
+ line = pout.readline
105
+ if hilight.any? {|pattern| line.include? pattern}
106
+ outclass='hilight'
107
+ elsif line =~ /\x1b\[\d/
108
+ line.gsub! /\x1b\[1m\x1b\[3\dm(.*?)\x1b\[0m/, '\1'
109
+ outclass = 'logger'
110
+ else
111
+ outclass='stdout'
112
+ end
113
+
114
+ if line.strip.size == 0
115
+ $x.pre ' ', :class=>outclass
116
+ else
117
+ $x.pre line.chomp, :class=>outclass
118
+ end
119
+ end
120
+ terr.join
121
+ end
122
+ end
123
+
124
+ def irb file
125
+ $x.pre "irb #{file}", :class=>'stdin'
126
+ log :irb, file
127
+ cmd = "irb -f -rubygems -r ./config/boot --prompt-mode simple " +
128
+ "#{$CODE}/#{file}"
129
+ Open3.popen3(cmd) do |pin, pout, perr|
130
+ terr = Thread.new do
131
+ until perr.eof?
132
+ line = perr.readline.chomp
133
+ line.gsub! /\x1b\[4(;\d+)*m(.*?)\x1b\[0m/, '\2'
134
+ line.gsub! /\x1b\[0(;\d+)*m(.*?)\x1b\[0m/, '\2'
135
+ line.gsub! /\x1b\[0(;\d+)*m/, ''
136
+ $x.pre line, :class=>'stderr'
137
+ end
138
+ end
139
+ pin.close
140
+ prompt = nil
141
+ until pout.eof?
142
+ line = pout.readline
143
+ if line =~ /^([?>]>)\s*#\s*(START|END):/
144
+ prompt = $1
145
+ elsif line =~ /^([?>]>)\s+$/
146
+ $x.pre ' ', :class=>'irb'
147
+ prompt ||= $1
148
+ elsif line =~ /^([?>]>)(.*)\n/
149
+ prompt ||= $1
150
+ $x.pre prompt + $2, :class=>'irb'
151
+ prompt = nil
152
+ elsif line =~ /^\w+(::\w+)*: /
153
+ $x.pre line.chomp, :class=>'stderr'
154
+ elsif line =~ /^\s+from [\/.:].*:\d+:in `\w.*'\s*$/
155
+ $x.pre line.chomp, :class=>'stderr'
156
+ else
157
+ $x.pre line.chomp, :class=>'stdout'
158
+ end
159
+ end
160
+ terr.join
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,163 @@
1
+ require 'fileutils'
2
+ require 'time'
3
+
4
+ at_exit do
5
+ next unless $output
6
+
7
+ $x.declare! :DOCTYPE, :html
8
+ $x.html :xmlns => 'http://www.w3.org/1999/xhtml' do
9
+ $x.header do
10
+ $x.title $title
11
+ $x.meta 'http-equiv'=>'text/html; charset=UTF-8'
12
+ $x.style :type => "text/css" do
13
+ $x.text! <<-'EOF'.unindent(2)
14
+ body {background-color: #F5F5DC}
15
+ #banner {margin-top: 0}
16
+ pre {font-weight: bold; margin: 0; padding: 0}
17
+ pre.stdin {color: #800080; margin-top: 1em; padding: 0}
18
+ pre.irb {color: #800080; padding: 0}
19
+ pre.stdout {color: #000; padding: 0}
20
+ pre.logger {color: #088; padding: 0}
21
+ pre.hilight {color: #000; background-color: #FF0; padding: 0}
22
+ pre.stderr {color: #F00; padding: 0}
23
+ div.body {border-style: solid; border-color: #800080; padding: 0.5em}
24
+ .issue, .traceback {background:#FDD; border: 4px solid #F00;
25
+ font-weight: bold; margin-top: 1em; padding: 0.5em}
26
+ div.body, .issue, .traceback {
27
+ -webkit-border-radius: 0.7em; -moz-border-radius: 0.7em;}
28
+ ul.toc {list-style: none}
29
+ ul a {text-decoration: none}
30
+ ul a:hover {text-decoration: underline; color: #000;
31
+ background-color: #F5F5DC}
32
+ a.toc h2 {background-color: #981A21; color:#FFF; padding: 6px}
33
+ ul a:visited {color: #000}
34
+ h2 {clear: both}
35
+ p.desc {font-style: italic}
36
+ p.overview {border-width: 2px; border-color: #000;
37
+ border-style: solid; border-radius: 4em;
38
+ background-color: #CCF; margin: 1.5em 1.5em; padding: 1em 2em;
39
+ -webkit-border-radius: 4em; -moz-border-radius: 4em;}
40
+ EOF
41
+ end
42
+ end
43
+
44
+ $x.body do
45
+ $x.h1 $title, :id=>'banner'
46
+ $x.h2 'Table of Contents'
47
+ $x.ul :class => 'toc'
48
+
49
+ # determine which range(s) of steps are to be executed
50
+ ranges = ARGV.grep(/^ \d+(.\d+)? ( (-|\.\.) \d+(.\d+)? )? /x).map do |arg|
51
+ bounds = arg.split(/-|\.\./)
52
+ Range.new(secsplit(bounds.first), secsplit(bounds.last))
53
+ end
54
+
55
+ # optionally save a snapshot
56
+ if ARGV.include? 'restore'
57
+ log :snap, 'restore'
58
+ Dir.chdir $BASE
59
+ FileUtils.rm_rf $WORK
60
+ FileUtils.cp_r "snapshot", $WORK, :preserve => true
61
+ Dir.chdir $WORK
62
+ if $autorestart and File.directory? $autorestart
63
+ Dir.chdir $autorestart
64
+ restart_server
65
+ end
66
+ end
67
+
68
+ # run steps
69
+ e = nil
70
+ begin
71
+ $sections.each do |section, title, steps|
72
+ omit = secinclude($omit, section)
73
+ omit ||= (!ranges.empty? and !secinclude(ranges, section))
74
+
75
+ if omit
76
+ $x.a(:class => 'omit', :id => "section-#{section}") do
77
+ $x.comment! title
78
+ end
79
+ else
80
+ head section, title
81
+ steps.call
82
+ end
83
+ end
84
+ rescue Exception => e
85
+ $x.pre :class => 'traceback' do
86
+ STDERR.puts e.inspect
87
+ $x.text! "#{e.inspect}\n"
88
+ e.backtrace.each {|line| $x.text! " #{line}\n"}
89
+ end
90
+ ensure
91
+ if e.class != SystemExit
92
+ $cleanup.call if $cleanup
93
+
94
+ # terminate server
95
+ Process.kill "INT", $server if $server
96
+ Process.wait($server) if $server
97
+
98
+ # optionally save a snapshot
99
+ if ARGV.include? 'save'
100
+ log :snap, 'save'
101
+ Dir.chdir $BASE
102
+ FileUtils.rm_rf "snapshot"
103
+ FileUtils.cp_r $WORK, "snapshot", :preserve => true
104
+ end
105
+ end
106
+ end
107
+
108
+ $x.a(:class => 'toc', :id => 'env') {$x.h2 'Environment'}
109
+ $x.pre Time.now.httpdate, :class=>'stdout'
110
+
111
+ cmd "#{$ruby} -v"
112
+ cmd 'gem -v'
113
+ cmd 'gem list'
114
+ cmd 'echo $RUBYLIB | sed "s/:/\n/g"'
115
+
116
+ cmd Gorp.which_rails($rails) + ' -v'
117
+
118
+ if $rails != 'rails'
119
+ Dir.chdir($rails) do
120
+ log :cmd, 'git log -1'
121
+ $x.pre 'git log -1', :class=>'stdin'
122
+ `git log -1`.strip.split(/\n/).each do |line|
123
+ line.sub! /commit (\w{40})/,
124
+ 'commit <a href="http://github.com/rails/rails/commit/\1">\1</a>'
125
+ if $1
126
+ $x.pre(:class=>'stdout') {$x << line.chomp}
127
+ else
128
+ $x.pre line.chomp, :class=>'stdout'
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ $x.a(:class => 'toc', :id => 'todos') {$x.h2 'Todos'}
135
+ $x.ul :class => 'todos'
136
+ end
137
+ end
138
+
139
+ # output results as HTML, after inserting style and toc information
140
+ $x.target![/<style.*?>()/,1] = "\n#{$style.target!.strip.gsub(/^/,' '*6)}\n"
141
+ $x.target!.sub! /<ul class="toc"\/>/,
142
+ "<ul class=\"toc\">\n#{$toc.target!.gsub(/^/,' '*6)} </ul>"
143
+ $x.target!.sub! /<ul class="todos"\/>/,
144
+ "<ul class=\"todos\">\n#{$todos.target!.gsub(/^/,' '*6)} </ul>"
145
+ $x.target!.gsub! '<strong/>', '<strong></strong>'
146
+ $x.target!.gsub! /(<textarea[^>]+)\/>/, '\1></textarea>'
147
+ log :WRITE, "#{$output}.html"
148
+ open("#{$WORK}/#{$output}.html",'w') { |file| file.write $x.target! }
149
+
150
+ # run tests
151
+ if $checker
152
+ log :CHECK, "#{$output}.html"
153
+ Dir.chdir $BASE
154
+ STDOUT.puts
155
+ if $checker.respond_to? :call
156
+ $checker.call
157
+ elsif $checker =~ /^[-\w]+$/
158
+ require File.join($BASE,$checker)
159
+ else
160
+ require $checker
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,37 @@
1
+ # The following is code that was a part of Rails 2.3.*, but was removed in 3.0:
2
+ #
3
+ # http://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb#L217
4
+ #
5
+ # What it does is ensure that requires of things like 'active_script' are
6
+ # satisfied by the vendored rails, and not by whatever gems you have
7
+ # installed.
8
+
9
+ vendor = File.expand_path(File.dirname(File.dirname(__FILE__)))
10
+ vendor_rails = File.join(vendor, 'rails')
11
+
12
+ if File.exist? vendor_rails
13
+ require 'rubygems'
14
+
15
+ Dir.chdir(vendor_rails) do
16
+ rails_version = open('railties/lib/rails/version.rb') do |file|
17
+ eval(file.read.gsub(/\s*(module|end).*\n/, '').downcase)
18
+ end
19
+
20
+ Dir[File.join('*', 'lib')].each do |lib|
21
+ stub = lib.split(File::Separator).first
22
+ stub.sub 'railties', 'rails'
23
+
24
+ next if Gem.loaded_specs.key?(stub)
25
+
26
+ spec = Gem::Specification.new do |s|
27
+ s.name = stub
28
+ s.version = rails_version
29
+ s.loaded_from = File.join(vendor_rails, lib)
30
+ end
31
+
32
+ $LOAD_PATH.unshift spec.loaded_from
33
+ Gem.loaded_specs[stub] = spec
34
+ Gem.source_index.add_spec spec
35
+ end
36
+ end
37
+ end
data/lib/gorp/rails.rb CHANGED
@@ -22,118 +22,161 @@ else
22
22
  $rails = 'rails'
23
23
  end
24
24
 
25
- # determine which version of rails is running
26
- def which_rails rails
27
- railties = File.join(rails, 'railties', 'bin', 'rails')
28
- rails = railties if File.exists?(railties)
29
- if File.exists?(rails)
30
- firstline = open(rails) {|file| file.readlines.first}
31
- rails = 'ruby ' + rails unless firstline =~ /^#!/
25
+ # verify version of rails
26
+ if $rails =~ /^rails( |$)/
27
+ `#{$rails} -v 2>/dev/null`
28
+ else
29
+ `ruby #{$rails}/railties/bin/rails -v 2>/dev/null`
30
+ end
31
+
32
+ if $?.success?
33
+ # place a link in the $WORK directory
34
+ FileUtils.rm_f File.join($WORK, 'rails')
35
+ unless $rails =~ /^rails( |$)/
36
+ FileUtils.ln_s $rails, File.join($WORK, 'rails')
32
37
  end
33
- rails
38
+ else
39
+ puts "Install rails or specify path to git clone of rails as the " +
40
+ "first argument."
41
+ Process.exit!
34
42
  end
35
43
 
36
- # run rails as a command
37
- def rails name, app=nil
38
- Dir.chdir($WORK)
39
- FileUtils.rm_rf name
40
- log :rails, name
41
-
42
- # determine how to invoke rails
43
- rails = which_rails $rails
44
-
45
- opt = (ARGV.include?('bundle') ? ' --dev' : '')
46
- $x.pre "#{rails} #{name}#{opt}", :class=>'stdin'
47
- popen3 "#{rails} #{name}#{opt}"
48
-
49
- # canonicalize the reference to Ruby
50
- Dir["#{name}/script/**/*"].each do |script|
51
- next if File.directory? script
52
- code = open(script) {|file| file.read}
53
- code.sub! /^#!.*/, '#!/usr/bin/env ruby'
54
- open(script,'w') {|file| file.write code}
44
+ module Gorp
45
+ # determine which version of rails is running
46
+ def self.which_rails rails
47
+ railties = File.join(rails, 'railties', 'bin', 'rails')
48
+ rails = railties if File.exists?(railties)
49
+ if File.exists?(rails)
50
+ firstline = open(rails) {|file| file.readlines.first}
51
+ rails = 'ruby ' + rails unless firstline =~ /^#!/
52
+ end
53
+ rails
55
54
  end
56
55
 
57
- cmd "mkdir #{name}" unless File.exist?(name)
58
- Dir.chdir(name)
59
- FileUtils.rm_rf 'public/.htaccess'
56
+ module Commands
57
+ # run rails as a command
58
+ def rails name, app=nil
59
+ Dir.chdir($WORK)
60
+ FileUtils.rm_rf name
61
+ log :rails, name
60
62
 
61
- cmd 'rake rails:freeze:edge' if ARGV.include? 'edge'
63
+ # determine how to invoke rails
64
+ rails = Gorp.which_rails $rails
62
65
 
63
- if $rails != 'rails' and File.directory?($rails)
64
- if File.exist? 'Gemfile'
65
- if ARGV.include? 'bundle'
66
- cmd 'gem bundle'
67
- else
68
- system 'mkdir -p vendor/gems'
69
- system "ln -s #{$rails} vendor/rails"
70
- system "cp #{__FILE__.sub(/\.rb$/,'.env')} vendor/gems/environment.rb"
66
+ opt = (ARGV.include?('bundle') ? ' --dev' : '')
67
+ $x.pre "#{rails} #{name}#{opt}", :class=>'stdin'
68
+ popen3 "#{rails} #{name}#{opt}"
69
+
70
+ # canonicalize the reference to Ruby
71
+ Dir["#{name}/script/**/*"].each do |script|
72
+ next if File.directory? script
73
+ code = open(script) {|file| file.read}
74
+ code.sub! /^#!.*/, '#!/usr/bin/env ruby'
75
+ open(script,'w') {|file| file.write code}
71
76
  end
72
- else
73
- system 'mkdir -p vendor'
74
- system "ln -s #{$rails} vendor/rails"
75
- end
76
- end
77
- end
78
77
 
79
- # start/restart a rails server in a separate process
80
- def restart_server
81
- log :server, 'restart'
82
- if $server
83
- $x.h3 'Restart the server.'
84
- Process.kill "INT", $server
85
- Process.wait($server)
86
- else
87
- $x.h3 'Start the server.'
88
- end
78
+ cmd "mkdir #{name}" unless File.exist?(name)
79
+ Dir.chdir(name)
80
+ FileUtils.rm_rf 'public/.htaccess'
81
+
82
+ cmd 'rake rails:freeze:edge' if ARGV.include? 'edge'
83
+
84
+ if $rails != 'rails' and File.directory?($rails)
85
+ if File.exist? 'Gemfile'
86
+ if ARGV.include? 'bundle'
87
+ if ENV['RUBYLIB']
88
+ gem=open('Gemfile') {|file| file.read}
89
89
 
90
- $server = fork
91
- if $server
92
- # wait for server to start
93
- 60.times do
94
- sleep 0.5
95
- begin
96
- status = Net::HTTP.get_response('localhost','/',$PORT).code
97
- break if %(200 404).include? status
98
- rescue Errno::ECONNREFUSED
90
+ gem.sub! /gem "rails", :path => "(.*)"/ do
91
+ rails = "directory \"#{$1}\", :glob => '{*/,}*.gemspec'\n"
92
+
93
+ version = open("#{$1}/railties/lib/rails/version.rb") do |file|
94
+ eval(file.read.gsub(/\s*(module|end).*\n/, '').downcase)
95
+ end
96
+
97
+ ENV['RUBYLIB'].split(File::PATH_SEPARATOR).each do |lib|
98
+ rails << "directory #{lib.sub(/\/lib$/,'').inspect}\n"
99
+ end
100
+ rails + "gem \"rails\", #{version.inspect}"
101
+ end
102
+
103
+ open('Gemfile','w') {|file| file.write gem}
104
+ end
105
+
106
+ cmd 'gem bundle'
107
+ else
108
+ system 'mkdir -p vendor/gems'
109
+ system "ln -s #{$rails} vendor/rails"
110
+ system "cp #{__FILE__.sub(/\.rb$/,'.env')} " +
111
+ "vendor/gems/environment.rb"
112
+ end
113
+ else
114
+ system 'mkdir -p vendor'
115
+ system "ln -s #{$rails} vendor/rails"
116
+ end
99
117
  end
100
118
  end
101
- else
102
- #
103
- # For unknown reason, when run as CGI, the below produces:
104
- # undefined method `chomp' for nil:NilClass (NoMethodError)
105
- # from rails/actionpack/lib/action_dispatch/middleware/static.rb:13
106
- # path = env['PATH_INFO'].chomp('/')
107
- #
108
- unless ENV['GATEWAY_INTERFACE'].to_s =~ /CGI/
109
- STDOUT.reopen '/dev/null', 'a'
110
- exec "#{$ruby} script/server --port #{$PORT}"
111
- end
112
119
 
113
- # alternatives to the above, with backtrace
114
- begin
115
- if File.exist?('config.ru')
116
- require 'rack'
117
- server = Rack::Builder.new {eval(open('config.ru') {|file| file.read})}
118
- Rack::Handler::WEBrick.run(server, :Port => $PORT)
120
+ # start/restart a rails server in a separate process
121
+ def restart_server
122
+ log :server, 'restart'
123
+ if $server
124
+ $x.h3 'Restart the server.'
125
+ Process.kill "INT", $server
126
+ Process.wait($server)
119
127
  else
120
- ARGV.clear.unshift('--port', $PORT.to_s)
128
+ $x.h3 'Start the server.'
129
+ end
121
130
 
122
- # start server, redirecting stdout to a string
123
- $stdout = StringIO.open('','w')
124
- require './config/boot'
125
- if Rails::VERSION::MAJOR == 2
126
- require 'commands/server'
127
- else
128
- require 'rails/commands/server'
129
- Rails::Server.start
130
- end
131
+ $server = fork
132
+ if $server
133
+ # wait for server to start
134
+ 60.times do
135
+ sleep 0.5
136
+ begin
137
+ status = Net::HTTP.get_response('localhost','/',$PORT).code
138
+ break if %(200 404).include? status
139
+ rescue Errno::ECONNREFUSED
140
+ end
141
+ end
142
+ else
143
+ #
144
+ # For unknown reason, when run as CGI, the below produces:
145
+ # undefined method `chomp' for nil:NilClass (NoMethodError)
146
+ # from rails/actionpack/lib/action_dispatch/middleware/static.rb:13
147
+ # path = env['PATH_INFO'].chomp('/')
148
+ #
149
+ unless ENV['GATEWAY_INTERFACE'].to_s =~ /CGI/
150
+ STDOUT.reopen '/dev/null', 'a'
151
+ exec "#{$ruby} script/server --port #{$PORT}"
152
+ end
153
+
154
+ # alternatives to the above, with backtrace
155
+ begin
156
+ if File.exist?('config.ru')
157
+ require 'rack'
158
+ server = Rack::Builder.new {eval(open('config.ru') {|fh| fh.read})}
159
+ Rack::Handler::WEBrick.run(server, :Port => $PORT)
160
+ else
161
+ ARGV.clear.unshift('--port', $PORT.to_s)
162
+
163
+ # start server, redirecting stdout to a string
164
+ $stdout = StringIO.open('','w')
165
+ require './config/boot'
166
+ if Rails::VERSION::MAJOR == 2
167
+ require 'commands/server'
168
+ else
169
+ require 'rails/commands/server'
170
+ Rails::Server.start
171
+ end
172
+ end
173
+ rescue
174
+ STDERR.puts $!
175
+ $!.backtrace.each {|method| STDERR.puts "\tfrom " + method}
176
+ ensure
177
+ Process.exit!
178
+ end
131
179
  end
132
- rescue
133
- STDERR.puts $!
134
- $!.backtrace.each {|method| STDERR.puts "\tfrom " + method}
135
- ensure
136
- Process.exit!
137
180
  end
138
181
  end
139
182
  end
data/lib/gorp/test.rb CHANGED
@@ -2,18 +2,18 @@ require 'test/unit'
2
2
  require 'builder'
3
3
  require 'gorp/env'
4
4
 
5
- $:.unshift "#{$WORK}/depot/vendor/rails/activesupport/lib"
5
+ $:.unshift "#{$WORK}/rails/activesupport/lib"
6
6
  require 'active_support'
7
7
  require 'active_support/version'
8
8
  require 'active_support/test_case'
9
9
  $:.shift
10
10
 
11
- module Book
11
+ module Gorp
12
12
  end
13
13
 
14
- class Book::TestCase < ActiveSupport::TestCase
14
+ class Gorp::TestCase < ActiveSupport::TestCase
15
15
  # just enough infrastructure to get 'assert_select' to work
16
- $:.unshift "#{$WORK}/depot/vendor/rails/actionpack/lib"
16
+ $:.unshift "#{$WORK}/rails/actionpack/lib"
17
17
  require 'action_controller'
18
18
  begin
19
19
  # Rails (2.3.3 ish)
data/lib/gorp/xml.rb ADDED
@@ -0,0 +1,96 @@
1
+ # pluggable XML parser support
2
+ begin
3
+ raise LoadError if ARGV.include? 'rexml'
4
+ require 'nokogiri'
5
+ def xhtmlparse(text)
6
+ Nokogiri::HTML(text)
7
+ end
8
+ Comment=Nokogiri::XML::Comment
9
+ rescue LoadError
10
+ require 'rexml/document'
11
+
12
+ HTML_VOIDS = %w(area base br col command embed hr img input keygen link meta
13
+ param source)
14
+
15
+ def xhtmlparse(text)
16
+ begin
17
+ require 'htmlentities'
18
+ text.gsub! '&amp;', '&amp;amp;'
19
+ text.gsub! '&lt;', '&amp;lt;'
20
+ text.gsub! '&gt;', '&amp;gt;'
21
+ text.gsub! '&apos;', '&amp;apos;'
22
+ text.gsub! '&quot;', '&amp;quot;'
23
+ text.force_encoding('utf-8') if text.respond_to? :force_encoding
24
+ text = HTMLEntities.new.decode(text)
25
+ rescue LoadError
26
+ end
27
+ doc = REXML::Document.new(text)
28
+ doc.get_elements('//*[not(* or text())]').each do |e|
29
+ e.text='' unless HTML_VOIDS.include? e.name
30
+ end
31
+ doc
32
+ end
33
+
34
+ class REXML::Element
35
+ def has_attribute? name
36
+ self.attributes.has_key? name
37
+ end
38
+
39
+ def at xpath
40
+ self.elements[xpath]
41
+ end
42
+
43
+ def search xpath
44
+ self.elements.to_a(xpath)
45
+ end
46
+
47
+ def content=(string)
48
+ self.text=string
49
+ end
50
+
51
+ def [](index)
52
+ if index.instance_of? String
53
+ self.attributes[index]
54
+ else
55
+ super(index)
56
+ end
57
+ end
58
+
59
+ def []=(index, value)
60
+ if index.instance_of? String
61
+ self.attributes[index] = value
62
+ else
63
+ super(index, value)
64
+ end
65
+ end
66
+ end
67
+
68
+ module REXML::Node
69
+ def before(node)
70
+ self.parent.insert_before(self, node)
71
+ end
72
+
73
+ def add_previous_sibling(node)
74
+ self.parent.insert_before(self, node)
75
+ end
76
+
77
+ def to_xml
78
+ self.to_s
79
+ end
80
+ end
81
+
82
+ # monkey patch for Ruby 1.8.6
83
+ doc = REXML::Document.new '<doc xmlns="ns"><item name="foo"/></doc>'
84
+ if not doc.root.elements["item[@name='foo']"]
85
+ class REXML::Element
86
+ def attribute( name, namespace=nil )
87
+ prefix = nil
88
+ prefix = namespaces.index(namespace) if namespace
89
+ prefix = nil if prefix == 'xmlns'
90
+ attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
91
+ end
92
+ end
93
+ end
94
+
95
+ Comment = REXML::Comment
96
+ end
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Gorp
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 17
4
+ MINOR = 18
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gorp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-31 00:00:00 -05:00
12
+ date: 2010-01-01 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -131,11 +131,15 @@ extensions: []
131
131
  extra_rdoc_files:
132
132
  - README
133
133
  - lib/gorp.rb
134
+ - lib/gorp/commands.rb
134
135
  - lib/gorp/edit.rb
135
136
  - lib/gorp/env.rb
136
137
  - lib/gorp/net.rb
138
+ - lib/gorp/output.rb
139
+ - lib/gorp/rails.env
137
140
  - lib/gorp/rails.rb
138
141
  - lib/gorp/test.rb
142
+ - lib/gorp/xml.rb
139
143
  - lib/version.rb
140
144
  files:
141
145
  - Manifest
@@ -143,11 +147,15 @@ files:
143
147
  - Rakefile
144
148
  - gorp.gemspec
145
149
  - lib/gorp.rb
150
+ - lib/gorp/commands.rb
146
151
  - lib/gorp/edit.rb
147
152
  - lib/gorp/env.rb
148
153
  - lib/gorp/net.rb
154
+ - lib/gorp/output.rb
155
+ - lib/gorp/rails.env
149
156
  - lib/gorp/rails.rb
150
157
  - lib/gorp/test.rb
158
+ - lib/gorp/xml.rb
151
159
  - lib/version.rb
152
160
  has_rdoc: true
153
161
  homepage: http://github.com/rubys/gorp