Skip to content

Commit

Permalink
There shall be a blog!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Schubert committed Aug 26, 2013
1 parent 67d443f commit 873ecc4
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'

gem 'redcarpet', '~> 3.0.0'

group :development, :test do
gem 'rspec-rails', '~> 2.14.0'
gem 'capybara', '~> 2.1.0'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ GEM
thor (>= 0.18.1, < 2.0)
raindrops (0.11.0)
rake (10.1.0)
redcarpet (3.0.0)
remotipart (1.2.1)
rspec (2.14.1)
rspec-core (~> 2.14.0)
Expand Down Expand Up @@ -195,6 +196,7 @@ DEPENDENCIES
rails (= 4.0.0)
rails_admin
rails_locale_detection (~> 2.0.0.pre)
redcarpet (~> 3.0.0)
rspec-instafail (~> 0.2.4)
rspec-rails (~> 2.14.0)
sass-rails (~> 4.0.0)
Expand Down
27 changes: 27 additions & 0 deletions app/assets/stylesheets/blog.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.blogcontent {
width: 75%;
margin: 50px auto 0;

h1, h2, h3 {
text-align: left;
color: rgb(64, 64, 64);
}

h1 {
font-size: 24px;

small {
display: block;
float: right;
margin-top: 10px;
}
}

h2 {
margin: 35px 0 15px 0;
}

li {
color: rgb(64, 64, 64);
}
}
21 changes: 6 additions & 15 deletions app/controllers/blog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
class BlogController < ApplicationController
respond_to :html
respond_to :html, :except => [:feed]
respond_to :atom, :only => [:feed]

def show
@blogpost = Blogpost.find_by_id params[:id]
end

def index
@blogposts = Blogpost.where(:published => true).order(:created_at => :desc)
end

def create
Blog.create person_params
end

def update
blog = Blog.find params[:id]
blog.update_attributes! person_params
redirect_to blog
end

private

def blog_params
params.require(:blog).permit :title, :published, :content
def feed
@blogposts = Blogpost.where(:published => true).order(:created_at => :desc).limit 5
end
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ def page_title title, suffix = t(:title)
"#{title} - #{suffix}"
end
end

def markdownify text
Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true).render(text).html_safe
end
end
3 changes: 3 additions & 0 deletions app/models/blogpost.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class Blogpost < ActiveRecord::Base
def to_param
"#{self.id}-#{self.title}".parameterize
end
end
16 changes: 16 additions & 0 deletions app/views/blog/feed.atom.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
atom_feed do |feed|
feed.title(t 'pages.blog.headline')
feed.updated(@blogposts.first.updated_at)

for blogpost in @blogposts
feed.entry(blogpost, :url => blog_url(blogpost)) do |entry|
entry.title(blogpost.title)

entry.author do |author|
author.name('Diaspora* Foundation')
end

entry.content(markdownify(blogpost.content), :type => 'html')
end
end
end
11 changes: 10 additions & 1 deletion app/views/blog/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
<h1><%= t 'pages.blog.headline' %> <small><%= t 'pages.blog.subline' %></small></h1>
</div>

Ohai, blog!
<%- @blogposts.each do |blogpost| %>
<div class="blogcontent bloglist-item">
<div class="page-header clearfix">
<h1><%= link_to blogpost.title, blog_url(blogpost, subdomain: 'blog') %> <small><%= l blogpost.created_at, format: :blog_headline %></small></h1>
</div>

<%= markdownify blogpost.content %>
</div>
<% end %>

15 changes: 15 additions & 0 deletions app/views/blog/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%- content_for :page_title do %>
<%= @blogpost.title %>
<% end %>

<div class="page-header">
<h1><%= t 'pages.blog.headline' %> <small><%= t 'pages.blog.subline' %></small></h1>
</div>

<div class="blogcontent">
<div class="page-header clearfix">
<h1><%= @blogpost.title %> <small><%= l @blogpost.created_at, format: :blog_headline %></small></h1>
</div>

<%= markdownify @blogpost.content %>
</div>
15 changes: 8 additions & 7 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<%= favicon_link_tag "favicon.png" %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<%= auto_discovery_link_tag :atom, news_feed_url, {:title => t('newsfeed')} %>
<%= stylesheet_link_tag 'application', :media => 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
Expand All @@ -16,21 +17,21 @@
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<%= link_to root_path, class: 'brand' do %>
<%= link_to root_url(subdomain: false), class: 'brand' do %>
<%= image_tag 'logo.png', alt: t('title'), title: t('title'), id: 'header-logo' %>
<% end %>

<div id="mainnav" class="pull-right">
<ul class="nav">
<!-- <li><%= link_to t('pages.about.menu_title'), about_url %></li> -->
<li><%= link_to t('pages.get_involved.menu_title'), get_involved_url %></li>
<!-- <li><%= link_to t('pages.blog.menu_title'), blog_index_url(subdomain: 'blog') %></li> -->
<!-- <li><%= link_to t('pages.about.menu_title'), about_url(subdomain: false) %></li> -->
<li><%= link_to t('pages.get_involved.menu_title'), get_involved_url(subdomain: false) %></li>
<li><%= link_to t('pages.blog.menu_title'), blog_index_url(subdomain: 'blog') %></li>
<li><%= link_to t('.wiki'), 'https://wiki.diasporafoundation.org' %></li>
<li><%= link_to t('pages.tutorials.menu_title'), tutorials_url %></li>
<li><%= link_to t('pages.tutorials.menu_title'), tutorials_url(subdomain: false) %></li>
<!-- <li><%= link_to t('.planet'), 'http://planet.diasporafoundation.org' %></li> -->
</ul>
<%= link_to t('buttons.host_pod'), about_path(anchor: "host"), class: 'btn primary' %>
<%= link_to t('buttons.join_diaspora'), root_path(anchor: "get_started"), class: 'btn success' %>
<%= link_to t('buttons.host_pod'), about_url(subdomain: false, anchor: "host"), class: 'btn primary' %>
<%= link_to t('buttons.join_diaspora'), root_url(subdomain: false, anchor: "get_started"), class: 'btn success' %>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
en:
time:
formats:
blog_headline: "%d %B %Y"
buttons:
host_pod: "Host a pod"
join_diaspora: "Join us!"
Expand All @@ -7,6 +10,7 @@ en:
footer:
copyleft: "CC-BY The diaspora* Foundation"
title: "The diaspora* Project"
newsfeed: "Newsfeed"
layouts:
application:
wiki: Wiki
Expand Down
7 changes: 4 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
DiasporaProjectSite::Application.routes.draw do
devise_for :users

get 'switch_locale/:locale' => 'i18n#switch_locale', as: :switch_locale

constraints subdomain: /^(|www)$/i do
controller :pages do
get :about
Expand All @@ -18,9 +20,7 @@
get :formatting
get :tips
get :other_docs
end

get 'switch_locale/:locale' => 'i18n#switch_locale', as: :switch_locale
end

root to: 'pages#index'
end
Expand All @@ -30,6 +30,7 @@
end

constraints subomdain: /^blog$/i do
get 'feed' => 'blog#feed', :as => :news_feed, :defaults => {:format => :atom}
resources :blog, path: '/', only: [:index, :show]
end
end

0 comments on commit 873ecc4

Please sign in to comment.