Render descriptions as Markdown
This commit is contained in:
parent
5fa73da51a
commit
481a643748
10 changed files with 42 additions and 12 deletions
1
Gemfile
1
Gemfile
|
|
@ -12,3 +12,4 @@ gem 'bcrypt'
|
||||||
gem 'gettext'
|
gem 'gettext'
|
||||||
gem 'chartkick'
|
gem 'chartkick'
|
||||||
gem 'mail'
|
gem 'mail'
|
||||||
|
gem 'redcarpet'
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ GEM
|
||||||
rackup (2.2.1)
|
rackup (2.2.1)
|
||||||
rack (>= 3)
|
rack (>= 3)
|
||||||
rake (13.2.1)
|
rake (13.2.1)
|
||||||
|
redcarpet (3.6.1)
|
||||||
ruby2_keywords (0.0.5)
|
ruby2_keywords (0.0.5)
|
||||||
securerandom (0.4.1)
|
securerandom (0.4.1)
|
||||||
sinatra (4.1.1)
|
sinatra (4.1.1)
|
||||||
|
|
@ -92,6 +93,9 @@ GEM
|
||||||
singleton (0.3.0)
|
singleton (0.3.0)
|
||||||
sqlite3 (2.6.0)
|
sqlite3 (2.6.0)
|
||||||
mini_portile2 (~> 2.8.0)
|
mini_portile2 (~> 2.8.0)
|
||||||
|
sqlite3 (2.6.0-arm64-darwin)
|
||||||
|
sqlite3 (2.6.0-x86_64-darwin)
|
||||||
|
sqlite3 (2.6.0-x86_64-linux-gnu)
|
||||||
text (1.3.1)
|
text (1.3.1)
|
||||||
tilt (2.6.0)
|
tilt (2.6.0)
|
||||||
timeout (0.4.3)
|
timeout (0.4.3)
|
||||||
|
|
@ -114,6 +118,7 @@ DEPENDENCIES
|
||||||
puma
|
puma
|
||||||
rackup
|
rackup
|
||||||
rake
|
rake
|
||||||
|
redcarpet
|
||||||
sinatra
|
sinatra
|
||||||
sinatra-activerecord
|
sinatra-activerecord
|
||||||
sqlite3
|
sqlite3
|
||||||
|
|
|
||||||
19
vedia.rb
19
vedia.rb
|
|
@ -6,6 +6,7 @@ require 'securerandom'
|
||||||
require 'chartkick'
|
require 'chartkick'
|
||||||
require 'mail'
|
require 'mail'
|
||||||
require 'tzinfo'
|
require 'tzinfo'
|
||||||
|
require 'redcarpet'
|
||||||
|
|
||||||
include GetText
|
include GetText
|
||||||
|
|
||||||
|
|
@ -479,4 +480,22 @@ helpers do
|
||||||
def format_date_and_time(timestamp)
|
def format_date_and_time(timestamp)
|
||||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F %R')} (#{session[:timezone].gsub('_', ' ')})"
|
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F %R')} (#{session[:timezone].gsub('_', ' ')})"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def markdown(markdown)
|
||||||
|
renderer = Redcarpet::Render::HTML.new(hard_wrap: true,
|
||||||
|
filter_html: true,
|
||||||
|
no_styles: true,
|
||||||
|
safe_links_only: true)
|
||||||
|
parser = Redcarpet::Markdown.new(renderer, tables: true,
|
||||||
|
autolink: true,
|
||||||
|
strikethrough: true,
|
||||||
|
space_after_headers: true,
|
||||||
|
superscript: true,
|
||||||
|
underline: true,
|
||||||
|
highlight: true,
|
||||||
|
quote: true,
|
||||||
|
footnotes: true)
|
||||||
|
parser.render(markdown)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 80em;
|
||||||
|
height: 20em;
|
||||||
|
}
|
||||||
|
|
||||||
<% settings.values.each do |v| %>
|
<% settings.values.each do |v| %>
|
||||||
.value-<%= v[:id] %> {
|
.value-<%= v[:id] %> {
|
||||||
background: <%= v[:color] %>;
|
background: <%= v[:color] %>;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="description"><%= _("Description") %></label>
|
<label for="description"><%= _("Description") %></label>
|
||||||
<input type="text" name="description" value="<%= @vote.description %>">
|
<textarea type="text" name="description"><%= @vote.description %></textarea>
|
||||||
</p>
|
</p>
|
||||||
<button type="submit"><%= _("Save") %></button>
|
<button type="submit"><%= _("Save") %></button>
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<% @vote.candidates.each do |candidate| %>
|
<% @vote.candidates.each do |candidate| %>
|
||||||
<h3><%= candidate.name %></h3>
|
<h3><%= candidate.name %></h3>
|
||||||
<p><%= candidate.description %></p>
|
<%= markdown(candidate.description) %>
|
||||||
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>/delete" method="post">
|
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>/delete" method="post">
|
||||||
<button type="submit"><%= _("Delete") %></button>
|
<button type="submit"><%= _("Delete") %></button>
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="description"><%= _("Description") %></label>
|
<label for="description"><%= _("Description") %></label>
|
||||||
<input type="text" name="description">
|
<textarea type="text" name="description"></textarea>
|
||||||
</p>
|
</p>
|
||||||
<button type="submit"><%= _("Add candidate") %></button>
|
<button type="submit"><%= _("Add candidate") %></button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="description"><%= _("Description") %></label>
|
<label for="description"><%= _("Description") %></label>
|
||||||
<input type="text" name="description">
|
<textarea type="text" name="description"></textarea>
|
||||||
</p>
|
</p>
|
||||||
<button type="submit"><%= _("Create new vote") %></button>
|
<button type="submit"><%= _("Create new vote") %></button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ opening it.") %></p>
|
||||||
|
|
||||||
<h2><%= @vote.title %></h2>
|
<h2><%= @vote.title %></h2>
|
||||||
|
|
||||||
<p><%= @vote.description %></p>
|
<%= markdown(@vote.description) %>
|
||||||
|
|
||||||
<h2><%= _("Candidates") %></h2>
|
<h2><%= _("Candidates") %></h2>
|
||||||
|
|
||||||
<% @vote.candidates.each do |candidate| %>
|
<% @vote.candidates.each do |candidate| %>
|
||||||
<h3><%= candidate.name %></h3>
|
<h3><%= candidate.name %></h3>
|
||||||
<p><%= candidate.description %></p>
|
<%= markdown(candidate.description) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><%= @vote.description %></p>
|
<%= markdown(@vote.description) %>
|
||||||
|
|
||||||
<% unless @vote.ratings.blank? %>
|
<% unless @vote.ratings.blank? %>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<h1><%= @vote.title %> <%= _("(Draft)") %></h1>
|
<h1><%= @vote.title %> <%= _("(Draft)") %></h1>
|
||||||
|
|
||||||
<p><%= @vote.description %></p>
|
<%= markdown(@vote.description) %>
|
||||||
|
|
||||||
<h2><%= _("Organizers") %></h2>
|
<h2><%= _("Organizers") %></h2>
|
||||||
|
|
||||||
|
|
@ -14,5 +14,5 @@
|
||||||
|
|
||||||
<% @vote.candidates.each do |candidate| %>
|
<% @vote.candidates.each do |candidate| %>
|
||||||
<h3><%= candidate.name %></h3>
|
<h3><%= candidate.name %></h3>
|
||||||
<p><%= candidate.description %></p>
|
<%= markdown(candidate.description) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><%= @vote.description %></p>
|
<%= markdown(@vote.description) %>
|
||||||
|
|
||||||
<h2><%= _("Your ratings") %></h2>
|
<h2><%= _("Your ratings") %></h2>
|
||||||
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
|
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
|
||||||
<% value = rating ? rating.value : 0 %>
|
<% value = rating ? rating.value : 0 %>
|
||||||
<li>
|
<li>
|
||||||
<p><%= candidate.name %></p>
|
<p><b><%= candidate.name %></b></p>
|
||||||
<p><%= candidate.description %></p>
|
<%= markdown(candidate.description) %>
|
||||||
<ul>
|
<ul>
|
||||||
<% settings.values.reverse.each do |v| %>
|
<% settings.values.reverse.each do |v| %>
|
||||||
<li><input type="radio" name="<%= candidate.id %>" id="<%= candidate.id %>-<%= v[:id] %>" value="<%= v[:id] %>" <% if value == v[:id] %>checked<% end %>><label for="<%= candidate.id %>-<%= v[:id] %>" class="value-<%= v[:id] %>"><%= v[:label] %></label></li>
|
<li><input type="radio" name="<%= candidate.id %>" id="<%= candidate.id %>-<%= v[:id] %>" value="<%= v[:id] %>" <% if value == v[:id] %>checked<% end %>><label for="<%= candidate.id %>-<%= v[:id] %>" class="value-<%= v[:id] %>"><%= v[:label] %></label></li>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue