From 6d20972f34b8c8f31f7194276077bffc1d978665 Mon Sep 17 00:00:00 2001 From: Fernando Seror Date: Sun, 9 Aug 2015 09:27:25 -0500 Subject: [PATCH 01/85] Share in social networks * Add the social buttons gem to the Gemfile * Initializer and translations for the social buttons * Add the social buttons assets to the sprockets require * Add the social buttons in the show debate view * Spec to lock down the amount of social share buttons to three --- Gemfile | 1 + Gemfile.lock | 4 ++++ app/assets/javascripts/application.js | 1 + app/assets/stylesheets/application.scss | 6 +++++- app/views/debates/show.html.erb | 1 + config/initializers/social_share_button.rb | 3 +++ config/locales/social_share_button.en.yml | 19 +++++++++++++++++++ config/locales/social_share_button.es.yml | 19 +++++++++++++++++++ spec/features/debates_spec.rb | 4 ++++ 9 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 config/initializers/social_share_button.rb create mode 100644 config/locales/social_share_button.en.yml create mode 100644 config/locales/social_share_button.es.yml diff --git a/Gemfile b/Gemfile index 5ca7a1a6bd6..f3e2928812e 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,7 @@ gem 'acts_as_votable' gem "recaptcha", require: "recaptcha/rails" gem 'ckeditor' gem 'cancancan' +gem 'social-share-button' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index fd9842f3982..f3c45c93dca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -241,6 +241,9 @@ GEM json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) + social-share-button (0.1.8) + coffee-rails + sass-rails spring (1.3.6) sprockets (3.2.0) rack (~> 1.0) @@ -318,6 +321,7 @@ DEPENDENCIES responders rspec-rails (~> 3.0) sass-rails (~> 5.0) + social-share-button spring turbolinks uglifier (>= 1.3.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 08153c4ec6f..def844e5a41 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,6 +15,7 @@ //= require foundation //= require turbolinks //= require ckeditor/init +//= require social-share-button //= require app //= require_tree . diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 1bcdc722a3f..e4379397e9b 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -1,6 +1,10 @@ +/* + *= require social-share-button + */ + @import "foundation_and_overrides"; @import "fonts"; @import "icons"; @import "variables"; @import "participacion"; -@import "debates"; \ No newline at end of file +@import "debates"; diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 51537d5a595..36622951a29 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -9,6 +9,7 @@

<%= @debate.title %>

<%= @debate.description %>

<%= render 'shared/tags', debate: @debate %>

+

<%= social_share_button_tag(@debate.title) %>

diff --git a/config/initializers/social_share_button.rb b/config/initializers/social_share_button.rb new file mode 100644 index 00000000000..d8b6e52546a --- /dev/null +++ b/config/initializers/social_share_button.rb @@ -0,0 +1,3 @@ +SocialShareButton.configure do |config| + config.allow_sites = %w(twitter facebook google_plus) +end diff --git a/config/locales/social_share_button.en.yml b/config/locales/social_share_button.en.yml new file mode 100644 index 00000000000..95dba5da939 --- /dev/null +++ b/config/locales/social_share_button.en.yml @@ -0,0 +1,19 @@ +en: + social_share_button: + share_to: Share to %{name} + weibo: Sina Weibo + twitter: Twitter + facebook: Facebook + douban: Douban + qq: Qzone + tqq: Tqq + delicious: Delicious + baidu: Baidu.com + kaixin001: Kaixin001.com + renren: Renren.com + google_plus: Google+ + google_bookmark: Google Bookmark + tumblr: Tumblr + plurk: Plurk + pinterest: Pinterest + email: Email diff --git a/config/locales/social_share_button.es.yml b/config/locales/social_share_button.es.yml new file mode 100644 index 00000000000..e0520c19b2a --- /dev/null +++ b/config/locales/social_share_button.es.yml @@ -0,0 +1,19 @@ +es: + social_share_button: + share_to: Compartir en %{name} + weibo: Sina Weibo + twitter: Twitter + facebook: Facebook + douban: Douban + qq: Qzone + tqq: Tqq + delicious: Delicious + baidu: Baidu.com + kaixin001: Kaixin001.com + renren: Renren.com + google_plus: Google+ + google_bookmark: Google Bookmark + tumblr: Tumblr + plurk: Plurk + pinterest: Pinterest + email: Correo electrónico diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 894b09b193c..113e066564d 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -34,6 +34,10 @@ expect(page).to have_content "Debate description" expect(page).to have_content debate.author.name expect(page).to have_content I18n.l(Date.today) + + within('.social-share-button') do + expect(page.all('a').count).to be(3) # Twitter, Facebook, Google+ + end end scenario 'Create' do From 4839081ad233c8142ec4dbdad0c00272dcb147d6 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 10 Aug 2015 20:24:56 +0200 Subject: [PATCH 02/85] uses simple_captcha instead of recaptcha [#51] --- Gemfile | 2 +- Gemfile.lock | 5 ++- app/controllers/application_controller.rb | 8 +--- app/controllers/debates_controller.rb | 5 +-- app/controllers/registrations_controller.rb | 8 ++-- app/helpers/recaptcha_helper.rb | 12 ------ app/models/debate.rb | 2 +- app/models/user.rb | 1 + app/views/debates/_form.html.erb | 4 +- app/views/devise/registrations/new.html.erb | 2 +- app/views/layouts/application.html.erb | 1 - app/views/layouts/devise.html.erb | 1 - app/views/shared/_captcha.html.erb | 3 -- app/views/simple_captcha/_simple_captcha.erb | 41 +++++++++++++++++++ config/i18n-tasks.yml | 1 + config/initializers/recaptcha.rb | 5 --- config/initializers/simple_captcha.rb | 37 +++++++++++++++++ config/locales/en.yml | 9 ++-- config/locales/es.yml | 9 ++-- config/locales/rails.en.yml | 4 -- config/locales/rails.es.yml | 10 ++--- config/secrets.yml.example | 2 - ...150808141306_create_simple_captcha_data.rb | 15 +++++++ db/schema.rb | 11 ++++- spec/features/debates_spec.rb | 3 ++ spec/features/tags_spec.rb | 1 + spec/features/users_spec.rb | 1 + spec/helpers/recaptcha_helper_spec.rb | 36 ---------------- spec/support/common_actions.rb | 5 +++ 29 files changed, 144 insertions(+), 100 deletions(-) delete mode 100644 app/helpers/recaptcha_helper.rb delete mode 100644 app/views/shared/_captcha.html.erb create mode 100644 app/views/simple_captcha/_simple_captcha.erb delete mode 100644 config/initializers/recaptcha.rb create mode 100644 config/initializers/simple_captcha.rb create mode 100644 db/migrate/20150808141306_create_simple_captcha_data.rb delete mode 100644 spec/helpers/recaptcha_helper_spec.rb diff --git a/Gemfile b/Gemfile index f3e2928812e..afa51a69e49 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'acts-as-taggable-on' gem "responders" gem 'foundation-rails' gem 'acts_as_votable' -gem "recaptcha", require: "recaptcha/rails" +gem 'simple_captcha2', require: 'simple_captcha' gem 'ckeditor' gem 'cancancan' gem 'social-share-button' diff --git a/Gemfile.lock b/Gemfile.lock index f3c45c93dca..9b4dc71a570 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -205,7 +205,6 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) - recaptcha (0.4.0) responders (2.1.0) railties (>= 4.2.0, < 5) rest-client (1.8.0) @@ -236,6 +235,8 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (~> 1.1) + simple_captcha2 (0.3.4) + rails (>= 4.1) simplecov (0.10.0) docile (~> 1.1.0) json (~> 1.8) @@ -317,10 +318,10 @@ DEPENDENCIES poltergeist quiet_assets rails (= 4.2.3) - recaptcha responders rspec-rails (~> 3.0) sass-rails (~> 5.0) + simple_captcha2 social-share-button spring turbolinks diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ad69fd5118c..083165303be 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,8 @@ require "application_responder" class ApplicationController < ActionController::Base - check_authorization unless: :devise_controller? - + include SimpleCaptcha::ControllerHelpers self.responder = ApplicationResponder respond_to :html @@ -38,9 +37,4 @@ def set_layout end end - def verify_captcha?(resource) - return true unless recaptcha_keys? - verify_recaptcha(model: resource) - end - end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index d7296543267..84f7d11a44c 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -1,5 +1,4 @@ class DebatesController < ApplicationController - include RecaptchaHelper before_action :authenticate_user!, except: [:index, :show] load_and_authorize_resource @@ -28,7 +27,7 @@ def edit def create @debate = Debate.new(debate_params) @debate.author = current_user - if verify_captcha?(@debate) and @debate.save + if @debate.save_with_captcha redirect_to @debate, notice: t('flash.actions.create.notice', resource_name: 'Debate') else render :new @@ -52,7 +51,7 @@ def set_debate end def debate_params - params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service) + params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service, :captcha, :captcha_key) end def set_voted_values(debates_ids) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 4991cdf705a..c979d631557 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -1,12 +1,10 @@ class RegistrationsController < Devise::RegistrationsController - include RecaptchaHelper def create - if verify_captcha?(resource) + build_resource(sign_up_params) + if resource.valid_with_captcha? super else - build_resource(sign_up_params) - flash.now[:alert] = t('recaptcha.errors.verification_failed') render :new end end @@ -15,7 +13,7 @@ def create private def sign_up_params - params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :use_nickname, :nickname) + params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :use_nickname, :nickname, :captcha, :captcha_key) end end diff --git a/app/helpers/recaptcha_helper.rb b/app/helpers/recaptcha_helper.rb deleted file mode 100644 index fb4cceb2028..00000000000 --- a/app/helpers/recaptcha_helper.rb +++ /dev/null @@ -1,12 +0,0 @@ -module RecaptchaHelper - - def recaptchable?(resource) - resource.new_record? - end - - def recaptcha_keys? - Recaptcha.configuration.public_key.present? && - Recaptcha.configuration.private_key.present? - end - -end \ No newline at end of file diff --git a/app/models/debate.rb b/app/models/debate.rb index 28181101af0..26fd2dbf052 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,6 +1,6 @@ require 'numeric' class Debate < ActiveRecord::Base - + apply_simple_captcha TITLE_LENGTH = Debate.columns.find{|c| c.name == 'title'}.limit acts_as_votable diff --git a/app/models/user.rb b/app/models/user.rb index 4eb832546ee..6857d981ce7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ActiveRecord::Base + apply_simple_captcha devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index c38d2c476f6..56af8013643 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -37,10 +37,10 @@
- <%= render 'shared/captcha', resource: @debate %> + <%= f.simple_captcha %>
-
+
<%= f.submit(class: "button radius") %>
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index c7cd839a208..d7352092e97 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -59,7 +59,7 @@ - <%= render 'shared/captcha', resource: resource %> + <%= f.simple_captcha %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 36a3c44cc9c..eee30377e7f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,7 +9,6 @@ <%= javascript_include_tag "vendor/modernizr" %> <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> - diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb index fe73e555332..85f448f81f5 100644 --- a/app/views/layouts/devise.html.erb +++ b/app/views/layouts/devise.html.erb @@ -9,7 +9,6 @@ <%= javascript_include_tag "vendor/modernizr" %> <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> - diff --git a/app/views/shared/_captcha.html.erb b/app/views/shared/_captcha.html.erb deleted file mode 100644 index 42ccb593682..00000000000 --- a/app/views/shared/_captcha.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% if recaptchable?(resource) and recaptcha_keys? %> - <%= recaptcha_tags ajax: true, hl: I18n.locale %> -<% end %> \ No newline at end of file diff --git a/app/views/simple_captcha/_simple_captcha.erb b/app/views/simple_captcha/_simple_captcha.erb new file mode 100644 index 00000000000..3a346a454c7 --- /dev/null +++ b/app/views/simple_captcha/_simple_captcha.erb @@ -0,0 +1,41 @@ + + +
+
+ <%= simple_captcha_options[:image] %> +
+ +
+ <%= simple_captcha_options[:field] %> +
+ +
+ <%= simple_captcha_options[:label] %> +
+ +
+ <%= simple_captcha_options[:refresh_button] %> +
+
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index f0afba346e5..12c1c80225d 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -99,6 +99,7 @@ ignore_unused: # - 'simple_form.{error_notification,required}.:' ignore_unused: - 'unauthorized.*' + - 'simple_captcha.*' ## Exclude these keys from the `i18n-tasks eq-base' report: # ignore_eq_base: diff --git a/config/initializers/recaptcha.rb b/config/initializers/recaptcha.rb deleted file mode 100644 index 36a5cef8b96..00000000000 --- a/config/initializers/recaptcha.rb +++ /dev/null @@ -1,5 +0,0 @@ -Recaptcha.configure do |config| - config.public_key = Rails.application.secrets.recaptcha_public_key - config.private_key = Rails.application.secrets.recaptcha_private_key - config.api_version = 'v2' -end \ No newline at end of file diff --git a/config/initializers/simple_captcha.rb b/config/initializers/simple_captcha.rb new file mode 100644 index 00000000000..8b55c0724f2 --- /dev/null +++ b/config/initializers/simple_captcha.rb @@ -0,0 +1,37 @@ +SimpleCaptcha.always_pass = false + +SimpleCaptcha.setup do |sc| + # default: 100x28 + sc.image_size = '120x40' + + # default: 5 + sc.length = 6 + + # default: simply_blue + # possible values: + # 'embosed_silver', + # 'simply_red', + # 'simply_green', + # 'simply_blue', + # 'distorted_black', + # 'all_black', + # 'charcoal_grey', + # 'almost_invisible' + # 'random' + sc.image_style = 'simply_green' + + # default: low + # possible values: 'low', 'medium', 'high', 'random' + sc.distortion = 'random' + + # default: medium + # possible values: 'none', 'low', 'medium', 'high' + sc.implode = 'medium' + + # sc.image_style = 'mycaptha' + # sc.add_image_style('mycaptha', [ + # "-background '#F4F7F8'", + # "-fill '#86818B'", + # "-border 1", + # "-bordercolor '#E0E2E3'"]) +end \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 29bc4df241e..d552ec75e1a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,9 +72,12 @@ en: last_name_label: "Last Name" use_nickname_label: "Use nickname" nickname_label: "Nickname" - recaptcha: - errors: - verification_failed: "The captcha verification failed" + simple_captcha: + placeholder: "Enter the image value" + label: "Enter the code in the box:" + message: + user: "secret code did not match with the image" + debate: "secret code did not match with the image" shared: tags_cloud: tags: Tags diff --git a/config/locales/es.yml b/config/locales/es.yml index 16af9d32432..46c4263102c 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -72,9 +72,12 @@ es: last_name_label: "Apellidos" use_nickname_label: "Usar pseudónimo" nickname_label: "Pseudónimo" - recaptcha: - errors: - verification_failed: "La verificación por captcha falló" + simple_captcha: + placeholder: "Introduce el texto de la imagen" + label: "Introduce el texto en la caja:" + message: + user: "el código secreto no coincide con la imagen" + debate: "el código secreto no coincide con la imagen" shared: tags_cloud: tags: Etiquetas diff --git a/config/locales/rails.en.yml b/config/locales/rails.en.yml index d09a8dd0951..cb5bdc38ff6 100644 --- a/config/locales/rails.en.yml +++ b/config/locales/rails.en.yml @@ -20,7 +20,3 @@ # available at http://guides.rubyonrails.org/i18n.html. en: - recaptcha: - errors: - verification_failed: "Incorrect Captcha" - recaptcha_unreachable: "Internet connecion error. Could not load Captcha" diff --git a/config/locales/rails.es.yml b/config/locales/rails.es.yml index a5666614d4a..f29361c451c 100644 --- a/config/locales/rails.es.yml +++ b/config/locales/rails.es.yml @@ -10,7 +10,7 @@ es: - vie - sáb abbr_month_names: - - + - - ene - feb - mar @@ -36,7 +36,7 @@ es: long: "%d de %B de %Y" short: "%d de %b" month_names: - - + - - enero - febrero - marzo @@ -195,8 +195,4 @@ es: default: "%A, %d de %B de %Y %H:%M:%S %z" long: "%d de %B de %Y %H:%M" short: "%d de %b %H:%M" - pm: pm - recaptcha: - errors: - verification_failed: "El Captcha no es correcto" - recaptcha_unreachable: "Fallo de conexión a Internet. No se ha podido cargar el Captcha" \ No newline at end of file + pm: pm \ No newline at end of file diff --git a/config/secrets.yml.example b/config/secrets.yml.example index 7fc62888769..f4ad9802733 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -11,8 +11,6 @@ # if you're sharing your code publicly. default: &default - recaptcha_public_key: <%= ENV["MADRID_RECAPTCHA_PUBLIC_KEY"] %> - recaptcha_private_key: <%= ENV["MADRID_RECAPTCHA_PRIVATE_KEY"] %> development: secret_key_base: 56792feef405a59b18ea7db57b4777e855103882b926413d4afdfb8c0ea8aa86ea6649da4e729c5f5ae324c0ab9338f789174cf48c544173bc18fdc3b14262e4 diff --git a/db/migrate/20150808141306_create_simple_captcha_data.rb b/db/migrate/20150808141306_create_simple_captcha_data.rb new file mode 100644 index 00000000000..4573b205640 --- /dev/null +++ b/db/migrate/20150808141306_create_simple_captcha_data.rb @@ -0,0 +1,15 @@ +class CreateSimpleCaptchaData < ActiveRecord::Migration + def self.up + create_table :simple_captcha_data do |t| + t.string :key, :limit => 40 + t.string :value, :limit => 6 + t.timestamps + end + + add_index :simple_captcha_data, :key, :name => "idx_key" + end + + def self.down + drop_table :simple_captcha_data + end +end diff --git a/db/schema.rb b/db/schema.rb index 2d97d8a6093..7dd74d45090 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150807140346) do +ActiveRecord::Schema.define(version: 20150808141306) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -53,6 +53,15 @@ add_index "moderators", ["user_id"], name: "index_moderators_on_user_id", using: :btree + create_table "simple_captcha_data", force: :cascade do |t| + t.string "key", limit: 40 + t.string "value", limit: 6 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "simple_captcha_data", ["key"], name: "idx_key", using: :btree + create_table "taggings", force: :cascade do |t| t.integer "tag_id" t.integer "taggable_id" diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 113e066564d..d164f113b99 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -47,6 +47,7 @@ visit new_debate_path fill_in 'debate_title', with: 'Acabar con los desahucios' fill_in 'debate_description', with: 'Esto es un tema muy importante porque...' + fill_in 'debate_captcha', with: correct_captcha_text check 'debate_terms_of_service' click_button 'Create Debate' @@ -65,6 +66,7 @@ visit new_debate_path fill_in 'debate_title', with: 'A test' fill_in 'debate_description', with: '

This is

' + fill_in 'debate_captcha', with: correct_captcha_text check 'debate_terms_of_service' click_button 'Create Debate' @@ -86,6 +88,7 @@ fill_in 'debate_title', with: 'A test' fill_in 'debate_description', with: 'A test' fill_in 'debate_tag_list', with: 'user_id=1, &a=3, ' + fill_in 'debate_captcha', with: SimpleCaptcha::SimpleCaptchaData.first.value check 'debate_terms_of_service' click_button 'Create Debate' diff --git a/spec/features/tags_spec.rb b/spec/features/tags_spec.rb index 8ea48eabc92..7c0b3209ae8 100644 --- a/spec/features/tags_spec.rb +++ b/spec/features/tags_spec.rb @@ -65,6 +65,7 @@ visit new_debate_path fill_in 'debate_title', with: 'Title' fill_in 'debate_description', with: 'Description' + fill_in 'debate_captcha', with: correct_captcha_text check 'debate_terms_of_service' fill_in 'debate_tag_list', with: "Impuestos, Economía, Hacienda" diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index c15869bae6a..be67c3e270c 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -11,6 +11,7 @@ fill_in 'user_email', with: 'manuela@madrid.es' fill_in 'user_password', with: 'judgementday' fill_in 'user_password_confirmation', with: 'judgementday' + fill_in 'user_captcha', with: correct_captcha_text click_button 'Sign up' diff --git a/spec/helpers/recaptcha_helper_spec.rb b/spec/helpers/recaptcha_helper_spec.rb deleted file mode 100644 index 7d44e2f08ab..00000000000 --- a/spec/helpers/recaptcha_helper_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'rails_helper' - -describe RecaptchaHelper do - - describe '#recaptchable?' do - - it 'should be true if new record' do - debate = build(:debate) - expect(helper.recaptchable?(debate)).to be true - end - - it 'should be false if existing record' do - debate = create(:debate) - expect(helper.recaptchable?(debate)).to be false - end - - end - - describe "#recaptcha_keys?" do - - it "should be true if Recaptcha keys are configured" do - allow(Recaptcha.configuration).to receive(:public_key).and_return("akjasf") - allow(Recaptcha.configuration).to receive(:private_key).and_return("akjasf4532") - - expect(helper.recaptcha_keys?).to be true - end - - it "should be false if Recaptcha keys are not configured" do - allow(Recaptcha.configuration).to receive(:public_key).and_return(nil) - allow(Recaptcha.configuration).to receive(:private_key).and_return(nil) - - expect(helper.recaptcha_keys?).to be false - end - - end -end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index d07f6026116..b625138b0de 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -9,6 +9,7 @@ def sign_up fill_in 'user_email', with: 'manuela@madrid.es' fill_in 'user_password', with: 'judgementday' fill_in 'user_password_confirmation', with: 'judgementday' + fill_in 'user_captcha', with: correct_captcha_text click_button 'Sign up' end @@ -51,4 +52,8 @@ def reply_to(user) expect(page).to have_content 'It will be done next week.' end + def correct_captcha_text + SimpleCaptcha::SimpleCaptchaData.first.value + end + end \ No newline at end of file From a2f83e2ced8727da3d8448513be0ab689379ebbe Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 10 Aug 2015 20:50:29 +0200 Subject: [PATCH 03/85] Creates style guide html --- doc/style-guide.html | 484 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 484 insertions(+) create mode 100644 doc/style-guide.html diff --git a/doc/style-guide.html b/doc/style-guide.html new file mode 100644 index 00000000000..bbc2578b88a --- /dev/null +++ b/doc/style-guide.html @@ -0,0 +1,484 @@ + + + + + gobierno abierto | Guía de estilo web + + + + + + + + + + + +
+

gobierno abierto Guía de estilo web

+ + + +
+

1. Introducción

+

¡Hola! hemos creado algunas directrices de cómo usar el diseño en los diferentes elementos.

+

IMPORTANTE
Esta guía de estilo no es definitiva ya que irá creciendo junto al proyecto, por lo que algunos elementos pueden tener modificaciones en el futuro.

+

En este proyecto para el maquetar el front utilizamos como base el framework Foundation. Puedes leer toda su documentación pero te recomendamos que leas con atención los siguientes enlaces, ya que resumen muy bien el funcionamiento del framework:

+ +

Para desarrollar el CSS utilizamos SASS. Si clonas el repositorio verás la siguiente estructura en las hojas de estilo:

+ +
    +
  • application.sccs hace un @import del resto de SCSS para compilarlos en un solo fichero.
  • +
  • debates.sccs todos los estilos relacionados con la sección de debates.
  • +
  • fonts.sccs desde aquí se important todas las fuentes.
  • +
  • foundation_and_overrides.sccs fichero SCSS de Foundation con todas sus variables por defecto.
  • +
  • icons.sccs fuente de iconos personalizada para el proyecto, creada en Fontastic.me.
  • +
  • variables.sccs lista de variables para utilizar en el resto de SCSS.
  • +
+ +

2. Tipografía

+

La fuente que utilizamos para el texto es Open Sans y utlizamos Lato para el logotipo: gobierno abierto

+ +

Heading 1

+ h1 {font-size: 32px;} + +

Heading 2

+ h2 {font-size: 24px;} + +

Heading 3

+ h3 {font-size: 18px;} + +

Heading 4

+ h4 {font-size: 16px;} + +
Heading 5
+ h5 {font-size: 14px;} + +
Heading 6
+ h6 {font-size: 13px;} + +

Ejemplo de texto

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.

+ + p {font-size: 13px; line-height: 24px;} + +

3. Enlaces

+

Los enlaces sobre fondo blanco utilizan el color #2895F1; y al hacer hover cambian al color #2178BF; Ejemplo: Esto es un enlace

+ +

Los enlaces sobre fondo oscuro utilizan el color #FFFFF;/white y al hacer hover cambian al color #2178BF; Ejemplo: Esto es un enlace

+ +

4. Botones

+ +

Utilizamos los botones con bordes redondeados por defecto en Foundation, en varios tamaños.

+ +

Botones expandidos

+ Button default + class="button radius expand"> +

+ Button success + class="button radius success expand" +

+ Button secondary + class="button radius secondary expand"> +

+ Button alert + class="button radius alert expand" + +

Botones normales

+ Button default + class="button radius"> +
+ Button success + class="button radius success" +
+ Button secondary + class="button radius secondary"> +
+ Button alert + class="button radius alert" + +

Botones pequeños

+ Button default + class="button radius small"> +
+ Button success + class="button radius small success" +
+ Button secondary + class="button radius small secondary"> +
+ Button alert + class="button radius small alert" + +

5. Formularios

+ +
+
+
+ + Mensaje de información para rellenar el campo + + + + + + + +
+
+ form { background: #F8F8F8; height: 48px; margin-bottom: 16px; } +
+ +

6. Colores

+
+
+ background
#EDEFF0
+
+
+ border
#DEE0E3
+
+
+ brand
#0077B9
+
+
+ check
#46DB91
+
+
+ debates
#008CCF
+
+ +
+ comments-bg
#F1F1F1
+
+
+ comments-info
#A5B2B9
+
+
+ comments-text
#3F4549
+
+ +
+ header-color
#292B33
+
+ +
+ link
#2895F1
+
+ +
+ link-hover
#2178BF
+
+ +
+ tags-bg
#FAFAFA
+
+ +
+ tags-border
#F0F0F0
+
+ +
+ tags-color
#8F8F8F
+
+ +
+ text-color
#222222
+
+ +
+ text-medium
#999999
+
+ +
+ text-light
#A3A6AD
+
+ +
+ votes
#31708f
+
+ +
+ votes-bg
#26AEEE
+
+ +
+ votes-border
#1F94CB
+
+ +
+ votes-like
#7BD2A8
+
+ +
+ votes-like-act
#5D9E7F
+
+ +
+ votes-neutral
#CCCCCC
+
+ +
+ votes-text
#FFFFFF
+
+ +
+ votes-unlike
#EF8585
+
+ +
+ votes-unlike-act
#BD6A6A
+
+
+ +

7. Alertas

+ +
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
+ class="alert-bx radius success" +

+
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
+ class="alert-bx radius info" +

+
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
+ class="alert-bx radius alert" +

+
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
+ class="alert-bx radius warning" +

+
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
+ class="alert-bx radius secondary" + +
+
+ + \ No newline at end of file From 3f27458ce211d32f5b6aeb3ca7ae8abe73029432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 11 Aug 2015 10:42:19 +0200 Subject: [PATCH 04/85] updates dependencies makes gemnasium happy --- Gemfile.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9b4dc71a570..ad49450cb35 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,7 +44,7 @@ GEM awesome_nested_set (>= 3.0) acts_as_votable (0.10.0) addressable (2.3.8) - arel (6.0.2) + arel (6.0.3) awesome_nested_set (3.0.2) activerecord (>= 4.0.0, < 5) bcrypt (3.1.10) @@ -75,7 +75,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - ckeditor (4.1.2) + ckeditor (4.1.3) cocaine orm_adapter (~> 0.5.0) climate_control (0.0.3) @@ -100,7 +100,7 @@ GEM thor (~> 0.19.1) database_cleaner (1.4.1) debug_inspector (0.0.2) - devise (3.5.1) + devise (3.5.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) @@ -128,19 +128,19 @@ GEM foundation-rails (5.5.2.1) railties (>= 3.1.0) sass (>= 3.3.0, < 3.5) - globalid (0.3.5) + globalid (0.3.6) activesupport (>= 4.1.0) highline (1.7.3) http-cookie (1.0.2) domain_name (~> 0.5) i18n (0.7.0) - i18n-tasks (0.8.6) - activesupport + i18n-tasks (0.8.7) + activesupport (>= 2.3.18) easy_translate (>= 0.5.0) erubis - highline + highline (>= 1.7.3) i18n - term-ansicolor + term-ansicolor (>= 1.3.2) terminal-table (>= 1.5.1) jquery-rails (4.0.4) rails-dom-testing (~> 1.0) @@ -160,7 +160,7 @@ GEM mime-types (>= 1.16, < 3) mime-types (2.6.1) mini_portile (0.6.2) - minitest (5.7.0) + minitest (5.8.0) multi_json (1.11.2) net-scp (1.2.1) net-ssh (>= 2.6.5) @@ -211,15 +211,15 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) - rspec-core (3.3.1) + rspec-core (3.3.2) rspec-support (~> 3.3.0) - rspec-expectations (3.3.0) + rspec-expectations (3.3.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) - rspec-mocks (3.3.1) + rspec-mocks (3.3.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) - rspec-rails (3.3.2) + rspec-rails (3.3.3) actionpack (>= 3.0, < 4.3) activesupport (>= 3.0, < 4.3) railties (>= 3.0, < 4.3) From f36f408f63cf6f6457b31de76e9e4d2533237651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 11 Aug 2015 10:57:48 +0200 Subject: [PATCH 05/85] fixes votes in debates' show Closes #135 --- app/views/debates/show.html.erb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 36622951a29..6425151859d 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -12,10 +12,12 @@

<%= social_share_button_tag(@debate.title) %>

-
+

<%= t("votes.supports") %>

- <%= render 'debates/votes', debate: @debate %> +
+ <%= render 'debates/votes', debate: @debate %> +
<% if user_signed_in? %> <%= link_to t("debates.show.leave_comment"), "#comments", class: "leave-comment" %> <% else %> From d7931f3d74eaabd18bbb9aa95b11e0dc56b92cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 11 Aug 2015 11:18:49 +0200 Subject: [PATCH 06/85] adds ImageMagick to README --- README.md | 2 +- README_EN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66c1853dcd6..8ac64fe1191 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Las herramientas utilizadas para el frontend no están cerradas aún. Los estilo ## Configuración para desarrollo y tests -Prerequisitos: tener instalado git, Ruby 2.2.2, la gema `bundler`, y una librería moderna de PostgreSQL. +Prerequisitos: tener instalado git, ImageMagick, Ruby 2.2.2, la gema `bundler`, y una librería moderna de PostgreSQL. ``` cd participacion diff --git a/README_EN.md b/README_EN.md index b1b1521ffa9..6352281503f 100644 --- a/README_EN.md +++ b/README_EN.md @@ -21,7 +21,7 @@ Frontend tools used include [SCSS](http://sass-lang.com/) over [Foundation](http ## Configuration for development and test environments -Prerequisites: install git, Ruby 2.2.2, bundler gem and PostgreSQL. +Prerequisites: install git, ImageMagick, Ruby 2.2.2, bundler gem and PostgreSQL. ``` cd participacion From f9e0dad7a2545323d1e744d9ba6d99ff51e4a042 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 11 Aug 2015 12:00:54 +0200 Subject: [PATCH 07/85] Adds links on comments title --- app/assets/stylesheets/debates.scss | 15 ++++++++++++++- app/assets/stylesheets/participacion.scss | 8 ++++++++ app/assets/stylesheets/variables.scss | 6 +++--- app/views/debates/_debate.html.erb | 3 +-- app/views/debates/_featured_debate.html.erb | 3 +-- app/views/debates/show.html.erb | 4 ++-- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss index 8e68dc5bb59..188b3bee485 100644 --- a/app/assets/stylesheets/debates.scss +++ b/app/assets/stylesheets/debates.scss @@ -13,7 +13,7 @@ @mixin votes { border-top: 1px solid $votes-border; padding: rem-calc(14) rem-calc(12); - background: $votes-background; + background: $votes-bg; margin: 0 -12px; .icon-like { @@ -178,6 +178,10 @@ font-size: rem-calc(16); vertical-align: top; } + + a { + color: $text-light; + } } .debate-description { @@ -320,6 +324,10 @@ line-height: $line-height*2; text-align: justify; + a { + color: $text-light; + } + .bullet { color: $border; } @@ -369,6 +377,11 @@ display: inline-block; margin-top: $line-height; } + + .tags { + display: block; + margin-top: $line-height; + } } // 04. New diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 09518ad238c..7705a8372cc 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -73,6 +73,14 @@ p { margin-bottom: $line-height/2; } +a { + color: $link; + + &:hover { + color: $link-hover; + } +} + .button { padding: rem-calc(15) rem-calc(32); } diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss index 6251d669daa..74f0f2bfbaf 100644 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -27,7 +27,7 @@ $comments-text: #3F4549; $header-color: #292B33; $link: #2895F1; -$link-hover: #2178BF; +$link-hover: #2178BF; $tags-bg: #FAFAFA; $tags-border: #F0F0F0; @@ -38,7 +38,7 @@ $text-medium: #999999; $text-light: #A3A6AD; $votes: #31708f; -$votes-background: #26AEEE; +$votes-bg: #26AEEE; $votes-border: #1F94CB; $votes-like: #7BD2A8; $votes-like-act: #5D9E7F; @@ -59,7 +59,7 @@ $success-bg: #DFF0D8; $success-border: #D6E9C6; $success-color: #3C763D; -$info-bg: #D9EDF7; +$info-bg: #D9EDF7; $info-border: #BCE8F1; $info-color: #31708F; diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index f31328ec9c0..207584fcb6f 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -9,8 +9,7 @@

<%= link_to debate.title, debate %>

  - <%= pluralize(debate.comment_threads.count, - t("debates.debate.comment"), t("debates.debate.comments")) %> + <%= link_to pluralize(debate.comment_threads.count, t("debates.debate.comment"), t("debates.debate.comments")), debate_path(debate, anchor: "comments") %>

<%= link_to debate.description, debate %> diff --git a/app/views/debates/_featured_debate.html.erb b/app/views/debates/_featured_debate.html.erb index 602b3d603d5..fc175fff8ee 100644 --- a/app/views/debates/_featured_debate.html.erb +++ b/app/views/debates/_featured_debate.html.erb @@ -8,8 +8,7 @@

<%= link_to featured_debate.title, featured_debate %>

  - <%= pluralize(featured_debate.comment_threads.count, - t("debates.show.comment"), t("debates.show.comments")) %> + <%= link_to pluralize(featured_debate.comment_threads.count, t("debates.show.comment"), t("debates.show.comments")), debate_path(featured_debate, anchor: "comments") %>

<%= link_to featured_debate.description, featured_debate %> diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 6425151859d..9ec936163d5 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -4,11 +4,11 @@  <%= link_to t("debates.show.back_link"), debates_path, class: 'left back' %>
<%= image_tag('user_default.jpg', class: 'author-photo', size: '32x32') %> - <%= @debate.author.name %> •  <%= l @debate.created_at.to_date %>  •  <%= pluralize(@debate.comment_threads.count, t("debates.show.comment"), t("debates.show.comments")) %> + <%= @debate.author.name %> •  <%= l @debate.created_at.to_date %>  •  <%= link_to pluralize(@debate.comment_threads.count, t("debates.show.comment"), t("debates.show.comments")), "#comments" %>

<%= @debate.title %>

<%= @debate.description %> -

<%= render 'shared/tags', debate: @debate %>

+ <%= render 'shared/tags', debate: @debate %>

<%= social_share_button_tag(@debate.title) %>

From d5c27b36d5fe5dc17120ea37ccfea78418080c76 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 11 Aug 2015 13:16:24 +0200 Subject: [PATCH 08/85] Improves styles for debate show and comments --- app/assets/stylesheets/debates.scss | 42 +++++++++++++++++++++++----- app/views/comments/_comment.html.erb | 40 ++++++++++++++------------ app/views/comments/_votes.html.erb | 16 ++++++++--- app/views/debates/show.html.erb | 14 ++++++---- 4 files changed, 78 insertions(+), 34 deletions(-) diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss index 188b3bee485..3d59bf61853 100644 --- a/app/assets/stylesheets/debates.scss +++ b/app/assets/stylesheets/debates.scss @@ -354,10 +354,17 @@ font-weight: bold; } + .sidebar { + border-top: 1px solid $border; + } + h3 { - border-bottom: 2px solid $votes-border; - font-size: rem-calc(18); - margin: 0; + border-top: 1px solid $votes-border; + display: inline-block; + font-family: $font-family-sans-serif; + font-size: rem-calc(16); + margin: -1px 0 rem-calc(12); + padding-top: rem-calc(6); text-transform: uppercase; } @@ -456,12 +463,24 @@ p { color: $comments-text; - font-size: rem-calc(15); margin-bottom: 0; } - a { + .comment-votes { color: $comments-info; + font-weight: lighter; + margin: rem-calc(15) rem-calc(6) 0; + + a { + color: $comments-info; + display: inline-block; + vertical-align: top; + } + + [class^="icon-"] { + font-size: rem-calc(20); + vertical-align: top; + } } .user-photo { @@ -469,7 +488,7 @@ display: inline-block; height: 32px; line-height: $line-height*2; - margin-right: $line-height/4; + margin-right: rem-calc(6); vertical-align: top; width: 32px; } @@ -478,13 +497,17 @@ margin-left: $line-height*1.6; .reply { + background: white; + border: 1px solid $border; font-size: rem-calc(12); font-weight: lighter; + margin: rem-calc(6) 0; + padding: rem-calc(6); } } .comment-children { - border-left: 1px dotted $border; + border-left: 1px dashed $border; margin-left: $line-height*1.6; padding-left: $line-height/4; @@ -498,6 +521,11 @@ font-size: rem-calc(13); font-weight: lighter; vertical-align: middle; + + span { + color: $text-color; + font-weight: bold; + } } } } \ No newline at end of file diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 6e4e02f19b0..f8eb903a2a3 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,25 +1,29 @@
-
+
- <%= image_tag('user_default_2.jpg', class: 'user-photo left', size: '32x32') %> + <%= image_tag('user_default_2.jpg', class: 'user-photo left', size: '32x32') %> -
- - <%= comment.user.name %> • <%= time_ago_in_words(comment.created_at) %> - -

