Skip to content

Commit

Permalink
Merge pull request #234 from aackerman/aackerman/summary-edit
Browse files Browse the repository at this point in the history
Create models, controller, and views to support adding editable block…
  • Loading branch information
jennapederson committed Aug 29, 2020
2 parents 48b14c0 + 13fa61e commit d58ece5
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 42 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ before_script:
- psql -c 'create database travis_ci_test;' -U postgres
- cp config/database.yml.travis config/database.yml
- bundle install
- bundle exec rake db:migrate RAILS_ENV=test

env:
global:
Expand Down
23 changes: 23 additions & 0 deletions src/app/controllers/admin/markdown_contents_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Admin::MarkdownContentsController < Admin::AdminController
load_resource
respond_to :html

def create
@markdown_content.attributes = markdown_content_params
@markdown_content.save!
redirect_to admin_markdown_content_path(@markdown_content)
end

def update
@markdown_content.update(markdown_content_params)
redirect_to admin_markdown_content_path(@markdown_content)
end

def index; end
def show; end
def edit; end

def markdown_content_params
params.require(:markdown_content).permit(:name, :slug, :markdown)
end
end
17 changes: 12 additions & 5 deletions src/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ def edit(obj, &blk)
end
end

def markdown(str)
def markdown(str, trusted: false)
return '' unless str

@markdown ||= Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new,
autolink: true,
space_after_headers: true)
sanitize_html(close_tags(@markdown.render(str))).html_safe
Redcarpet::Render::HTML.new,
autolink: true,
space_after_headers: true
)

if trusted
sanitize(close_tags(@markdown.render(str))).html_safe
else
sanitize_html(close_tags(@markdown.render(str))).html_safe
end
end

def close_tags(html)
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class Ability
include CanCan::Ability

def initialize(user)
can :index, [Event, Participant, Timeslot]
can :index, [Event, Participant, Timeslot, MarkdownContent]
end
end
3 changes: 3 additions & 0 deletions src/app/models/markdown_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class MarkdownContent < ActiveRecord::Base
validates :slug, presence: true
end
15 changes: 15 additions & 0 deletions src/app/views/admin/markdown_contents/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= semantic_form_for([:admin, @markdown_content]) do |f| %>
<div>
<%= f.semantic_errors %>
</div>
<div>
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :slug %>
<%= f.input :markdown, as: :text, input_html: { class: 'full-width' } %>
<% end %>
</div>
<div>
<%= f.actions %>
</div>
<% end %>
7 changes: 7 additions & 0 deletions src/app/views/admin/markdown_contents/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><%= link_to 'Create new markdown content', new_admin_markdown_content_path %></p>

<% @markdown_contents.map do |mc| %>
<p>Slug <%= mc.slug %></p>
<%= link_to 'View', [:admin, mc] %>
<%= link_to 'Edit', [:edit, :admin, mc] %>
<% end %>
15 changes: 15 additions & 0 deletions src/app/views/admin/markdown_contents/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= semantic_form_for([:admin, @markdown_content]) do |f| %>
<div>
<%= f.semantic_errors %>
</div>
<div>
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :slug %>
<%= f.input :markdown, as: :text, input_html: { class: 'full-width' } %>
<% end %>
</div>
<div>
<%= f.actions %>
</div>
<% end %>
12 changes: 12 additions & 0 deletions src/app/views/admin/markdown_contents/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h2>Name</h1>
<p><%= @markdown_content.name %></p>

<h2>Slug</h2>
<p><%= @markdown_content.slug %></p>

<h2>Rendered Markdown</h2>
<div>
<%= markdown @markdown_content.markdown, trusted: true =%>
</div>

<%= link_to 'Edit', [:edit, :admin, @markdown_content] %>
1 change: 1 addition & 0 deletions src/app/views/admin/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<li><%= link_to 'Configuration', admin_config_path %></li>
<li><%= link_to 'Events', admin_events_path %></li>
<li><%= link_to 'Sessions', admin_sessions_path %></li>
<li><%= link_to 'Markdown', admin_markdown_contents_path %></li>
</ul>
34 changes: 1 addition & 33 deletions src/app/views/events/_aside.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,6 @@
<p><%= add_sessions_button %></p>

<div class="sidebar-box">
<h3>How long are sessions?</h3>
<p>Sessions can be at most <strong>50 minutes</strong> long. If you need extra
time, there will be empty small breakout rooms available.</p>

