Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Fixes #42 - Import old wordpress data and convert to markdown… #98

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ gem 'bugsnag'

group :development do
gem 'annotate'
gem 'quiet_assets'
gem 'spring'
gem 'spring-commands-rspec'
end

group :legacy do
gem 'mysql2'
gem 'reverse_markdown'
gem 'nokogiri'
end

group :development, :test do
gem 'capybara'
gem 'factory_girl_rails'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ GEM
multi_json (1.11.2)
multi_xml (0.5.5)
multipart-post (2.0.0)
mysql2 (0.4.2)
neat (1.7.2)
bourbon (>= 4.0)
sass (>= 3.3)
Expand Down Expand Up @@ -226,6 +227,8 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -271,6 +274,8 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
reverse_markdown (1.0.0)
nokogiri
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
Expand Down Expand Up @@ -380,13 +385,17 @@ DEPENDENCIES
guard-rspec
guard-rubocop
jquery-rails
mysql2
newrelic_rpm
nokogiri
omniauth-github
pg
pry
quiet_assets
rails (~> 4.2.2)
rails_12factor
redcarpet
reverse_markdown
rspec-rails
rubocop
sass-rails
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class HomeController < ApplicationController

def index
@events = Event.published.limit(2)
@news_items = NewsItem.published.to_a
@news_items = NewsItem.published.limit(10).to_a
end

end
18 changes: 16 additions & 2 deletions app/controllers/news_items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
class NewsItemsController < ApplicationController
def index
@news_items = NewsItem.published.to_a
@news_items = news_item_scope.to_a
end

# TODO: See Issue #151
# If `params[:slug]` is present, it's *most probably* coming from a
# wordpress legacy link.
# When the legacy data was imported, we also stored that original `slug`
# and this is why we first try to load an event_item using that param.
#
def show
@news_item = NewsItem.published.find(params[:id])
@news_item = news_item_scope.where(slug: params[:slug]).first ||
news_item_scope.where(id: params[:id]).first ||
raise(ActiveRecord::RecordNotFound)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benichu Could we extract as a method and pushed into the model? e.g.

NewsItem.fetch_published!(params[:id], params[:slug])

This allow to document the method, as I'm unsure why this is required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. The reason why it's required is to still resolve old wordpress links (ex: if someone clicks on an post url from google)
I'll extract that logic into a tested and documented class method tonight or later today...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, we probably should do a redirect to the correct URL, but let's do that as a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, just created a ticket for that #151
Until then, I am also going to leave the object loading methods as-is in the controller, I'll just add a comment to the method.

end

private

def news_item_scope
NewsItem.published
end
end
6 changes: 2 additions & 4 deletions app/dashboards/news_item_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NewsItemDashboard < Administrate::BaseDashboard
id: Field::Number,
title: Field::String,
body: Field::Text,
state: Field::String,
state: EnumField,
published_at: Field::DateTime,
created_at: Field::DateTime,
updated_at: Field::DateTime,
Expand All @@ -26,11 +26,9 @@ class NewsItemDashboard < Administrate::BaseDashboard
COLLECTION_ATTRIBUTES = [
:id,
:title,
:body,
:state,
:published_at,
:created_at,
:updated_at,
:published_at,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benichu This array ends with a comma, is that normal ? Coming from you I guess it is, but I've never seen this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got my answer : rubocop/ruby-style-guide#76

]

# SHOW_PAGE_ATTRIBUTES
Expand Down
27 changes: 24 additions & 3 deletions app/models/news_item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
# a NewsItem represents any announcement that we want to communicate to our
# web audience.
#
# When it is marked as `published`, a `published_at` is automatically added/updated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [83/80]

# and will decide on the display order of that `news_item`
#
# NOTE: [legacy]
# - This is also where we imported the old wordpress posts
# - The `slug` is purely used to store the old wordpress slug and make sure we
# can still resolve: http://www.montrealrb.com/[post_date:YYYY]/[post_date:MM]/[post_name]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [92/80]

#
class NewsItem < ActiveRecord::Base
# Extends
extend Enumerize
enumerize :state, in: [:draft, :archived, :published]
scope :published, -> { where(state: :published).order(:published_at) }
validates :published_at, presence: true, if: -> { state.published? }

# Scopes
scope :published, -> { where(state: :published).order(published_at: :desc) }

# Validations
validates :published_at, presence: true, if: -> { state.published? }
validates_presence_of :title, :state

# Class methods
enumerize :state, in: [:draft, :archived, :published]
to_param :title