<%= comment.body %>

+
+ + <%= comment.user.name %> • <%= time_ago_in_words(comment.created_at) %> + +

<%= comment.body %>

- - <%= render 'comments/votes', comment: comment %> - + + <%= render 'comments/votes', comment: comment %> + - <% if user_signed_in? %> -

<%= render 'comments/form', {parent: comment, toggeable: true} %>

- <% end %> -
+

+ númerototal respuestas + <% if user_signed_in? %> +  |  + <%= render 'comments/form', {parent: comment, toggeable: true} %>

+ <% end %> +
-
- <%= render comment.children %> -
-
+
+ <%= render comment.children %> +
+ +
\ No newline at end of file diff --git a/app/views/comments/_votes.html.erb b/app/views/comments/_votes.html.erb index 2f92ff246c1..4763388b36c 100644 --- a/app/views/comments/_votes.html.erb +++ b/app/views/comments/_votes.html.erb @@ -1,11 +1,19 @@ + + númerototal votos + + |  - <%= link_to "up", vote_comment_path(comment, value: 'yes'), - method: "post", remote: true %> + <%= link_to vote_comment_path(comment, value: 'yes'), + method: "post", remote: true do %> + + <% end %> <%= comment.get_likes.size %> - <%= link_to "down", vote_comment_path(comment, value: 'no'), - method: "post", remote: true %> + <%= link_to vote_comment_path(comment, value: 'no'), + method: "post", remote: true do %> + + <% end %> <%= comment.get_dislikes.size %> \ No newline at end of file diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 9ec936163d5..d10d0e0224c 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -2,17 +2,22 @@
 <%= link_to t("debates.show.back_link"), debates_path, class: 'left back' %> +

