From c2c6e1ccc42e151f29a9a224be522ce598db0cd9 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Thu, 11 Dec 2014 05:26:48 +0100 Subject: [PATCH] implement basic entries list --- Gemfile | 4 ++- Gemfile.lock | 16 +++++++++-- app/controllers/planet_controller.rb | 13 +++++++++ app/views/planet/index.html.erb | 22 +++++++++++++++ config/locales/en.yml | 3 +- config/routes.rb | 41 ++++++++++++++++------------ lib/planet/models/entry.rb | 9 ++++++ 7 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 app/controllers/planet_controller.rb create mode 100644 app/views/planet/index.html.erb diff --git a/Gemfile b/Gemfile index 1c59fa0..879c93f 100644 --- a/Gemfile +++ b/Gemfile @@ -12,17 +12,19 @@ gem 'rails_admin' gem 'rails_locale_detection', '~> 2.0.0.pre' gem 'sass-rails', '~> 4.0.0' -gem 'bootstrap-sass', '~> 3.2.0' +gem 'bootstrap-sass', '~> 3.3.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0' gem 'jquery-rails' gem 'turbolinks' +gem 'will_paginate-bootstrap' gem 'redcarpet', '~> 3.2' gem 'paperclip', '~> 4.1' gem 'feedjira', github: 'feedjira/feedjira' gem 'trollop', '~> 2.0' +gem 'sanitize', '~> 3.0.0' group :development, :test do gem 'pry' diff --git a/Gemfile.lock b/Gemfile.lock index 94b4d26..009da73 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,7 +39,7 @@ GEM arel (5.0.1.20140414130214) awesome_print (1.2.0) bcrypt (3.1.9) - bootstrap-sass (3.2.0.2) + bootstrap-sass (3.3.1.0) sass (~> 3.2) builder (3.2.2) capybara (2.4.4) @@ -60,6 +60,7 @@ GEM coffee-script-source execjs coffee-script-source (1.8.0) + crass (0.2.1) curb (0.8.6) devise (3.4.1) bcrypt (~> 3.0) @@ -104,6 +105,8 @@ GEM nested_form (0.3.2) nokogiri (1.6.5) mini_portile (~> 0.6.0) + nokogumbo (1.1.12) + nokogiri orm_adapter (0.5.0) paperclip (4.2.1) activemodel (>= 3.0.0) @@ -182,6 +185,10 @@ GEM rspec-support (3.1.2) ruby-progressbar (1.7.0) safe_yaml (1.0.4) + sanitize (3.0.3) + crass (~> 0.2.0) + nokogiri (>= 1.4.4) + nokogumbo (= 1.1.12) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -216,6 +223,9 @@ GEM raindrops (~> 0.7) warden (1.2.3) rack (>= 1.0) + will_paginate (3.0.7) + will_paginate-bootstrap (1.0.1) + will_paginate (>= 3.0.3) xpath (2.0.0) nokogiri (~> 1.3) @@ -224,7 +234,7 @@ PLATFORMS DEPENDENCIES awesome_print - bootstrap-sass (~> 3.2.0) + bootstrap-sass (~> 3.3.0) capybara (~> 2.4.1) coffee-rails (~> 4.0) devise (~> 3.4.0) @@ -240,8 +250,10 @@ DEPENDENCIES redcarpet (~> 3.2) rspec-instafail (~> 0.2.4) rspec-rails (~> 3.0) + sanitize (~> 3.0.0) sass-rails (~> 4.0.0) trollop (~> 2.0) turbolinks uglifier (>= 1.3.0) unicorn + will_paginate-bootstrap diff --git a/app/controllers/planet_controller.rb b/app/controllers/planet_controller.rb new file mode 100644 index 0000000..03abc1e --- /dev/null +++ b/app/controllers/planet_controller.rb @@ -0,0 +1,13 @@ +class PlanetController < ApplicationController + respond_to :html, :except => [:feed] + respond_to :atom, :only => [:feed] + + def index + @entries = Planet::Models::Entry.order(:published_at => :desc) + .paginate(:page => params[:page], :per_page => 10) + end + + def feed + # TODO implement me + end +end diff --git a/app/views/planet/index.html.erb b/app/views/planet/index.html.erb new file mode 100644 index 0000000..0c3dc02 --- /dev/null +++ b/app/views/planet/index.html.erb @@ -0,0 +1,22 @@ +<%- content_for :page_title do %> + <%= t 'pages.planet.menu_title' %> +<% end %> + + + +<%- @entries.each do |entry| %> +
+ + + <%= entry.sanitized_body.html_safe %> +
+<% end %> + +<%= will_paginate @entries, renderer: BootstrapPagination::Rails %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 4eab5a2..888625b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -192,7 +192,8 @@ en: subline: "official announcements" menu_title: Blog planet: - headline: Planet + headline: "The diaspora* planet" + subline: "blog posts by our community" menu_title: Planet tutorials: headline: "diaspora* tutorials" diff --git a/config/routes.rb b/config/routes.rb index 7dba035..1db8e0f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,23 +4,23 @@ get 'switch_locale/:locale' => 'i18n#switch_locale', as: :switch_locale constraints subdomain: /^(|www)$/i do - controller :pages do - get :about - get :get_involved - get :tutorials - scope 'getting_started' do - get :sign_up, action: 'getting_started1' - get :interface, action: 'getting_started2' - get :aspects, action: 'getting_started3' - get :connecting, action: 'getting_started4' - get :sharing, action: 'getting_started5' - get :conversations, action: 'getting_started6' - get :finishing, action: 'getting_started7' - end - get :formatting - get :tips - get :other_docs - end + controller :pages do + get :about + get :formatting + get :get_involved + get :other_docs + get :tips + get :tutorials + scope 'getting_started' do + get :aspects, action: 'getting_started3' + get :connecting, action: 'getting_started4' + get :conversations, action: 'getting_started6' + get :finishing, action: 'getting_started7' + get :interface, action: 'getting_started2' + get :sharing, action: 'getting_started5' + get :sign_up, action: 'getting_started1' + end + end root to: 'pages#index' end @@ -29,8 +29,13 @@ mount RailsAdmin::Engine => '/', as: 'rails_admin' end - constraints subomdain: /^blog$/i do + constraints subdomain: /^blog$/i do get 'feed' => 'blog#feed', :as => :news_feed, :defaults => {:format => :atom} resources :blog, path: '/', only: [:index, :show] end + + constraints subdomain: /^planet$/i do + get 'feed' => 'planet#feed', :as => :planet_feed, :defaults => {:format => :atom} + get '/' => 'planet#index' + end end diff --git a/lib/planet/models/entry.rb b/lib/planet/models/entry.rb index b4f4884..05175e9 100644 --- a/lib/planet/models/entry.rb +++ b/lib/planet/models/entry.rb @@ -4,6 +4,15 @@ class Entry < ActiveRecord::Base belongs_to :feed validates_presence_of :entry_id, :feed, :title, :body, :url validates_uniqueness_of :entry_id + + def sanitized_body + Sanitize.fragment(self.body, Sanitize::Config.merge( + Sanitize::Config::RELAXED, + :add_attributes => { + 'a' => {'rel' => 'nofollow'} + } + )) + end end end end