whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [5/50] Commit dac2c11: refactor
Date Fri, 22 Jan 2016 02:40:52 GMT
Commit dac2c114a7cf843902f0d3f2689259fe64bbb84e:
    refactor


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

------------------------------------------------------------
views/agenda.js.rb                                           | ++++++++++++ 
views/app.js.rb                                              | + 
views/index.js.rb                                            | + -
views/main.js.rb                                             | +++++ --------
views/report.js.rb                                           | +++++ 
------------------------------------------------------------
105 changes: 72 additions, 33 deletions.
------------------------------------------------------------


diff --git a/views/agenda.js.rb b/views/agenda.js.rb
index bcbbbc5..73ddfd0 100644
--- a/views/agenda.js.rb
+++ b/views/agenda.js.rb
@@ -14,6 +14,10 @@ def self.load(list)
     return @@index
   end
 
+  def self.index
+    @@index
+  end
+
   def self.find(path)
     result = nil
     @@index.each do |item|
@@ -38,6 +42,50 @@ def text
     @text || @report
   end
 
+  def self.view
+    Index
+  end
+
+  def self.color
+    'blank'
+  end
+
+  def self.title
+    @@date
+  end
+
+  def self.prev
+    result = {title: 'Help', href: 'help'}
+
+    @@agendas.each do |agenda|
+      date = agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
+
+      if date < @@date and (result.title == 'Help' or date > result.title)
+	result = {title: date, link: "../#{date}/"}
+      end
+    end
+
+    result
+  end
+
+  def self.next
+    result = {title: 'Help', href: 'help'}
+
+    @@agendas.each do |agenda|
+      date = agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
+
+      if date > @@date and (result.title == 'Help' or date < result.title)
+	result = {title: date, link: "../#{date}/"}
+      end
+    end
+
+    result
+  end
+
+  def view
+    Report
+  end
+
   def color
     if not @title
       'blank'
diff --git a/views/app.js.rb b/views/app.js.rb
index 46b5f97..e4b3ec5 100644
--- a/views/app.js.rb
+++ b/views/app.js.rb
@@ -1,4 +1,5 @@
 require_relative 'main'
 require_relative 'index'
+require_relative 'report'
 
 require_relative 'agenda'
diff --git a/views/index.js.rb b/views/index.js.rb
index b32b407..55f962b 100644
--- a/views/index.js.rb
+++ b/views/index.js.rb
@@ -12,7 +12,7 @@ def render
 	_th 'Shepherd'
       end
 
-      _tbody @@agenda do |row|
+      _tbody Agenda.index do |row|
 	_tr class: row.color do
 	  _td row.attach
 	  _td do
diff --git a/views/main.js.rb b/views/main.js.rb
index 862c77b..dcca558 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -1,36 +1,19 @@
 class Main < React
   def initialize
-    @agenda = Agenda.load(@@parsed)
-    @next = {text: 'Help', link: 'help'}
-    @prev = {text: 'Help', link: 'help'}
+    Agenda.load(@@parsed)
 
     if @@path
       @item = Agenda.find(@@path)
-      @prev = {text: @item.prev.title, link: @item.prev.href} if @item.prev
-      @next = {text: @item.next.title, link: @item.next.href} if @item.next
-      @color = @item.color
-      @title = @item.title
     else
-      @date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
-      @title = @date
-      @color = 'blank'
-      @@agendas.each do |agenda|
-        date = agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
-
-        if date > @date and (@next.text == 'Help' or date < @next.text)
-          @next = {text: date, link: "../#{date}/"}
-        end
-      
-        if date < @date and (@prev.text == 'Help' or date > @prev.text)
-          @prev = {text: date, link: "../#{date}/"}
-        end
-      end
+      Agenda._date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
+      Agenda._agendas = @@agendas
+      @item = Agenda
     end
   end
 
   def render
-    _header.navbar.navbar_fixed_top class: @color do
-      _div.navbar_brand @title
+    _header.navbar.navbar_fixed_top class: @item.color do
+      _div.navbar_brand @item.title
       _ul.nav.nav_pills.navbar_right do
         _li.dropdown do
           _a.dropdown_toggle.nav! 'navigation'
@@ -39,16 +22,18 @@ def render
     end
 
     _main do
-      if @item
-        _pre @item.text
-      else
-        React.createElement(Index, agenda: @agenda)
-      end
+      React.createElement(@item.view, data: @item)
     end
 
-    _footer.navbar.navbar_fixed_bottom class: @color do
-      _a.backlink.navbar_brand @prev.text, rel: 'prev', href: @prev.link
-      _a.nextlink.navbar_brand @next.text, rel: 'next', href: @next.link
+    _footer.navbar.navbar_fixed_bottom class: @item.color do
+      if @item.prev
+        _a.backlink.navbar_brand @item.prev.title, rel: 'prev', 
+         href: @item.prev.href
+      end
+      if @item.next
+        _a.nextlink.navbar_brand @item.next.title, rel: 'next', 
+         href: @item.next.href
+      end
     end
   end
 
@@ -61,7 +46,7 @@ def window.onresize()
       main.style.marginBottom = "#{footer.clientHeight}px"
     end
 
-    document.getElementsByTagName('title')[0].textContent = @title
+    document.getElementsByTagName('title')[0].textContent = @item.title
     window.onresize()
   end
 
diff --git a/views/report.js.rb b/views/report.js.rb
new file mode 100644
index 0000000..3570e2e
--- /dev/null
+++ b/views/report.js.rb
@@ -0,0 +1,5 @@
+class Report < React
+  def render
+    _pre @@data.text
+  end
+end

Mime
View raw message