<%= @debate.title %>

+
<%= image_tag('user_default.jpg', class: 'author-photo', size: '32x32') %> <%= @debate.author.name %> •  <%= l @debate.created_at.to_date %>  •  <%= link_to pluralize(@debate.comment_threads.count, t("debates.show.comment"), t("debates.show.comments")), "#comments" %>
-

<%= @debate.title %>

+ <%= @debate.description %> + <%= render 'shared/tags', debate: @debate %> +

<%= social_share_button_tag(@debate.title) %>

-
+
@@ -45,4 +49,4 @@ <%= link_to t("debates.show.edit_debate_link"), edit_debate_path(@debate), :class => 'button radius right' %> <% end %>
- + \ No newline at end of file From 4dd7e14ac43ce1e5d1ed4ee055c4916639adee21 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 10 Aug 2015 21:25:04 +0200 Subject: [PATCH 09/85] moves featured debates to home page --- app/controllers/application_controller.rb | 3 + app/controllers/debates_controller.rb | 4 - app/controllers/welcome_controller.rb | 9 ++ app/views/debates/_debate.html.erb | 2 +- app/views/debates/index.html.erb | 3 - app/views/layouts/_header.html.erb | 2 +- .../_featured_debate.html.erb | 0 app/views/welcome/index.html.erb | 13 +++ config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/routes.rb | 2 +- spec/features/debates_spec.rb | 9 -- spec/features/home_spec.rb | 15 +++ spec/features/votes_spec.rb | 107 +++++++++++++----- 14 files changed, 122 insertions(+), 51 deletions(-) create mode 100644 app/controllers/welcome_controller.rb rename app/views/{debates => welcome}/_featured_debate.html.erb (100%) create mode 100644 app/views/welcome/index.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 083165303be..550fbcf2eb7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,4 +37,7 @@ def set_layout end end + def set_voted_values(debates_ids) + @voted_values = current_user ? current_user.votes_on_debates(debates_ids) : {} + end end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 84f7d11a44c..cca1e89a2d8 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -9,7 +9,6 @@ def index else @debates = Debate.all.order("created_at DESC") set_voted_values @debates.map(&:id) - @featured_debates = @debates.to_a.shift(3) end end @@ -54,7 +53,4 @@ def debate_params params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service, :captcha, :captcha_key) end - def set_voted_values(debates_ids) - @voted_values = current_user ? current_user.votes_on_debates(debates_ids) : {} - end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 00000000000..70498a70c53 --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,9 @@ +class WelcomeController < ApplicationController + skip_authorization_check + + def index + @featured_debates = Debate.order("created_at DESC").limit(3) + set_voted_values @featured_debates.map(&:id) + end + +end \ No newline at end of file diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index 207584fcb6f..0bcc2e70894 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 9f521727069..f459b656470 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -1,7 +1,4 @@
-
<%= render @debates %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 48ffa41d574..5d9cdb6659c 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -41,7 +41,7 @@

