Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding support for heroku

  • Loading branch information...
commit 060ee57a6a7928150f0eb1861f3ac96bedf701ca 1 parent cc84764
@akitaonrails authored
View
9 Gemfile
@@ -1,11 +1,12 @@
source 'https://rubygems.org'
+ruby "1.9.3"
+
gem 'rails', '3.2.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'sqlite3'
gem 'devise'
# Gems used only for assets and not required
@@ -49,6 +50,7 @@ gem 'ActiveAdmin-Globalize3-inputs'
# gem 'debugger'
group :development, :test do
+ gem 'sqlite3'
gem 'rspec-rails'
gem 'pry-rails'
@@ -56,3 +58,8 @@ group :development, :test do
gem 'guard-rspec'
gem 'growl'
end
+
+group :production do
+ gem 'pg'
+ gem 'thin'
+end
View
9 Gemfile.lock
@@ -56,6 +56,7 @@ GEM
execjs
coffee-script-source (1.3.3)
commonjs (0.2.6)
+ daemons (1.1.8)
devise (2.1.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
@@ -63,6 +64,7 @@ GEM
warden (~> 1.2.1)
diff-lcs (1.1.3)
erubis (2.7.0)
+ eventmachine (0.12.10)
execjs (1.4.0)
multi_json (~> 1.0)
fastercsv (1.5.5)
@@ -124,6 +126,7 @@ GEM
paper_trail (2.6.3)
activerecord (~> 3.0)
railties (~> 3.0)
+ pg (0.13.2)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
@@ -194,6 +197,10 @@ GEM
sqlite3 (1.3.6)
therubyracer (0.10.1)
libv8 (~> 3.3.10)
+ thin (1.3.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
thor (0.15.4)
tilt (1.3.3)
treetop (1.4.10)
@@ -227,6 +234,7 @@ DEPENDENCIES
jquery-rails
jquery-ui-rails
less-rails
+ pg
pry-rails
rails (= 3.2.6)
rails-translate-routes
@@ -235,5 +243,6 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sqlite3
therubyracer
+ thin
twitter-bootstrap-rails
uglifier (>= 1.0.3)
View
4 app/admin/articles.rb
@@ -13,10 +13,10 @@
I18n.available_locales.each do |locale|
h3 I18n.t(locale, scope: ["translation"])
div do
- h4 article.translations.where(locale: locale).first.title
+ h4 article.translations.where(locale: locale).first.title rescue nil
end
div do
- article.translations.where(locale: locale).first.body_html.html_safe
+ article.translations.where(locale: locale).first.body_html.html_safe rescue nil
end
end
end
View
3  app/helpers/application_helper.rb
@@ -20,6 +20,9 @@ def navigation_links
options = params[:controller] == "articles" ? { class: "active" } : {}
links << content_tag(:li, link_to(t("articles.title"), articles_path), options).html_safe
+ options = params[:controller] =~ /devise/i ? { class: "active" } : {}
+ links << content_tag(:li, link_to(t("devise.registrations.new.title"), new_user_registration_path), options).html_safe
+
links << content_tag(:li, link_to(t("admin.title"), admin_dashboard_path)).html_safe
content_tag(:ul, links.join("\n").html_safe, class: "nav")
View
10 app/models/article.rb
@@ -12,6 +12,14 @@ class Translation
attr_accessible :locale, :title, :body, :body_html
end
+ def translations_attributes=(attributes)
+ new_translations = attributes.values.reduce({}) do |new_values, translation|
+ translation.merge!("body_html" => RDiscount.new(translation["body"] || "").to_html )
+ new_values.merge! translation.delete("locale") => translation
+ end
+ set_translations new_translations
+ end
+
private
def should_generate_new_friendly_id?
@@ -19,6 +27,6 @@ def should_generate_new_friendly_id?
end
def generate_html
- self.body_html = RDiscount.new(self.body).to_html
+ self.body_html = RDiscount.new(self.body || "").to_html
end
end
View
6 config/application.rb
@@ -34,6 +34,8 @@ class Application < Rails::Application
config.i18n.available_locales = [:en, :"pt-BR"]
config.i18n.default_locale = :"pt-BR"
+ config.i18n.fallbacks = true
+
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
@@ -59,5 +61,9 @@ class Application < Rails::Application
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
+
+ config.assets.initialize_on_precompile = false
+
+ config.assets.precompile += %w(active_admin.js active_admin.css)
end
end
View
2  db/migrate/20120713201558_create_articles.rb
@@ -6,7 +6,7 @@ def up
end
add_index :articles, :slug, unique: true
- Article.create_translation_table! :title => :string, :body => :text
+ Article.create_translation_table! :title => :string, :body => :text, :body_html => :text
end
def down
View
5 db/migrate/20120714161124_add_html_cache_fields_to_article.rb
@@ -1,5 +0,0 @@
-class AddHtmlCacheFieldsToArticle < ActiveRecord::Migration
- def change
- add_column :article_translations, :body_html, :text
- end
-end
View
24 spec/models/article_spec.rb
@@ -28,6 +28,30 @@
end
end
+ context "multiple translations" do
+ before(:each) do
+ @params = {"translations_attributes"=>{
+ "0"=>{"title"=>"Hello World", "body"=>"**Markdown Test**", "locale"=>"en"},
+ "1"=>{"title"=>"Ola Mundo", "body"=>"__Teste de Markdown__", "locale"=>"pt-BR"}}}
+ end
+
+ it "should accept multiple translations at once" do
+ @article = Article.new(@params)
+ @article.translations.size.should == 2
+ @article.save
+ @article.reload
+ @article.translations.size.should == 2
+ end
+
+ it "should generate all the HTMLs at once" do
+ @article = Article.create(@params)
+ I18n.locale = :en
+ @article.body_html.should == "<p><strong>Markdown Test</strong></p>\n"
+ I18n.locale = :"pt-BR"
+ @article.body_html.should == "<p><strong>Teste de Markdown</strong></p>\n"
+ end
+ end
+
context "slug" do
it "should generate a slug" do
@article.slug.should == "hello-world"
Please sign in to comment.
Something went wrong with that request. Please try again.