# Instance methods
end
54 changes: 2 additions & 52 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,61 +1,11 @@
<% @news_items.each do |news_item| %>
<div class="post clearfix">
<h2 class="post-title"><%= news_item.title%></h2>
<h2 class="post-title"><%= link_to news_item.title, news_item_path(news_item) %></h2>
<p class="meta">
Posted <%= time_ago_in_words(news_item.published_at) %> ago
</p>
<div class="post-body">
<%= news_item.body %>
<%= render_markdown_as_html news_item.body %>
</div>
</div>
<% end %>
<div class="post clearfix">
<h2 class="post-title"><%= link_to 'So Long, and Thanks for All the Fish', '#' %></h2>
<p class="meta">
Posted on November 18 in <%= link_to 'News', '#' %> by <%= link_to 'Martin', '#' %>
</p>
<div class="post-body">
<p>Hey fellow Rubyist,</p>
<p>Yesterday was my last meet-up as a Montreal.rb organizer. After 4.5 years of taking care of our group, it’s time for me to pass the torch.</p>
<p>I remember so much from all the time I spent volunteering for Montreal.rb. The group grew during my tenure and we frequently had new faces, an achievement that I’m really proud of. We also had great projects like Railsbridge and Office Hours. Those are proof of our dynamic community here in Montreal. I would like to thank everyone who attended one of our events, those who spent time helping me organize Montreal.rb, and especially those who had the courage to give a talk.</p>
<p>Does that mean that Montreal.rb will die? I don’t think so. I’m leaving because I believe our community is ready to grow without me supporting it on my shoulders. I’ll be honest here: organizing Montreal.rb takes a lot more time than what you would think. If you like our group and you want to see it survive, please get involved. Do not let only one person be responsible for our group, it’s really hard to do. You don’t need to spend as much time as I did – organizing 1 meet-up here and there is enough to help the organizers.</p>
<p>What is next for me? Where will I get involved next? Honestly, I don’t know. I’m working and having fun at Sharethebus – we are hiring btw <img src="http://www.montrealrb.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"> – that’s a start. I’ll maybe have time to do some open source, who knows?</p>
<p>Anyhow, I’ll see you at the next Montreal.rb meet-up where I’ll be only an attendee – a first since 2011.</p>
<p>Take care of our group for me,</p>
<p>Martin</p>
<p>
<%= link_to icon('caret-right', 'Read More'), '#', class: 'btn btn-primary pull-right' %>
</p>
</div>
</div>
<div class="post clearfix">
<h2 class="post-title"><%= link_to 'Rails Workshop', '#' %></h2>
<p class="meta">
Posted on November 10 in <%= link_to 'Events', '#' %> by <%= link_to 'Sophie', '#' %>
</p>
<ul class='list-unstyled'>
<li>When: Tuesday November 24, 2015 from 6:30pm to 10:30pm</li>
<li>Where: Centre Cloud.ca, 420 rue Guy, Montreal</li>
<li>Who: Everybody interested in building a Rails website</li>
<li>How much: Free! Pizza and beer offered by AdGear</li>
</ul>
<div class="post-body">
<p>
This workshop is a couple hours sprint to help us have a brand new Rails website!!
</p>
<p>
Experienced and new Ruby on Rails developpers are welcome to pair together to work on the features we need to publish the website.
</p>
<p>
You must bring your own laptop with Ruby on Rails, PostgreSQL and Git installed.<br>
You should clone the existing repository (https://github.com/montrealrb/Montreal.rb) and create your github account if you don’t already have one.<br>
Experienced Rails developpers should be able to run the webserver before the event.
</p>
<p>
If you have some problems with any of the requirered installations, we might be able to help you or you can pair with somebody else on their computer.
</p>
<p>
<%= link_to icon('caret-right', 'Read More'), '#', class: 'btn btn-primary pull-right' %>
</p>
</div>
</div>
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
devise_for :users,
controllers: { omniauth_callbacks: "users/omniauth_callbacks" }

resources :events, only: [:index, :show]
# NewsItem compatibility with old wordpress Posts url
get "/:year/:month/:slug",
to: "news_items#show",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the parameters of a method call if they span more than one line.

constraints: { year: /\d{4}/, month: /\d{2}/ }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of a hash literal if they span more than one line.

resources :news_items, only: [:index, :show]

resources :events, only: [:index, :show]
resources :organizations, only: [:index, :show]
resources :pages, only: [:show]

Expand Down
Loading