<%= t("layouts.header.open_city") %>

<%= t("layouts.header.open_city_slogan") %>

- <%= link_to t("layouts.header.create_debate"), new_debate_path, class: 'button radius' %> + <%= link_to t("layouts.header.see_all_debates"), debates_path, class: 'button radius' %>
<% end %> diff --git a/app/views/debates/_featured_debate.html.erb b/app/views/welcome/_featured_debate.html.erb similarity index 100% rename from app/views/debates/_featured_debate.html.erb rename to app/views/welcome/_featured_debate.html.erb diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 00000000000..b732760917b --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,13 @@ +
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index d552ec75e1a..d5bf385062b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,7 +9,7 @@ en: menu: Menu open_city: We are opening Madrid open_city_slogan: So the citizens can decide what kind of city they want. - create_debate: Create a debate + see_all_debates: See all debates my_account_link: My account language: Site language footer: diff --git a/config/locales/es.yml b/config/locales/es.yml index 46c4263102c..f112593701f 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -9,7 +9,7 @@ es: menu: Menú open_city: Estamos abriendo Madrid open_city_slogan: Para que todos los madrileños decidamos que ciudad queremos tener. - create_debate: Crea un debate + see_all_debates: Ver todos los debates my_account_link: Mi cuenta language: Idioma de la página footer: diff --git a/config/routes.rb b/config/routes.rb index 74179ba2a70..fc7c040b2e1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" - root 'debates#index' + root 'welcome#index' resources :debates do member do diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index d164f113b99..6265b17d7fb 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -4,18 +4,9 @@ scenario 'Index' do debates = [create(:debate), create(:debate), create(:debate)] - featured_debates = [create(:debate), create(:debate), create(:debate)] visit debates_path - expect(page).to have_selector('#featured-debates .debate-featured', count: 3) - featured_debates.each do |debate| - within('#featured-debates') do - expect(page).to have_content debate.title - expect(page).to have_css("a[href='#{debate_path(debate)}']", text: debate.description) - end - end - expect(page).to have_selector('#debates .debate', count: 3) debates.each do |debate| within('#debates') do diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index 2efa307cc12..fcad1ca249d 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -2,4 +2,19 @@ feature "Home" do + scenario 'featured debates' do + featured_debates = [create(:debate), create(:debate), create(:debate)] + + visit root_path + + expect(page).to have_selector('#featured-debates .debate-featured', count: 3) + featured_debates.each do |debate| + within('#featured-debates') do + expect(page).to have_content debate.title + expect(page).to have_css("a[href='#{debate_path(debate)}']", text: debate.description) + end + end + + end + end diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index ecb8a8b8fe8..8deb20c20f5 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -13,51 +13,100 @@ visit debate_path(@debate) end - scenario "Index show user votes on debates" do + scenario "Home shows user votes on featured debates" do debate1 = create(:debate) debate2 = create(:debate) debate3 = create(:debate) vote = create(:vote, voter: @manuela, votable: debate1, vote_flag: true) vote = create(:vote, voter: @manuela, votable: debate3, vote_flag: false) - visit debates_path + visit root_path - within("#debate_#{debate1.id}_votes") do - within(".in-favor") do - expect(page).to have_css("a.voted") - expect(page).to_not have_css("a.no-voted") + within("#featured-debates") do + within("#debate_#{debate1.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + + within(".against") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end end - within(".against") do - expect(page).to have_css("a.no-voted") - expect(page).to_not have_css("a.voted") - end - end + within("#debate_#{debate2.id}_votes") do + within(".in-favor") do + expect(page).to_not have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end - within("#debate_#{debate2.id}_votes") do - within(".in-favor") do - expect(page).to_not have_css("a.voted") - expect(page).to_not have_css("a.no-voted") + within(".against") do + expect(page).to_not have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end end - within(".against") do - expect(page).to_not have_css("a.no-voted") - expect(page).to_not have_css("a.voted") + within("#debate_#{debate3.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end + + within(".against") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end end end + end - within("#debate_#{debate3.id}_votes") do - within(".in-favor") do - expect(page).to have_css("a.no-voted") - expect(page).to_not have_css("a.voted") + scenario "Index shows user votes on debates" do + debate1 = create(:debate) + debate2 = create(:debate) + debate3 = create(:debate) + vote = create(:vote, voter: @manuela, votable: debate1, vote_flag: true) + vote = create(:vote, voter: @manuela, votable: debate3, vote_flag: false) + + visit debates_path + + within("#debates") do + within("#debate_#{debate1.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + + within(".against") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end end - within(".against") do - expect(page).to have_css("a.voted") - expect(page).to_not have_css("a.no-voted") + within("#debate_#{debate2.id}_votes") do + within(".in-favor") do + expect(page).to_not have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + + within(".against") do + expect(page).to_not have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end end - end + within("#debate_#{debate3.id}_votes") do + within(".in-favor") do + expect(page).to have_css("a.no-voted") + expect(page).to_not have_css("a.voted") + end + + within(".against") do + expect(page).to have_css("a.voted") + expect(page).to_not have_css("a.no-voted") + end + end + end end scenario 'Show no votes' do @@ -114,7 +163,7 @@ end scenario 'Create from debate featured', :js do - visit debates_path + visit root_path within("#featured-debates") do find('.in-favor a').click @@ -131,15 +180,13 @@ expect(page).to have_content "1 vote" end - expect(URI.parse(current_url).path).to eq(debates_path) + expect(URI.parse(current_url).path).to eq(root_path) end scenario 'Create from debate index', :js do - 3.times { create(:debate) } visit debates_path within("#debates") do - expect(page).to have_css(".debate", count: 1) find('.in-favor a').click From 3cddc1070a4dbaef690333f1e0e0e705cbe45983 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 11 Aug 2015 17:40:27 +0200 Subject: [PATCH 10/85] Adds styles for not logged votes --- app/assets/stylesheets/debates.scss | 33 +++++++++++++++++++++++++-- app/assets/stylesheets/variables.scss | 2 ++ app/views/debates/_votes.html.erb | 5 ++++ config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss index 3d59bf61853..be1005f7411 100644 --- a/app/assets/stylesheets/debates.scss +++ b/app/assets/stylesheets/debates.scss @@ -11,10 +11,11 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - @mixin votes { - border-top: 1px solid $votes-border; - padding: rem-calc(14) rem-calc(12); background: $votes-bg; + border-top: 1px solid $votes-border; margin: 0 -12px; + padding: rem-calc(14) rem-calc(12); + position: relative; .icon-like { background: white; @@ -114,6 +115,24 @@ .divider { margin: 0 rem-calc(6); } + + .not-logged { + background: $not-logged-bg; + color: white; + height: 100%; + left: 0; + line-height: $line-height*2; + padding-top: $line-height/2; + position: absolute; + text-align: center; + top: 0; + width: 100%; + + a { + color: white; + text-decoration: underline; + } + } } // 02. Index @@ -291,6 +310,11 @@ line-height: $line-height/2; } } + + .not-logged { + line-height: $line-height; + padding-top: $line-height*1.5; + } } } @@ -378,6 +402,11 @@ float: none; line-height: $line-height; } + + .not-logged { + line-height: $line-height; + padding: $line-height; + } } .leave-comment { diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss index 74f0f2bfbaf..03ea93dfd9f 100644 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -47,6 +47,8 @@ $votes-text: #FFFFFF; $votes-unlike: #EF8585; $votes-unlike-act: #BD6A6A; +$not-logged-bg: rgba(22,99,135,.9); + // 03. Forms // - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/views/debates/_votes.html.erb b/app/views/debates/_votes.html.erb index 7f47e26492d..066f140dc4e 100644 --- a/app/views/debates/_votes.html.erb +++ b/app/views/debates/_votes.html.erb @@ -20,4 +20,9 @@ <%= pluralize(debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %> +
+ <%= t("votes.unauthenticated", + signin: link_to(t("votes.signin"), new_user_session_path), + signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> +
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index d552ec75e1a..51675f7b709 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -61,6 +61,9 @@ en: agree: I agree disagree: I disagree supports: Supports + unauthenticated: "You need to %{signin} or %{signup} before continuing." + signin: sign in + signup: sign up account: show: title: "My account" diff --git a/config/locales/es.yml b/config/locales/es.yml index 46c4263102c..ed989c9a768 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -61,6 +61,9 @@ es: agree: Estoy de acuerdo disagree: No estoy de acuerdo supports: Apoyos + unauthenticated: "Necesitas %{signin} o %{signup} para continuar." + signin: iniciar sesión + signup: registrarte account: show: title: "Mi cuenta" From 9d2bece0b30113e1e6873f5bac1a2d8b291896f6 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 11 Aug 2015 18:05:12 +0200 Subject: [PATCH 11/85] Fixes #142 --- app/assets/javascripts/comments.js.coffee | 11 +++++++---- app/views/comments/create.js.erb | 8 +++++++- spec/features/comments_spec.rb | 11 +++++++---- spec/support/common_actions.rb | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee index 7a8743f882d..452b706e78c 100644 --- a/app/assets/javascripts/comments.js.coffee +++ b/app/assets/javascripts/comments.js.coffee @@ -4,10 +4,15 @@ App.Comments = $(response_html).insertAfter($("#js-comment-form-#{parent_id}")) reset_and_hide_form: (id) -> - form = $("#js-comment-form-#{id}") - form.val('') + form = $("#js-comment-form-#{id} form") + input = form.find("textarea") + input.val('') form.hide() + reset_form: (id) -> + input = $("#js-comment-form-#{id} form textarea") + input.val('') + toggle_form: (id) -> $("#js-comment-form-#{id}").toggle() @@ -16,5 +21,3 @@ App.Comments = id = $(this).data().id App.Comments.toggle_form(id) false - - diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 9eeec31082c..f2b078195e9 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,3 +1,9 @@ var parent_id = '<%= dom_id(@parent) %>'; -App.Comments.reset_and_hide_form(parent_id); + +<% if @parent.is_a?(Debate) -%> + App.Comments.reset_form(parent_id); +<% else -%> + App.Comments.reset_and_hide_form(parent_id); +<% end -%> + App.Comments.add_response(parent_id, "<%= j(render @comment) %>"); diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 1ec6a8c107b..0cc64bce18c 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -59,6 +59,7 @@ visit debate_path(debate) click_link "Reply" + within "#js-comment-form-comment_#{comment.id}" do fill_in 'comment_body', with: 'It will be done next week.' click_button 'Publish reply' @@ -67,6 +68,8 @@ within "#comment-#{comment.id}" do expect(page).to have_content 'It will be done next week.' end + + expect(page).to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end scenario "N replies", :js do @@ -74,13 +77,13 @@ parent = create(:comment, commentable: debate) 7.times do - create(:comment, commentable: debate). - move_to_child_of(parent) - parent = parent.children.first + create(:comment, commentable: debate). + move_to_child_of(parent) + parent = parent.children.first end visit debate_path(debate) expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") end -end \ No newline at end of file +end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index b625138b0de..5e56d2ceae6 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -56,4 +56,4 @@ def correct_captcha_text SimpleCaptcha::SimpleCaptchaData.first.value end -end \ No newline at end of file +end From 44d4fa9fc422fbbeb3e5cafdef45ac4c00ff2da2 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 11 Aug 2015 20:27:37 +0200 Subject: [PATCH 12/85] order comments by the most recent first --- app/controllers/debates_controller.rb | 8 ++++---- app/models/comment.rb | 2 ++ app/views/comments/_comment.html.erb | 4 ++-- app/views/debates/_debate.html.erb | 2 +- app/views/debates/show.html.erb | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index cca1e89a2d8..2c024368193 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -4,11 +4,11 @@ class DebatesController < ApplicationController def index if params[:tag] - @debates = Debate.tagged_with(params[:tag]).order("created_at DESC") - set_voted_values @debates.map(&:id) + @debates = Debate.tagged_with(params[:tag]).order(id: :desc) + set_voted_values @debates.pluck(:id) else - @debates = Debate.all.order("created_at DESC") - set_voted_values @debates.map(&:id) + @debates = Debate.all.order(id: :desc) + set_voted_values @debates.pluck(:id) end end diff --git a/app/models/comment.rb b/app/models/comment.rb index c2cf7529223..d4ceb9e3edb 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -8,6 +8,8 @@ class Comment < ActiveRecord::Base belongs_to :commentable, polymorphic: true belongs_to :user + scope :recent, -> { order(id: :desc) } + def self.build(commentable, user, body) new commentable: commentable, user_id: user.id, diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index f8eb903a2a3..4e375c540b7 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -22,8 +22,8 @@
- <%= render comment.children %> + <%= render comment.children.reorder('id DESC, lft') %>
-
\ No newline at end of file +
diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index 0bcc2e70894..4620e12329a 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -25,4 +25,4 @@
-
\ No newline at end of file +
diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index d10d0e0224c..28fefd085a9 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -43,10 +43,10 @@ <%= render 'comments/form', {parent: @debate, toggeable: false} %>
<% end %> - <%= render @debate.root_comments %> + <%= render @debate.root_comments.recent %> <% if current_user && @debate.editable_by?(current_user) %> <%= link_to t("debates.show.edit_debate_link"), edit_debate_path(@debate), :class => 'button radius right' %> <% end %> - \ No newline at end of file + From 0541e9e93686e7e5e8101fc7f8c90fe222afe623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 11 Aug 2015 23:20:42 +0200 Subject: [PATCH 13/85] shows not-logged votes on hover if user not logged Fixes #85 --- app/assets/javascripts/application.js | 1 + app/assets/javascripts/votes.js.coffee | 15 +++++++++++++++ app/views/debates/_votes.html.erb | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/votes.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index def844e5a41..d6dedd05cca 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,6 +21,7 @@ var initialize_modules = function() { App.Comments.initialize(); + App.Votes.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/votes.js.coffee b/app/assets/javascripts/votes.js.coffee new file mode 100644 index 00000000000..5005ad5b8c0 --- /dev/null +++ b/app/assets/javascripts/votes.js.coffee @@ -0,0 +1,15 @@ +App.Votes = + + hoverize: (votes) -> + $(votes).hover -> + $("div.not-logged", votes).show() + , -> + $("div.not-logged", votes).hide() + + initialize: -> + App.Votes.hoverize votes for votes in $("div.votes") + false + + + + diff --git a/app/views/debates/_votes.html.erb b/app/views/debates/_votes.html.erb index 066f140dc4e..a15a66a4d50 100644 --- a/app/views/debates/_votes.html.erb +++ b/app/views/debates/_votes.html.erb @@ -20,9 +20,12 @@ <%= pluralize(debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %> -
+ + <% unless user_signed_in? %> + + <% end %>
\ No newline at end of file From 10588a989c1bc523f3e217ed4aef5b6d19a477b1 Mon Sep 17 00:00:00 2001 From: David Gil Date: Wed, 12 Aug 2015 00:02:19 +0200 Subject: [PATCH 14/85] revert using pluck to use map again --- app/controllers/debates_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 2c024368193..3b61becc298 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -5,10 +5,10 @@ class DebatesController < ApplicationController def index if params[:tag] @debates = Debate.tagged_with(params[:tag]).order(id: :desc) - set_voted_values @debates.pluck(:id) + set_voted_values @debates.map(&:id) else @debates = Debate.all.order(id: :desc) - set_voted_values @debates.pluck(:id) + set_voted_values @debates.map(&:id) end end From 4b501ee46be1da5c8d190a8c2ea2b53f75112016 Mon Sep 17 00:00:00 2001 From: Manuel Maldonado Date: Wed, 12 Aug 2015 01:36:42 +0200 Subject: [PATCH 15/85] Capistrano recipe --- .gitignore | 3 + Capfile | 6 +- Gemfile | 2 +- Gemfile.lock | 10 +- config/deploy-secrets.yml.example | 2 + config/deploy.rb | 38 ++++++-- config/deploy/preproduction.rb | 8 +- config/deploy/production.rb | 8 +- .../sample_config_files/apache_passenger.conf | 19 ++++ .../sample_config_files/apache_unicorn.conf | 31 ++++++ .../sample_config_files/unicorn_init.sh | 96 +++++++++++++++++++ config/deploy/shared/database.yml.erb | 10 ++ config/deploy/shared/log_rotation.erb | 11 +++ config/deploy/shared/secrets.yml.erb | 4 + config/deploy/shared/sidekiq.yml.erb | 2 + config/deploy/shared/unicorn.rb.erb | 42 ++++++++ config/deploy/staging.rb | 8 +- lib/capistrano/substitute_strings.rb | 12 +++ lib/capistrano/tasks/apache.cap | 30 ++++++ lib/capistrano/tasks/check_revision.cap | 14 +++ .../tasks/compile_assets_locally.cap | 17 ++++ lib/capistrano/tasks/logs.cap | 14 +++ lib/capistrano/tasks/restart.cap | 10 ++ lib/capistrano/tasks/run_tests.cap | 18 ++++ lib/capistrano/tasks/setup_config.cap | 27 ++++++ lib/capistrano/template.rb | 32 +++++++ 26 files changed, 452 insertions(+), 22 deletions(-) create mode 100644 config/deploy/sample_config_files/apache_passenger.conf create mode 100644 config/deploy/sample_config_files/apache_unicorn.conf create mode 100644 config/deploy/sample_config_files/unicorn_init.sh create mode 100644 config/deploy/shared/database.yml.erb create mode 100755 config/deploy/shared/log_rotation.erb create mode 100644 config/deploy/shared/secrets.yml.erb create mode 100644 config/deploy/shared/sidekiq.yml.erb create mode 100755 config/deploy/shared/unicorn.rb.erb create mode 100755 lib/capistrano/substitute_strings.rb create mode 100755 lib/capistrano/tasks/apache.cap create mode 100755 lib/capistrano/tasks/check_revision.cap create mode 100755 lib/capistrano/tasks/compile_assets_locally.cap create mode 100755 lib/capistrano/tasks/logs.cap create mode 100644 lib/capistrano/tasks/restart.cap create mode 100755 lib/capistrano/tasks/run_tests.cap create mode 100755 lib/capistrano/tasks/setup_config.cap create mode 100755 lib/capistrano/template.rb diff --git a/.gitignore b/.gitignore index 5cc51978774..339f1eb5e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ /config/deploy-secrets.yml /coverage + +# Mac finder artifacts +.DS_Store diff --git a/Capfile b/Capfile index b565fae2363..17e03a6f89d 100644 --- a/Capfile +++ b/Capfile @@ -6,9 +6,11 @@ require 'capistrano/deploy' require 'capistrano/rvm' require 'capistrano/bundler' -require 'capistrano/rails/assets' +#require 'capistrano/rails/assets' require 'capistrano/rails/migrations' -require 'capistrano/passenger' +#require 'capistrano/passenger' # Load custom tasks from `lib/capistrano/tasks` if you have any defined Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } +Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } +Dir.glob('lib/capistrano/**/*.rb').each { |r| import r } diff --git a/Gemfile b/Gemfile index afa51a69e49..edb2e190bd5 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,7 @@ gem 'simple_captcha2', require: 'simple_captcha' gem 'ckeditor' gem 'cancancan' gem 'social-share-button' +gem 'unicorn' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console @@ -49,7 +50,6 @@ group :development, :test do gem "capistrano-bundler", '1.1.4', require: false gem "capistrano-rails", '1.1.3', require: false gem "capistrano-rvm", require: false - gem "capistrano-passenger", require: false end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index ad49450cb35..a6a269d2ea8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,8 +61,6 @@ GEM capistrano-bundler (1.1.4) capistrano (~> 3.1) sshkit (~> 1.2) - capistrano-passenger (0.1.1) - capistrano (~> 3.0) capistrano-rails (1.1.3) capistrano (~> 3.1) capistrano-bundler (~> 1.1) @@ -147,6 +145,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) + kgio (2.9.3) launchy (2.4.3) addressable (~> 2.3) letter_opener (1.4.1) @@ -204,6 +203,7 @@ GEM activesupport (= 4.2.3) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.15.0) rake (10.4.2) responders (2.1.0) railties (>= 4.2.0, < 5) @@ -274,6 +274,10 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.1) + unicorn (4.9.0) + kgio (~> 2.6) + rack + raindrops (~> 0.7) warden (1.2.3) rack (>= 1.0) web-console (2.2.1) @@ -298,7 +302,6 @@ DEPENDENCIES cancancan capistrano (= 3.4.0) capistrano-bundler (= 1.1.4) - capistrano-passenger capistrano-rails (= 1.1.3) capistrano-rvm capybara @@ -326,6 +329,7 @@ DEPENDENCIES spring turbolinks uglifier (>= 1.3.0) + unicorn web-console (~> 2.0) BUNDLED WITH diff --git a/config/deploy-secrets.yml.example b/config/deploy-secrets.yml.example index b69fea22574..696f6ce7558 100644 --- a/config/deploy-secrets.yml.example +++ b/config/deploy-secrets.yml.example @@ -3,6 +3,8 @@ staging: ssh_port: 21 server: staging.participacion.madrid.es user: xxxxx + server_name: staging.participacion.madrid.es + db_server: postgre.participacion.madrid.es preproduction: deploy_to: "/var/www/participacion" diff --git a/config/deploy.rb b/config/deploy.rb index 8104d742f5c..9c45bd28389 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -8,14 +8,20 @@ def deploysecret(key) set :rails_env, fetch(:stage) set :rvm_ruby_version, '2.2.2' +set :rvm_type, :user set :application, 'participacion' -set :repo_url, 'git@github.com:AyuntamientoMadrid/participacion.git' +set :server_name, deploysecret(:server_name) +#set :repo_url, 'git@github.com:AyuntamientoMadrid/participacion.git' +# If ssh access is restricted, probably you need to use https access +set :repo_url, 'https://github.com/AyuntamientoMadrid/participacion.git' set :scm, :git set :revision, `git rev-parse --short #{fetch(:branch)}`.strip set :log_level, :info +set :pty, true +set :use_sudo, false set :linked_files, %w{config/database.yml config/secrets.yml} set :linked_dirs, %w{log tmp public/system public/assets} @@ -24,15 +30,27 @@ def deploysecret(key) set :local_user, ENV['USER'] -namespace :deploy do +# Run test before deploy +set :tests, ["spec"] + +# Config files should be copied by deploy:setup_config +set(:config_files, %w( + log_rotation + database.yml + secrets.yml + unicorn.rb + sidekiq.yml +)) - after :restart, :clear_cache do - on roles(:web), in: :groups, limit: 3, wait: 10 do - # Here we can do anything such as: - # within release_path do - # execute :rake, 'cache:clear' - # end - end - end +namespace :deploy do + # Check right version of deploy branch + before :deploy, "deploy:check_revision" + # Run test aund continue only if passed + before :deploy, "deploy:run_tests" + # Compile assets locally and then rsync + after 'deploy:symlink:shared', 'deploy:compile_assets_locally' + after :finishing, 'deploy:cleanup' + # Restart unicorn + after 'deploy:publishing', 'deploy:restart' end diff --git a/config/deploy/preproduction.rb b/config/deploy/preproduction.rb index fb9033c038f..7a18c011d95 100644 --- a/config/deploy/preproduction.rb +++ b/config/deploy/preproduction.rb @@ -1,5 +1,9 @@ set :deploy_to, deploysecret(:deploy_to) -set :branch, :production +set :server_name, deploysecret(:server_name) +set :db_server, deploysecret(:db_server) +set :branch, :master set :ssh_options, port: deploysecret(:ssh_port) +set :stage, :production +set :rails_env, :production -server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) \ No newline at end of file +server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) diff --git a/config/deploy/production.rb b/config/deploy/production.rb index fb9033c038f..7a18c011d95 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,5 +1,9 @@ set :deploy_to, deploysecret(:deploy_to) -set :branch, :production +set :server_name, deploysecret(:server_name) +set :db_server, deploysecret(:db_server) +set :branch, :master set :ssh_options, port: deploysecret(:ssh_port) +set :stage, :production +set :rails_env, :production -server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) \ No newline at end of file +server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) diff --git a/config/deploy/sample_config_files/apache_passenger.conf b/config/deploy/sample_config_files/apache_passenger.conf new file mode 100644 index 00000000000..f97fc9b2ad0 --- /dev/null +++ b/config/deploy/sample_config_files/apache_passenger.conf @@ -0,0 +1,19 @@ + + + ServerName yourdomain.com + ServerAlias www.yourdomain.com + ServerAdmin webmaster@localhost + + DocumentRoot /path/to/deploy_to/current/public + + # RailsEnv production + + ErrorLog ${APACHE_LOG_DIR}/yourdomain.error.log + CustomLog ${APACHE_LOG_DIR}/yourdomain.access.log combined + + + Options FollowSymLinks + Require all granted + + + diff --git a/config/deploy/sample_config_files/apache_unicorn.conf b/config/deploy/sample_config_files/apache_unicorn.conf new file mode 100644 index 00000000000..93aafec2342 --- /dev/null +++ b/config/deploy/sample_config_files/apache_unicorn.conf @@ -0,0 +1,31 @@ + + + ServerAdmin admin@yourdomain.com + ServerName yourdomain.com + ServerAlias www.yourdomain.com + + DocumentRoot /path/to/deploy_to/current/public + + RewriteEngine On + + + BalancerMember http://127.0.0.1:5000 + + + # Redirect all non-static requests to thin + RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f + RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L] + + ProxyPass / balancer://unicornservers/ + ProxyPassReverse / balancer://unicornservers/ + ProxyPreserveHost on + + + Order deny,allow + Allow from all + + + ErrorLog ${APACHE_LOG_DIR}/yourdomain.error.log + CustomLog ${APACHE_LOG_DIR}/yourdomain.access.log combined + + diff --git a/config/deploy/sample_config_files/unicorn_init.sh b/config/deploy/sample_config_files/unicorn_init.sh new file mode 100644 index 00000000000..1cef9110ba8 --- /dev/null +++ b/config/deploy/sample_config_files/unicorn_init.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: unicorn +# Required-Start: $local_fs $remote_fs $network $syslog +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts the unicorn web server +# Description: starts unicorn +### END INIT INFO + +set -e + +TIMEOUT=${TIMEOUT-60} +APP_ROOT=<%= current_path %> +PID_DIR=$APP_ROOT/tmp/pids +PID=$PID_DIR/unicorn.pid +CMD="cd $APP_ROOT; bundle exec unicorn -D -c /path/to/shared/config/unicorn.rb -E production" +AS_USER=deploy +set -u + +OLD_PIN="$PID.oldbin" + +sig () { + test -s "$PID" && kill -$1 `cat $PID` +} + +oldsig () { + test -s $OLD_PIN && kill -$1 `cat $OLD_PIN` +} + +workersig () { + workerpid="$APP_ROOT/tmp/pids/unicorn.$2.pid" + + test -s "$workerpid" && kill -$1 `cat $workerpid` +} + +run () { + if [ "$(id -un)" = "$AS_USER" ]; then + eval $1 + else + su -c "$1" - $AS_USER + fi +} + +case "$1" in +start) + sig 0 && echo >&2 "Already running" && exit 0 + run "$CMD" + ;; +stop) + sig QUIT && exit 0 + echo >&2 "Not running" + ;; +force-stop) + sig TERM && exit 0 + echo >&2 "Not running" + ;; +kill_worker) + workersig QUIT $2 && exit 0 + echo >&2 "Worker not running" + ;; +restart|reload) + sig USR2 && echo reloaded OK && exit 0 + echo >&2 "Couldn't reload, starting '$CMD' instead" + run "$CMD" + ;; +upgrade) + if sig USR2 && sleep 2 && sig 0 && oldsig QUIT + then + n=$TIMEOUT + while test -s $OLD_PIN && test $n -ge 0 + do + printf '.' && sleep 1 && n=$(( $n - 1 )) + done + echo + + if test $n -lt 0 && test -s $OLD_PIN + then + echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds" + exit 1 + fi + exit 0 + fi + echo >&2 "Couldn't upgrade, starting '$CMD' instead" + run "$CMD" + ;; +reopen-logs) + sig USR1 + ;; +*) + echo >&2 "Usage: $0 " + exit 1 + ;; +esac diff --git a/config/deploy/shared/database.yml.erb b/config/deploy/shared/database.yml.erb new file mode 100644 index 00000000000..2449ae6f827 --- /dev/null +++ b/config/deploy/shared/database.yml.erb @@ -0,0 +1,10 @@ +<%= fetch(:rails_env) %>: + adapter: postgresql + timeout: 5000 + encoding: unicode + reconnect: false + database: <%= "#{fetch(:application)}" %> + pool: 5 + username: + password: + host: <%= fetch(:db_server) %> diff --git a/config/deploy/shared/log_rotation.erb b/config/deploy/shared/log_rotation.erb new file mode 100755 index 00000000000..7507de18401 --- /dev/null +++ b/config/deploy/shared/log_rotation.erb @@ -0,0 +1,11 @@ +<%= fetch(:deploy_to) %>/shared/log/*.log { + daily + missingok + rotate 52 + compress + delaycompress + notifempty + sharedscripts + endscript + copytruncate +} diff --git a/config/deploy/shared/secrets.yml.erb b/config/deploy/shared/secrets.yml.erb new file mode 100644 index 00000000000..d3c3251af9a --- /dev/null +++ b/config/deploy/shared/secrets.yml.erb @@ -0,0 +1,4 @@ +<%= fetch(:rails_env) %>: + recaptcha_public_key: <%= ENV["MADRID_RECAPTCHA_PUBLIC_KEY"] %> + recaptcha_private_key: <%= ENV["MADRID_RECAPTCHA_PRIVATE_KEY"] %> + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/config/deploy/shared/sidekiq.yml.erb b/config/deploy/shared/sidekiq.yml.erb new file mode 100644 index 00000000000..1d4747933a1 --- /dev/null +++ b/config/deploy/shared/sidekiq.yml.erb @@ -0,0 +1,2 @@ +<%= fetch(:rails_env) %>: + :concurrency: <%= fetch(:sidekiq_concurrency, 5) %> diff --git a/config/deploy/shared/unicorn.rb.erb b/config/deploy/shared/unicorn.rb.erb new file mode 100755 index 00000000000..805734276da --- /dev/null +++ b/config/deploy/shared/unicorn.rb.erb @@ -0,0 +1,42 @@ +root = "<%= current_path %>" +working_directory root +pid "#{root}/tmp/pids/unicorn.pid" +stderr_path "#{root}/log/unicorn.log" +stdout_path "#{root}/log/unicorn.log" + +listen 5000 +#listen "/tmp/unicorn.<%= fetch(:application) %>.sock" +worker_processes 4 +timeout 40 +preload_app true + +# Force unicorn to look at the Gemfile in the current_path +# otherwise once we've first started a master process, it +# will always point to the first one it started. +before_exec do |server| + ENV['BUNDLE_GEMFILE'] = "<%= current_path %>/Gemfile" +end + +before_fork do |server, worker| + defined?(ActiveRecord::Base) and + ActiveRecord::Base.connection.disconnect! + # Quit the old unicorn process + old_pid = "#{server.config[:pid]}.oldbin" + if File.exists?(old_pid) && server.pid != old_pid + puts "We've got an old pid and server pid is not the old pid" + begin + Process.kill("QUIT", File.read(old_pid).to_i) + puts "killing master process (good thing tm)" + rescue Errno::ENOENT, Errno::ESRCH + puts "unicorn master already killed" + end + end +end + +after_fork do |server, worker| + port = 5000 + worker.nr + child_pid = server.config[:pid].sub('.pid', ".#{port}.pid") + system("echo #{Process.pid} > #{child_pid}") + defined?(ActiveRecord::Base) and + ActiveRecord::Base.establish_connection +end diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 5ca436c4297..09ba7401a98 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,7 +1,11 @@ set :deploy_to, deploysecret(:deploy_to) +set :server_name, deploysecret(:server_name) +set :db_server, deploysecret(:db_server) set :branch, :master set :ssh_options, port: deploysecret(:ssh_port) - -set :passenger_restart_with_sudo, false +set :stage, :staging +set :rails_env, :staging server deploysecret(:server), user: deploysecret(:user), roles: %w(web app db importer) + + diff --git a/lib/capistrano/substitute_strings.rb b/lib/capistrano/substitute_strings.rb new file mode 100755 index 00000000000..d4b244323fe --- /dev/null +++ b/lib/capistrano/substitute_strings.rb @@ -0,0 +1,12 @@ +# we often want to refer to variables which +# are defined in subsequent stage files. This +# let's us use the {{var}} to represent fetch(:var) +# in strings which are only evaluated at runtime. + +def sub_strings(input_string) + output_string = input_string + input_string.scan(/{{(\w*)}}/).each do |var| + output_string.gsub!("{{#{var[0]}}}", fetch(var[0].to_sym)) + end + output_string +end diff --git a/lib/capistrano/tasks/apache.cap b/lib/capistrano/tasks/apache.cap new file mode 100755 index 00000000000..3dfbced57fa --- /dev/null +++ b/lib/capistrano/tasks/apache.cap @@ -0,0 +1,30 @@ +namespace :apache do + %w(start stop restart reload).each do |task_name| + desc "#{task } Apache" + task task_name do + on roles(:app), in: :sequence, wait: 5 do + sudo "/etc/init.d/apache2 #{task_name}" + end + end + end + + desc "Enable site virual host" + task "enable_virtual_host" do + on roles(:app) do + "cd /etc/apache2/sites-available/" + sudo "a2ensite #{fetch(:server_name)}" + end + end + + desc "Remove default Apache Virtual Host" + task "remove_default_vhost" do + on roles(:app) do + if test("[ -f /etc/apache2/sites-enabled/000-default.conf ]") + sudo "rm /etc/apache2/sites-enabled/000-default.conf" + puts "removed default Apache Virtualhost" + else + puts "No default Apache Virtualhost to remove" + end + end + end +end diff --git a/lib/capistrano/tasks/check_revision.cap b/lib/capistrano/tasks/check_revision.cap new file mode 100755 index 00000000000..12cf3390db8 --- /dev/null +++ b/lib/capistrano/tasks/check_revision.cap @@ -0,0 +1,14 @@ +namespace :deploy do + desc "checks whether the currently checkout out revision matches the + remote one we're trying to deploy from" + task :check_revision do + branch = fetch(:branch) + unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}` + puts "WARNING: HEAD is not the same as origin/#{branch}" + puts "Run `git push` to sync changes or make sure you've" + puts "checked out the branch: #{branch} as you can only deploy" + puts "if you've got the target branch checked out" + exit + end + end +end diff --git a/lib/capistrano/tasks/compile_assets_locally.cap b/lib/capistrano/tasks/compile_assets_locally.cap new file mode 100755 index 00000000000..5966ff1ead8 --- /dev/null +++ b/lib/capistrano/tasks/compile_assets_locally.cap @@ -0,0 +1,17 @@ +namespace :deploy do + desc "compiles assets locally then rsyncs" + task :compile_assets_locally do + run_locally do + execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:precompile" + end + on roles(:app) do |role| + run_locally do + execute"rsync -av ./public/assets/ #{role.user}@#{role.hostname}:#{release_path}/public/assets/;" + end + "chmod -R 755 #{release_path}/public/assets/" + end + run_locally do + execute "rm -rf ./public/assets" + end + end +end diff --git a/lib/capistrano/tasks/logs.cap b/lib/capistrano/tasks/logs.cap new file mode 100755 index 00000000000..7bbfac2e45f --- /dev/null +++ b/lib/capistrano/tasks/logs.cap @@ -0,0 +1,14 @@ +namespace :logs do + task :tail, :file do |t, args| + if args[:file] + on roles(:app) do + execute "tail -f #{shared_path}/log/#{args[:file]}.log" + end + else + puts "please specify a logfile e.g: 'rake logs:tail[logfile]" + puts "will tail 'shared_path/log/logfile.log'" + puts "remember if you use zsh you'll need to format it as:" + puts "rake 'logs:tail[logfile]' (single quotes)" + end + end +end diff --git a/lib/capistrano/tasks/restart.cap b/lib/capistrano/tasks/restart.cap new file mode 100644 index 00000000000..ff8c028f030 --- /dev/null +++ b/lib/capistrano/tasks/restart.cap @@ -0,0 +1,10 @@ +namespace :deploy do + desc 'Commands for unicorn application' + %w(start stop force-stop restart upgrade reopen-logs).each do |command| + task command.to_sym do + on roles(:app), in: :sequence, wait: 5 do + sudo "/etc/init.d/unicorn_#{fetch(:full_app_name)} #{command}" + end + end + end +end diff --git a/lib/capistrano/tasks/run_tests.cap b/lib/capistrano/tasks/run_tests.cap new file mode 100755 index 00000000000..32f26f9cee7 --- /dev/null +++ b/lib/capistrano/tasks/run_tests.cap @@ -0,0 +1,18 @@ +namespace :deploy do + desc "Runs test before deploying, can't deploy unless they pass" + task :run_tests do + test_log = "log/capistrano.test.log" + tests = fetch(:tests) + tests.each do |test| + puts "--> Running tests: '#{test}', please wait ..." + unless system "bundle exec rspec #{test} > #{test_log} 2>&1" + puts "--> Tests: '#{test}' failed. Results in: #{test_log} and below:" + system "cat #{test_log}" + exit; + end + puts "--> '#{test}' passed" + end + puts "--> All tests passed" + system "rm #{test_log}" + end +end diff --git a/lib/capistrano/tasks/setup_config.cap b/lib/capistrano/tasks/setup_config.cap new file mode 100755 index 00000000000..27ba96a1251 --- /dev/null +++ b/lib/capistrano/tasks/setup_config.cap @@ -0,0 +1,27 @@ +namespace :deploy do + task :setup_config do + on roles(:app) do + # make the config dir + execute :mkdir, "-p #{shared_path}/config" + full_app_name = fetch(:full_app_name) + + # config files to be uploaded to shared/config, see the + # definition of smart_template for details of operation. + # Essentially looks for #{filename}.erb in deploy/#{full_app_name}/ + # and if it isn't there, falls back to deploy/#{shared}. Generally + # everything should be in deploy/shared with params which differ + # set in the stage files + config_files = fetch(:config_files) + config_files.each do |file| + smart_template file + end + + # symlink stuff which should be... symlinked + symlinks = fetch(:symlinks) + + symlinks.each do |symlink| + sudo "ln -nfs #{shared_path}/config/#{symlink[:source]} #{sub_strings(symlink[:link])}" + end + end + end +end diff --git a/lib/capistrano/template.rb b/lib/capistrano/template.rb new file mode 100755 index 00000000000..07bd0be37e2 --- /dev/null +++ b/lib/capistrano/template.rb @@ -0,0 +1,32 @@ +# will first try and copy the file: +# config/deploy/#{full_app_name}/#{from}.erb +# to: +# shared/config/to +# if the original source path doesn exist then it will +# search in: +# config/deploy/shared/#{from}.erb +# this allows files which are common to all enviros to +# come from a single source while allowing specific +# ones to be over-ridden +# if the target file name is the same as the source then +# the second parameter can be left out +def smart_template(from, to=nil) + to ||= from + full_to_path = "#{shared_path}/config/#{to}" + if from_erb_path = template_file(from) + from_erb = StringIO.new(ERB.new(File.read(from_erb_path)).result(binding)) + upload! from_erb, full_to_path + info "copying: #{from_erb} to: #{full_to_path}" + else + error "error #{from} not found" + end +end + +def template_file(name) + if File.exist?((file = "config/deploy/#{fetch(:full_app_name)}/#{name}.erb")) + return file + elsif File.exist?((file = "config/deploy/shared/#{name}.erb")) + return file + end + return nil +end From 94dc53e68cb83a9de9509e575c52b442afd9cfb8 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 11 Aug 2015 19:53:18 +0200 Subject: [PATCH 16/85] Improves styles for account page, adds user avatar --- app/assets/stylesheets/participacion.scss | 5 +++++ app/views/account/show.html.erb | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 7705a8372cc..7469007b376 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -457,12 +457,17 @@ form { opacity: .5; } + .avatar { + margin-bottom: $line-height; + } + h2 { clear: both; font-size: rem-calc(20); font-weight: bold; line-height: $line-height; margin: 0; + margin-bottom: $line-height/2; } .recommendations { diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 185af445b0c..6a2d6d416ed 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -35,7 +35,11 @@ <% end %> -
+
+

<%= t("account.show.avatar")%>

+ <%= image_tag('user_default_big.jpg', class: "avatar", size: "100x100") %> + +

<%= t("account.show.notifications")%>

<%= f.label :email_on_debate_comment do %> <%= f.check_box :email_on_debate_comment %> <%= t("account.show.email_on_debate_comment_label") %> From 502920c7f2cdaaeab909935afcbb0a9715c39c13 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 11 Aug 2015 19:53:18 +0200 Subject: [PATCH 17/85] Improves styles for account page, adds user image --- app/assets/images/user_default_big.jpg | Bin 0 -> 2084 bytes app/assets/stylesheets/participacion.scss | 7 ++++++- app/views/account/show.html.erb | 20 ++++++------------- app/views/devise/registrations/edit.html.erb | 2 +- config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ 6 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 app/assets/images/user_default_big.jpg diff --git a/app/assets/images/user_default_big.jpg b/app/assets/images/user_default_big.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d1c5bcea2fbe94ebf3f33971870ae2590cb7609b GIT binary patch literal 2084 zcmex=G?WUP)qwZeFo6%mkOz;^d;tf|AVqJOz-6iAnjTCALaHmqNUdTL3o}Ygi#E^!3HB zG&dI%0AOQ_OM+4n?!{_waY$uBs(w&vaeir0aw<@{GDvfQm2**QVo82cNPd0}EEEGW z@=NlIGx7@*oSng;rl8@Qn4Fmh64V6i^7Xay%quQQ%u7!7bg@+enxmJQnPO#T=IG{T zXkct?VdiFN=xXX@U}EHAXk=(;W@u<`Vrm4_>yn>bnwy$e0@Is<&})KIFDOCe765H_ zNiE7OOHFYr%Fk5*d)z7$w_6Nxng`XJg4-=dIQ8lS9itD5UZm)T2?5g(hzU=;Kn^_l zr{)3Ed=W5l|9{882TrmKDF=X=i1Ghzh86}k78Vv(7B*H^HcmDm=H_5yEDnV4Bw zIboU@nV4Bv1=$pZ*bN;M8-)WGDs46|bSj#(=+GtQVsSyBL5z&d?A)wK>IEBFSU)Hl zZagSt~TfWlgpxzB`7 z>&BaBCwu*xwbD=Yy56ksSx+XX7*F@S?ApxF^#1YM=PKcQ<>If-EvdV@W!lT*Wz{AFX1eCu zzjd+e#NM5Icj{5u^^)}bLf@A`Q$2Qg=^wRInP|1gXU1F4cehNY3F|^#Eb{j2m-QJx zYqmN1%dENM|EA#0D<99R)BY*j&O98W-4pvX+H2*jzm_#de*)`yrngM&T;uP(nCr#eYty{`*>@wA8DR9`95xyOBee7^N8^U4EYt5~gTYqf9L#p_N8KCW#p z{9DG_YO+vi3iHyJTRFq-M`XBfjnVuW+&%ld%VqVpxal10c3-uv?VYzKv^Q?S)2DJr zwG2MDauwEnNfvLD{C)F zX}aV&e_r>4sIu(~*`l-0a+@>V-8Uz?V!vs&%-zj5<~-eGx~bB8Pj8-R-fO=t*LJ;l z<$2om!PX12lszuSpPyBfvi13QzqQU94q%(PO>5Mwi%UM|Md+NJ+na5bwbV6gN%UiJ zxwyEL%a*(E-u8N$du#W(mtAvzUCS1{@}d4o#E<1#vp36f6+YH1c5jOPlcik0_C-M* z+s4bY_H5g9;r3j$1DS=>&e^=Js@icYO8@oj*z=c*zhCj}-1>ZxN!sjX51XHzoczjv zmX+;&Svk2MuXLY1TJA5O>6pBs?3b3A$(NWrdz7A^n)L9l=)sEF!E*Dqiwi#5c29X{ Z#Jk7+>c<~E?v#VL91?Iuk<9;Z0st%4&z=AP literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 7469007b376..2b9cfd9836d 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -370,12 +370,16 @@ form { line-height: $line-height; } - input[type]:not([type=submit]) { + input[type]:not([type=submit]):not([type=file]) { background: $input-bg; height: $line-height*2; margin-bottom: rem-calc(16); } + input[type=file] { + margin: rem-calc(12) 0; + } + .note { display: block; font-size: rem-calc(13); @@ -390,6 +394,7 @@ form { .checkbox { display: inline-block; font-size: rem-calc(14); + font-weight: normal; line-height: $line-height*2; margin: 0 0 0 rem-calc(6); vertical-align: top; diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 6a2d6d416ed..6d1f4d9cd58 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -1,6 +1,8 @@