Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding globalize3, friendlyid and small rdiscount support (no cache)

  • Loading branch information...
commit 0ff7071d72daa73e48fc497fe8034f46d1e16b5b 1 parent d997162
@akitaonrails authored
View
3  Gemfile
@@ -22,6 +22,9 @@ end
gem 'jquery-rails'
gem 'rails-translate-routes'
+gem 'globalize3'
+gem 'friendly_id'
+gem 'rdiscount'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
12 Gemfile.lock
@@ -48,6 +48,11 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ friendly_id (4.0.7)
+ globalize3 (0.2.0)
+ activemodel (>= 3.0.0)
+ activerecord (>= 3.0.0)
+ paper_trail (~> 2)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.4)
@@ -63,6 +68,9 @@ GEM
mime-types (1.19)
multi_json (1.3.6)
orm_adapter (0.3.0)
+ paper_trail (2.6.3)
+ activerecord (~> 3.0)
+ railties (~> 3.0)
polyglot (0.3.3)
pry (0.9.9.6)
coderay (~> 1.0.5)
@@ -95,6 +103,7 @@ GEM
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
+ rdiscount (1.6.8)
rdoc (3.12)
json (~> 1.4)
rspec (2.10.0)
@@ -139,10 +148,13 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
devise
+ friendly_id
+ globalize3
jquery-rails
pry-rails
rails (= 3.2.6)
rails-translate-routes
+ rdiscount
rspec-rails
sass-rails (~> 3.2.3)
sqlite3
View
3  app/assets/javascripts/articles.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/articles.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the articles controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
6 app/controllers/articles_controller.rb
@@ -0,0 +1,6 @@
+class ArticlesController < ApplicationController
+ def show
+ @article = Article.find(params[:id])
+ @body_html = RDiscount.new(@article.body || "").to_html
+ end
+end
View
2  app/helpers/articles_helper.rb
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
View
17 app/models/article.rb
@@ -0,0 +1,17 @@
+class Article < ActiveRecord::Base
+ attr_accessible :body, :slug, :title, :locale
+ extend FriendlyId
+ friendly_id :title, use: :slugged
+
+ translates :title, :body
+
+ class Translation
+ attr_accessible :locale
+ end
+
+private
+
+ def should_generate_new_friendly_id?
+ new_record?
+ end
+end
View
3  app/views/articles/show.html.erb
@@ -0,0 +1,3 @@
+<h1><%= @article.title %></h1>
+
+<%=raw @article.body %>
View
13 app/views/welcome/index.html.erb
@@ -1,12 +1,7 @@
-<h1>Welcome#index</h1>
-
-<p>
- <%= t("hello") %>
-</p>
+<h1>Articles</h1>
<ul>
- <li><%= number_to_currency(100.0) %></li>
- <li><%= l(Time.current, :format => :long) %></li>
- <li><%= distance_of_time_in_words Time.now, Time.now + 2.hours %></li>
- <li><%= User.human_attribute_name(:password) %></li>
+ <% Article.all.each do |article| %>
+ <li><%= link_to article.title, article_path(article.slug) %></li>
+ <% end %>
</ul>
View
2  config/locales/routes.yml
@@ -10,3 +10,5 @@ pt-BR:
sign_in: login
users: usuarios
cancel: cancelar
+ article: artigo
+ articles: artigos
View
3  config/routes.rb
@@ -1,5 +1,8 @@
I18nDemo::Application.routes.draw do
+ get "articles/show"
+
devise_for :users
+ resources :articles
get "welcome/index", as: "welcome"
root to: 'welcome#index'
end
View
16 db/migrate/20120713201558_create_articles.rb
@@ -0,0 +1,16 @@
+class CreateArticles < ActiveRecord::Migration
+ def up
+ create_table :articles do |t|
+ t.string :slug, null: false
+ t.timestamps
+ end
+ add_index :articles, :slug, unique: true
+
+ Article.create_translation_table! :title => :string, :body => :text
+ end
+
+ def down
+ drop_table :articles
+ Article.drop_translation_table!
+ end
+end
View
22 db/schema.rb
@@ -11,7 +11,27 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120712230107) do
+ActiveRecord::Schema.define(:version => 20120713201558) do
+
+ create_table "article_translations", :force => true do |t|
+ t.integer "article_id"
+ t.string "locale"
+ t.string "title"
+ t.text "body"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "article_translations", ["article_id"], :name => "index_article_translations_on_article_id"
+ add_index "article_translations", ["locale"], :name => "index_article_translations_on_locale"
+
+ create_table "articles", :force => true do |t|
+ t.string "slug", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "articles", ["slug"], :name => "index_articles_on_slug", :unique => true
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
View
241 public/index.html
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
12 spec/controllers/articles_controller_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe ArticlesController do
+
+ describe "GET 'show'" do
+ it "returns http success" do
+ get 'show'
+ response.should be_success
+ end
+ end
+
+end
View
15 spec/helpers/articles_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the ArticlesHelper. For example:
+#
+# describe ArticlesHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe ArticlesHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/article_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Article do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/views/articles/show.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe "articles/show.html.erb" do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.