<h3>What kind of sessions are OK?</h3>
<p>If you're interested in a topic, chances are others are
too. Types of sessions could
include <strong>presentations</strong> (on a programming
language, cool project, marketing, music, or anything
else), <strong>panel
discussions</strong>, <strong>hackfests</strong>,
or <strong>meetups</strong>.</p>

<p><strong>What's not OK?</strong> <%= t('conference') %> is not a forum for advertisements or snake oil sales.</p>

<p>If you've got an idea for a session and you want to run it by us, email casey@minnestar.org or support@minnestar.org.</p>

<h3>No Spectators, Only Participants</h3>
<p>The first rule of <%= t('conference') %> is <strong>No Spectators, Only
Participants</strong>. We encourage everyone to participate in
the event by presenting, hosting a discussion, or even just
participating in discussions and Q&amp;A. Come ready to engage
with your peers, share something you know, and learn something
new!</p>

<h3>Sessions from Past Events</h3>
<p>
All demos and sessions from past minne&#x2731; events have
been imported into our <a href="http://wiki.minnestar.org/">wiki</a>. Take a stroll down
memory lane with <a href="http://wiki.minnestar.org/wiki/MinneBar_1">Minnebar 1</a>...
and everything in between.
</p>
<%= markdown MarkdownContent.find_by_slug('homepage-summary').markdown, trusted: true %>
</div>
</div>

1 change: 1 addition & 0 deletions src/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
namespace :admin do
resource :config, only: [:show, :create]
resources :sessions
resources :markdown_contents, path: 'markdown-contents'
resources :events do
resources :timeslots, only: [:index, :new, :create]
resources :rooms, only: [:new, :create]
Expand Down
11 changes: 11 additions & 0 deletions src/db/migrate/20190713124823_create_markdown_contents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateMarkdownContents < ActiveRecord::Migration[5.2]
def change
create_table :markdown_contents do |t|
t.string :name, null: false
t.string :slug, null: false, index: { unique: true }
t.string :markdown, null: false

t.timestamps
end
end
end
35 changes: 35 additions & 0 deletions src/db/migrate/20190713173911_create_homepage_summary_markdown.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class CreateHomepageSummaryMarkdown < ActiveRecord::Migration[5.2]
def up
mc = MarkdownContent.new({
name: 'Homepage Summary',
slug: 'homepage-summary',
markdown: <<~EOF
### How long are sessions?
Sessions can be at most **50 minutes** long. If you need extra time, there will be empty small breakout rooms available.
### What kind of sessions are OK?
If you're interested in a topic, chances are others are too. Types of sessions could include **presentations** (on a programming language, cool project, marketing, music, or anything else), **panel discussions**, **hackfests**, or **meetups**.
**What's not OK?** Minnebar is not a forum for advertisements or snake oil sales.
If you've got an idea for a session and you want to run it by us, email casey@minnestar.org or support@minnestar.org.
### No Spectators, Only Participants
The first rule of Minnebar is **No Spectators, Only Participants**. We encourage everyone to participate in the event by presenting, hosting a discussion, or even just participating in discussions and Q&A. Come ready to engage with your peers, share something you know, and learn something new!
### Sessions from Past Events
All demos and sessions from past minne✱ events have been imported into our [wiki](http://wiki.minnestar.org/). Take a stroll down memory lane with [Minnebar 1](http://wiki.minnestar.org/wiki/MinneBar_1)... and everything in between.
EOF
})
mc.save!
end

def down
mc = MarkdownContent.find_by_slug('homepage-summary')
mc.destroy!
end
end
11 changes: 10 additions & 1 deletion src/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2017_03_24_203935) do
ActiveRecord::Schema.define(version: 2019_07_13_173911) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -47,6 +47,15 @@
t.string "name", limit: 255
end

create_table "markdown_contents", force: :cascade do |t|
t.string "name", null: false
t.string "slug", null: false
t.string "markdown", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["slug"], name: "index_markdown_contents_on_slug", unique: true
end

create_table "participants", id: :serial, force: :cascade do |t|
t.string "name", limit: 255
t.string "email", limit: 255
Expand Down
4 changes: 2 additions & 2 deletions src/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
end

config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.clean_with(:truncation, { except: %w[markdown_contents] })
Category.find_or_create_defaults
end

Expand All @@ -59,7 +59,7 @@
end

config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation, {:except => %w[categories]}
DatabaseCleaner.strategy = :truncation, { except: %w[categories markdown_contents] }
end

config.before(:each) do
Expand Down

0 comments on commit d58ece5

Please sign in to comment.