Skip to content

Commit

Permalink
render on the client - search controllers' views first
Browse files Browse the repository at this point in the history
  • Loading branch information
jschementi committed May 23, 2008
1 parent 0c9de8c commit a12568e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
31 changes: 3 additions & 28 deletions app/views/posts/_posts.rb
@@ -1,30 +1,5 @@
#get "posts", :format => 'ruby'
download "/posts.json" do |s, a|
@posts = JSON.new.parse(a.result)
render :partial => "posts/posts", :update => "posts"
@posts = JSON.parse(a.result)
render :partial => "posts", :update => "posts"
end

#get "posts", :format => 'ruby'
#render_posts :update => "posts"

def render_posts(options = {})
id, posts = options[:update], @posts
if @posts.empty?
output = "No posts! Add one below!"
else
output = "<table>"
output += " <tr>"
posts.first.keys.each do |key|
output += " <th>#{key}</th>"
end
output += " </tr>"
posts.each do |post|
output += " <tr>"
post.keys.each do |key|
output += " <td>#{post[key]}</td>"
end
output += " </tr>"
end
output += "</table>"
end
document.send(id)[:innerHTML] = output
end
11 changes: 10 additions & 1 deletion vendor/plugins/silverline/client/lib/application.rb
Expand Up @@ -44,7 +44,16 @@ def render(options = {})
split_url = options[:partial].split "/"
split_url[-1] = "_#{split_url[-1]}"
partial = split_url.join "/"
rhtml = ERB.new XAP.get_file_contents("views/#{partial}.html.erb")

path = params[:rb_to_run].to_s.split("/")[0..-2].join("/") unless params[:rb_to_run].nil?
filename = "#{path}/#{partial}.html.erb"
begin
XAP.get_file(filename)
rescue
filename = "views/#{partial}.html.erb"
end

rhtml = ERB.new XAP.get_file_contents(filename)
document.send(options[:update])[:innerHTML] = rhtml.result(binding)
end
end
16 changes: 6 additions & 10 deletions vendor/plugins/silverline/client/lib/helpers/json.rb
@@ -1,16 +1,12 @@
require 'strscan'

class JSON

# TODO: Use Struct when it works properly
# AST = Struct.new(:value)
class AST
def initialize(value)
@value = value
end
def value
@value
end
def self.parse(input)
JSON.new.parse(input)
end
# /endTODO

AST = Struct.new(:value)

def parse(input)
@input = StringScanner.new(input)
Expand Down
2 changes: 1 addition & 1 deletion vendor/plugins/silverline/client/lib/helpers/xap.rb
Expand Up @@ -19,7 +19,7 @@ def self.get_file(relative_path_or_uri)
get_file(Uri.new(normalize_path(relative_path_or_uri), UriKind.relative))
elsif relative_path_or_uri.class == Uri
sri = Application.get_resource_stream(relative_path_or_uri)
raise "#{relative_path_or_uri.to_string.to_s} does not exist" if sri.nil?
raise Exception.new("#{relative_path_or_uri.to_string.to_s} does not exist") if sri.nil?
sri.stream
end
end
Expand Down

0 comments on commit a12568e

Please sign in to comment.