You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2015/12/13 16:14:54 UTC

[whimsy.git] [20/37] Commit 255300d: move parts page to React.js

Commit 255300d3d5640d36ee73dab5cd175c5db22eda47:
    move parts page to React.js


Branch: refs/heads/secmail
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>

------------------------------------------------------------
Gemfile                                                      | ++ 
Rakefile                                                     | + --
server.rb                                                    | +++ 
views/app.js.rb                                              | + 
views/parts.html.rb                                          | +++++ ------
views/parts.js.rb                                            | +++++++++ 
------------------------------------------------------------
29 changes: 21 additions, 8 deletions.
------------------------------------------------------------


diff --git a/Gemfile b/Gemfile
index 1c7eef6..cff64ab 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,6 +7,8 @@ gem 'whimsy-asf'
 gem 'sinatra'
 gem 'sanitize'
 gem 'wunderbar', '~> 1.0.9'
+gem 'ruby2js'
+gem 'execjs'
 
 group :demo do
   gem 'listen'
diff --git a/Rakefile b/Rakefile
index 6a8a23b..b5699df 100644
--- a/Rakefile
+++ b/Rakefile
@@ -27,8 +27,7 @@ end
 
 desc 'WebServer that provides an interface to explore emails'
 task :server => :bundle do
-  require 'whimsy/asf/config'
-  ENV['RACK_ENV']='development'
+  ENV['RACK_ENV']='production'
   require 'wunderbar/listen'
 end
 
diff --git a/server.rb b/server.rb
index 0210c54..16a1054 100644
--- a/server.rb
+++ b/server.rb
@@ -4,7 +4,9 @@
 
 require 'wunderbar/sinatra'
 require 'wunderbar/bootstrap'
+require 'wunderbar/react'
 require 'ruby2js/filter/functions'
+require 'ruby2js/filter/require'
 require 'sanitize'
 
 require_relative 'mailbox'
@@ -43,6 +45,7 @@
 get %r{^/(\d+)/(\w+)/_index_$} do |month, hash|
   @message = Mailbox.new(month).headers[hash]
   pass unless @message
+  @attachments = @message[:attachments]
   _html :parts
 end
 
diff --git a/views/app.js.rb b/views/app.js.rb
new file mode 100644
index 0000000..5d99b56
--- /dev/null
+++ b/views/app.js.rb
@@ -0,0 +1 @@
+require_relative 'parts'
diff --git a/views/parts.html.rb b/views/parts.html.rb
index 4238da4..84827b3 100644
--- a/views/parts.html.rb
+++ b/views/parts.html.rb
@@ -8,11 +8,10 @@
     _li! {_a 'headers', href: '_headers_', target: 'content'}
   end
 
-  _ul_ do
-    @message[:attachments].each do |attachment|
-      _li do
-        _a attachment[:name], href: attachment[:name], target: 'content'
-      end
-    end
+  _div.attachments!
+
+  _script src: '../../app.js'
+  _.render '#attachments' do
+    _Parts attachments: @attachments
   end
 end
diff --git a/views/parts.js.rb b/views/parts.js.rb
new file mode 100644
index 0000000..37f3822
--- /dev/null
+++ b/views/parts.js.rb
@@ -0,0 +1,9 @@
+class Parts < React
+  def render
+    _ul @@attachments do |attachment|
+      _li do
+        _a attachment.name, href: attachment.name, target: 'content'
+      end
+    end
+  end
+end