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] [4/50] Commit 3fa92b2: brute force an item page
Date Fri, 22 Jan 2016 02:40:52 GMT
Commit 3fa92b2aef17a1a5a70f89525c3ba5f801b73537:
    brute force an item page


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

------------------------------------------------------------
main.rb                                                      | + 
spec/item_spec.rb                                            | ++++++++++++++ 
views/agenda.js.rb                                           | +++++++++ -
views/main.html.rb                                           | + -
views/main.js.rb                                             | +++++++ ---
------------------------------------------------------------
75 changes: 61 additions, 14 deletions.
------------------------------------------------------------


diff --git a/main.rb b/main.rb
index b133516..2597c32 100755
--- a/main.rb
+++ b/main.rb
@@ -31,6 +31,7 @@
   Dir.chdir(FOUNDATION_BOARD) {@agendas = Dir['board_agenda_*.txt'].sort}
   Dir.chdir(FOUNDATION_BOARD) {@drafts = Dir['board_minutes_*.txt'].sort}
   @base = env['PATH_INFO'].chomp(path).untaint
+  @path = path
   @agenda = "board_agenda_#{date.gsub('-','_')}.txt"
 
   if AGENDA_CACHE[@agenda][:mtime] == 0
diff --git a/spec/item_spec.rb b/spec/item_spec.rb
new file mode 100644
index 0000000..be7a89b
--- /dev/null
+++ b/spec/item_spec.rb
@@ -0,0 +1,14 @@
+require_relative 'spec_helper'
+
+feature 'item' do
+  it "should show the Secretary report" do
+    visit '/2014-02-19/Secretary'
+    expect(page).to have_selector '.navbar-fixed-top .navbar-brand', 
+      text: 'Secretary'
+    expect(page).to have_selector 'pre', text: /December doldrums/
+    expect(page).to have_selector '.backlink[href="Treasurer"]', 
+     text: 'Treasurer'
+    expect(page).to have_selector '.nextlink[href="Executive-Vice-President"]', 
+     text: 'Executive Vice President'
+  end
+end
diff --git a/views/agenda.js.rb b/views/agenda.js.rb
index e1df46a..bcbbbc5 100644
--- a/views/agenda.js.rb
+++ b/views/agenda.js.rb
@@ -3,12 +3,25 @@ class Agenda
 
   def self.load(list)
     @@index.clear()
+    prev = nil
     list.each do |item|
-      @@index << Agenda.new(item)
+      item = Agenda.new(item)
+      item.prev = prev
+      prev.next = item if prev
+      prev = item
+      @@index << item
     end
     return @@index
   end
 
+  def self.find(path)
+    result = nil
+    @@index.each do |item|
+      result = item if item.href == path
+    end
+    return result
+  end
+
   def initialize(entry)
     for name in entry
       self["_#{name}"] = entry[name]
@@ -21,6 +34,10 @@ def href
     @title.gsub(/[^a-zA-Z0-9]+/, '-')
   end
 
+  def text
+    @text || @report
+  end
+
   def color
     if not @title
       'blank'
diff --git a/views/main.html.rb b/views/main.html.rb
index 78f7b5d..21fec60 100755
--- a/views/main.html.rb
+++ b/views/main.html.rb
@@ -13,6 +13,6 @@
 
   _script src: '../app.js'
   _.render '#main' do
-    _Main parsed: @parsed, agenda: @agenda, agendas: @agendas
+    _Main parsed: @parsed, agenda: @agenda, agendas: @agendas, path: @path
   end
 end
diff --git a/views/main.js.rb b/views/main.js.rb
index 7a94785..862c77b 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -1,26 +1,36 @@
 class Main < React
   def initialize
     @agenda = Agenda.load(@@parsed)
-    @date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
     @next = {text: 'Help', link: 'help'}
     @prev = {text: 'Help', link: 'help'}
 
-    @@agendas.each do |agenda|
-      date = agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
+    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 (@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}/"}
+        if date < @date and (@prev.text == 'Help' or date > @prev.text)
+          @prev = {text: date, link: "../#{date}/"}
+        end
       end
     end
   end
 
   def render
-    _header.navbar.navbar_fixed_top.blank do
-      _div.navbar_brand @date
+    _header.navbar.navbar_fixed_top class: @color do
+      _div.navbar_brand @title
       _ul.nav.nav_pills.navbar_right do
         _li.dropdown do
           _a.dropdown_toggle.nav! 'navigation'
@@ -29,10 +39,14 @@ def render
     end
 
     _main do
-      React.createElement(Index, agenda: @agenda)
+      if @item
+        _pre @item.text
+      else
+        React.createElement(Index, agenda: @agenda)
+      end
     end
 
-    _footer.navbar.navbar_fixed_bottom.blank do
+    _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
     end
@@ -47,6 +61,7 @@ def window.onresize()
       main.style.marginBottom = "#{footer.clientHeight}px"
     end
 
+    document.getElementsByTagName('title')[0].textContent = @title
     window.onresize()
   end
 

Mime
View raw message