Skip to content

Commit

Permalink
Synchronous downloading support
Browse files Browse the repository at this point in the history
  • Loading branch information
jschementi committed May 9, 2008
1 parent fe548d3 commit 851e7cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
15 changes: 6 additions & 9 deletions app/views/posts/_posts.rb
Expand Up @@ -3,16 +3,13 @@
class Posts < SilverlightApplication
def initialize
super
request = Net::WebClient.new
request.download_string_completed do |s,a|
@posts = JSONParser.new.parse(a.result)
_render "posts", @posts
#render :id => "posts", :view => "posts/index"
end
request.download_string_async Uri.new("http://#{params[:http_host]}/posts.json")
result = download "/posts.json"
@posts = JSONParser.new.parse(result)
render_posts :id => "posts"
end

def _render(id, posts)

def render_posts(options = {})
id, posts = options[:id], @posts
output = "<table>"
output += " <tr>"
posts.first.keys.each do |key|
Expand Down
18 changes: 18 additions & 0 deletions vendor/plugins/silverline/client/lib/downloader.rb
@@ -0,0 +1,18 @@
include System::Windows::Browser

module Downloader

def download(url, &block)
if block.nil?
request = HtmlPage.Window.CreateInstance("XMLHttpRequest".to_clr_string)
request.Invoke("open".to_clr_string, "GET".to_clr_string, url, false)
request.Invoke("send".to_clr_string, "".to_clr_string)
request.GetProperty("responseText".to_clr_string).to_s
else
request = Net::WebClient.new
request.download_string_completed(&block)
request.download_string_async Uri.new("http://#{params[:http_host]}#{url}")
end
end

end

0 comments on commit 851e7cd

Please sign in to comment.