You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2020/06/02 11:38:47 UTC
[whimsy] branch master updated: switch to mustache
This is an automated email from the ASF dual-hosted git repository.
rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new e3590a8 switch to mustache
e3590a8 is described below
commit e3590a892d2f7e8b2c9830f8aef020b0e5eefef0
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Tue Jun 2 07:38:30 2020 -0400
switch to mustache
---
www/board/agenda/Gemfile | 1 +
www/board/agenda/main.rb | 1 +
www/board/agenda/views/actions/reminder-text.json.rb | 8 +++++---
.../agenda/views/actions/send-reminders.json.rb | 20 ++++++++++++--------
4 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/www/board/agenda/Gemfile b/www/board/agenda/Gemfile
index 4a677a7..2e71cff 100644
--- a/www/board/agenda/Gemfile
+++ b/www/board/agenda/Gemfile
@@ -21,6 +21,7 @@ gem 'listen'
gem 'activesupport'
gem 'mail'
gem 'erubis'
+gem 'mustache'
gem 'websocket-eventmachine-server'
gem 'websocket-client-simple'
diff --git a/www/board/agenda/main.rb b/www/board/agenda/main.rb
index a5eaed4..9561482 100755
--- a/www/board/agenda/main.rb
+++ b/www/board/agenda/main.rb
@@ -25,6 +25,7 @@ require 'open-uri'
require 'erubis'
require 'tzinfo'
require 'active_support/time'
+require 'mustache'
unless ENV['RACK_ENV'] == 'development'
disable :logging # suppress log of requests to stderr/error.log
diff --git a/www/board/agenda/views/actions/reminder-text.json.rb b/www/board/agenda/views/actions/reminder-text.json.rb
index b307316..7d3d4fc 100644
--- a/www/board/agenda/views/actions/reminder-text.json.rb
+++ b/www/board/agenda/views/actions/reminder-text.json.rb
@@ -3,7 +3,7 @@ require 'active_support/time'
# read template for the reminders
@reminder.untaint if @reminder =~ /^reminder\d$/
@reminder.untaint if @reminder =~ /^non-responsive$/
-template = File.read("#{FOUNDATION_BOARD}/templates/#@reminder.txt")
+template = File.read("#{FOUNDATION_BOARD}/templates/#@reminder.mustache")
# find the latest agenda
agenda = Dir["#{FOUNDATION_BOARD}/board_agenda_*.txt"].sort.last.untaint
@@ -13,7 +13,9 @@ meeting = ASF::Board.nextMeeting
dueDate = meeting - 7.days
# substitutable variables
-vars = {
+view = {
+ project: '{{{project}}}',
+ link: '{{{link}}}',
meetingDate: meeting.strftime("%a, %d %b %Y at %H:%M %Z"),
month: meeting.strftime("%B"),
year: meeting.year.to_s,
@@ -23,7 +25,7 @@ vars = {
}
# perform the substitution
-vars.each {|var, value| template.gsub! "[#{var}]", value}
+template = Mustache.render(template, view)
# extract subject
subject = template[/Subject: (.*)/, 1]
diff --git a/www/board/agenda/views/actions/send-reminders.json.rb b/www/board/agenda/views/actions/send-reminders.json.rb
index 13beab2..08fa502 100644
--- a/www/board/agenda/views/actions/send-reminders.json.rb
+++ b/www/board/agenda/views/actions/send-reminders.json.rb
@@ -31,17 +31,21 @@ Agenda.parse(@agenda, :full).each do |item|
# substitute [whoTo] values
if item['to'] == 'president'
- reminder = @message.gsub('[whoTo]', 'operations@apache.org')
+ whoTo = 'operations@apache.org'
else
- reminder = @message.gsub('[whoTo]', 'board@apache.org')
+ whoTo = 'board@apache.org'
end
- # substitute [link] values
- reminder.gsub! '[link]', item['title'].gsub(/\W/, '-')
+ # values to substitute
+ view = {
+ whoTo: whoTo,
+ link: item['title'].gsub(/\W/, '-'),
+ project: item['title']
+ }
- # substitute [project] values
- reminder.gsub! '[project]', item['title'].gsub(/\W/, '-')
- subject = @subject.gsub('[project]', item['title']).untaint
+ # apply changes to both subject and the message text itself
+ subject = Mustache.render(@subject, view)
+ message = Mustache.render(@message, view)
# cc list
cclist = []
@@ -62,7 +66,7 @@ Agenda.parse(@agenda, :full).each do |item|
cc cclist unless cclist.empty?
subject subject
- body reminder.untaint
+ body message.untaint
end
# deliver mail