mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00

Changes you will need to make: * In your environment.rb, you will need to update references to a few files per environment.rb.tmpl * In your environment.rb, you will need to specify the local time zone of the computer that is running your Tracks install. Other notes on my changes: * Modified our code to take advantage of Rails 2.1's slick time zone support. * Upgraded will_paginate for compatibility * Hacked the Selenium on Rails plugin, which has not been updated in some time and does not support Rails 2.1 * Verified that all tests pass on my machine, including Selenium tests -- I'd like confirmation from others, too.
85 lines
No EOL
2.4 KiB
Ruby
85 lines
No EOL
2.4 KiB
Ruby
class SeleniumOnRails::Selenese
|
|
end
|
|
ActionView::Template.register_template_handler 'sel', SeleniumOnRails::Selenese
|
|
|
|
|
|
class SeleniumOnRails::Selenese
|
|
def initialize view
|
|
@view = view
|
|
end
|
|
|
|
def render template
|
|
name = @view.assigns['page_title']
|
|
lines = template.strip.split "\n"
|
|
html = ''
|
|
html << extract_comments(lines)
|
|
html << extract_commands(lines, name)
|
|
html << extract_comments(lines)
|
|
raise 'You cannot have comments in the middle of commands!' if next_line lines, :any
|
|
html
|
|
end
|
|
|
|
def compilable?
|
|
false
|
|
end
|
|
|
|
private
|
|
def next_line lines, expects
|
|
while lines.any?
|
|
l = lines.shift.strip
|
|
next if (l.empty? and expects != :comment)
|
|
comment = (l =~ /^\|.*\|$/).nil?
|
|
if (comment and expects == :command) or (!comment and expects == :comment)
|
|
lines.unshift l
|
|
return nil
|
|
end
|
|
return l
|
|
end
|
|
end
|
|
|
|
def extract_comments lines
|
|
comments = ''
|
|
while (line = next_line lines, :comment)
|
|
comments << line + "\n"
|
|
end
|
|
if defined? RedCloth
|
|
comments = RedCloth.new(comments).to_html
|
|
end
|
|
comments += "\n" unless comments.empty?
|
|
comments
|
|
end
|
|
|
|
def extract_commands lines, name
|
|
html = "<table>\n<tr><th colspan=\"3\">#{name}</th></tr>\n"
|
|
while (line = next_line lines, :command)
|
|
line = line[1..-2] #remove starting and ending |
|
|
cells = line.split '|'
|
|
if cells.first == 'includePartial'
|
|
html << include_partial(cells[1..-1])
|
|
next
|
|
end
|
|
raise 'There might only be a maximum of three cells!' if cells.length > 3
|
|
html << '<tr>'
|
|
(1..3).each do
|
|
cell = cells.shift
|
|
cell = (cell ? CGI.escapeHTML(cell.strip) : ' ')
|
|
html << "<td>#{cell}</td>"
|
|
end
|
|
html << "</tr>\n"
|
|
end
|
|
html << "</table>\n"
|
|
end
|
|
|
|
def include_partial params
|
|
partial = params.shift
|
|
locals = {}
|
|
params.each do |assignment|
|
|
next if assignment.empty?
|
|
_, var, value = assignment.split(/^([a-z_][a-zA-Z0-9_]*)\s*=\s*(.*)$/)
|
|
raise "Invalid format '#{assignment}'. Should be '|includePartial|partial|var1=value|var2=value|." unless var
|
|
locals[var.to_sym] = value or ''
|
|
end
|
|
@view.render :partial => partial, :locals => locals
|
|
end
|
|
|
|
end |