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 'chartkick'
|
||||
gem 'mail'
|
||||
gem 'redcarpet'
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ GEM
|
|||
rackup (2.2.1)
|
||||
rack (>= 3)
|
||||
rake (13.2.1)
|
||||
redcarpet (3.6.1)
|
||||
ruby2_keywords (0.0.5)
|
||||
securerandom (0.4.1)
|
||||
sinatra (4.1.1)
|
||||
|
|
@ -92,6 +93,9 @@ GEM
|
|||
singleton (0.3.0)
|
||||
sqlite3 (2.6.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)
|
||||
tilt (2.6.0)
|
||||
timeout (0.4.3)
|
||||
|
|
@ -114,6 +118,7 @@ DEPENDENCIES
|
|||
puma
|
||||
rackup
|
||||
rake
|
||||
redcarpet
|
||||
sinatra
|
||||
sinatra-activerecord
|
||||
sqlite3
|
||||
|
|
|
|||
19
vedia.rb
19
vedia.rb
|
|
@ -6,6 +6,7 @@ require 'securerandom'
|
|||
require 'chartkick'
|
||||
require 'mail'
|
||||
require 'tzinfo'
|
||||
require 'redcarpet'
|
||||
|
||||
include GetText
|
||||
|
||||
|
|
@ -479,4 +480,22 @@ helpers do
|
|||
def format_date_and_time(timestamp)
|
||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F %R')} (#{session[:timezone].gsub('_', ' ')})"
|
||||
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
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
color: red;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 80em;
|
||||
height: 20em;
|
||||
}
|
||||
|
||||
<% settings.values.each do |v| %>
|
||||
.value-<%= v[:id] %> {
|
||||
background: <%= v[:color] %>;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
</p>
|
||||
<p>
|
||||
<label for="description"><%= _("Description") %></label>
|
||||
<input type="text" name="description" value="<%= @vote.description %>">
|
||||
<textarea type="text" name="description"><%= @vote.description %></textarea>
|
||||
</p>
|
||||
<button type="submit"><%= _("Save") %></button>
|
||||
</form>
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<% @vote.candidates.each do |candidate| %>
|
||||
<h3><%= candidate.name %></h3>
|
||||
<p><%= candidate.description %></p>
|
||||
<%= markdown(candidate.description) %>
|
||||
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>/delete" method="post">
|
||||
<button type="submit"><%= _("Delete") %></button>
|
||||
</form>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
</p>
|
||||
<p>
|
||||
<label for="description"><%= _("Description") %></label>
|
||||
<input type="text" name="description">
|
||||
<textarea type="text" name="description"></textarea>
|
||||
</p>
|
||||
<button type="submit"><%= _("Add candidate") %></button>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
</p>
|
||||
<p>
|
||||
<label for="description"><%= _("Description") %></label>
|
||||
<input type="text" name="description">
|
||||
<textarea type="text" name="description"></textarea>
|
||||
</p>
|
||||
<button type="submit"><%= _("Create new vote") %></button>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ opening it.") %></p>
|
|||
|
||||
<h2><%= @vote.title %></h2>
|
||||
|
||||
<p><%= @vote.description %></p>
|
||||
<%= markdown(@vote.description) %>
|
||||
|
||||
<h2><%= _("Candidates") %></h2>
|
||||
|
||||
<% @vote.candidates.each do |candidate| %>
|
||||
<h3><%= candidate.name %></h3>
|
||||
<p><%= candidate.description %></p>
|
||||
<%= markdown(candidate.description) %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
||||
<% end %>
|
||||
|
||||
<p><%= @vote.description %></p>
|
||||
<%= markdown(@vote.description) %>
|
||||
|
||||
<% unless @vote.ratings.blank? %>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<h1><%= @vote.title %> <%= _("(Draft)") %></h1>
|
||||
|
||||
<p><%= @vote.description %></p>
|
||||
<%= markdown(@vote.description) %>
|
||||
|
||||
<h2><%= _("Organizers") %></h2>
|
||||
|
||||
|
|
@ -14,5 +14,5 @@
|
|||
|
||||
<% @vote.candidates.each do |candidate| %>
|
||||
<h3><%= candidate.name %></h3>
|
||||
<p><%= candidate.description %></p>
|
||||
<%= markdown(candidate.description) %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
||||
<% end %>
|
||||
|
||||
<p><%= @vote.description %></p>
|
||||
<%= markdown(@vote.description) %>
|
||||
|
||||
<h2><%= _("Your ratings") %></h2>
|
||||
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
|
||||
<% value = rating ? rating.value : 0 %>
|
||||
<li>
|
||||
<p><%= candidate.name %></p>
|
||||
<p><%= candidate.description %></p>
|
||||
<p><b><%= candidate.name %></b></p>
|
||||
<%= markdown(candidate.description) %>
|
||||
<ul>
|
||||
<% 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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue