diff --git a/Gemfile b/Gemfile index edb2e190b..b52642871 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,7 @@ gem 'simple_captcha2', require: 'simple_captcha' gem 'ckeditor' gem 'cancancan' gem 'social-share-button' +gem 'initialjs-rails' gem 'unicorn' group :development, :test do @@ -61,4 +62,3 @@ end group :test do gem 'email_spec' end - diff --git a/Gemfile.lock b/Gemfile.lock index a6a269d2e..f95d14855 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -140,6 +140,8 @@ GEM i18n term-ansicolor (>= 1.3.2) terminal-table (>= 1.5.1) + initialjs-rails (0.1.0) + railties (>= 3.1, < 5.0) jquery-rails (4.0.4) rails-dom-testing (~> 1.0) railties (>= 4.2.0) @@ -314,6 +316,7 @@ DEPENDENCIES factory_girl_rails foundation-rails i18n-tasks + initialjs-rails jquery-rails launchy letter_opener_web (~> 1.2.0) diff --git a/app/assets/images/user_default.jpg b/app/assets/images/user_default.jpg deleted file mode 100644 index c67f27f55..000000000 Binary files a/app/assets/images/user_default.jpg and /dev/null differ diff --git a/app/assets/images/user_default_2.jpg b/app/assets/images/user_default_2.jpg deleted file mode 100644 index ed164ab57..000000000 Binary files a/app/assets/images/user_default_2.jpg and /dev/null differ diff --git a/app/assets/images/user_default_big.jpg b/app/assets/images/user_default_big.jpg deleted file mode 100644 index d1c5bcea2..000000000 Binary files a/app/assets/images/user_default_big.jpg and /dev/null differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d6dedd05c..ed87ec326 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,17 +16,20 @@ //= require turbolinks //= require ckeditor/init //= require social-share-button +//= require initial //= require app //= require_tree . var initialize_modules = function() { App.Comments.initialize(); + App.Users.initialize(); App.Votes.initialize(); }; $(function(){ $(document).foundation(); - $(document).ready(initialize_modules) - $(document).on('page:load', initialize_modules) + $(document).ready(initialize_modules); + $(document).on('page:load', initialize_modules); + $(document).on('ajax:complete', initialize_modules); }); diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee index 0831d8a20..f6243beab 100644 --- a/app/assets/javascripts/comments.js.coffee +++ b/app/assets/javascripts/comments.js.coffee @@ -17,7 +17,17 @@ App.Comments = $("#js-comment-form-#{id}").toggle() initialize: -> - $('body').on 'click', '.js-add-comment-link', -> - id = $(this).data().id - App.Comments.toggle_form(id) - false + # $('body').on 'click', '.js-add-comment-link', -> + # id = $(this).data().id + # App.Comments.toggle_form(id) + # false + # + $('body .js-add-comment-link').each -> + $this = $(this) + + unless $this.data('initialized') is 'yes' + $this.on('click', -> + id = $(this).data().id + App.Comments.toggle_form(id) + false + ).data 'initialized', 'yes' diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 000000000..9c4fa42b0 --- /dev/null +++ b/app/assets/javascripts/users.js.coffee @@ -0,0 +1,5 @@ +App.Users = + + initialize: -> + $('.initialjs-avatar').initial(); + false diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss index a97764583..3aaa26b75 100644 --- a/app/assets/stylesheets/debates.scss +++ b/app/assets/stylesheets/debates.scss @@ -371,13 +371,8 @@ } .author-photo { - border-radius: 2px; - display: inline-block; - height: 32px; line-height: $line-height*2; margin-right: $line-height/4; - vertical-align: middle; - width: 32px; } .author { @@ -524,16 +519,6 @@ } } - .user-photo { - border-radius: 2px; - display: inline-block; - height: 32px; - line-height: $line-height*2; - margin-right: rem-calc(6); - vertical-align: top; - width: 32px; - } - .comment-body { margin-left: $line-height*1.6; @@ -569,4 +554,4 @@ } } } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 60ffc337d..e2fb5f041 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -484,7 +484,7 @@ form { opacity: .5; } - .avatar { + .initialjs-avatar { margin-bottom: $line-height; } @@ -522,4 +522,4 @@ form { } } } -} \ No newline at end of file +} diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index ecfb17209..2cb792dc7 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -36,13 +36,15 @@

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

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

<%= 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") %> <% end %> + <%= f.label :email_on_comment_reply do %> <%= f.check_box :email_on_comment_reply %> <%= t("account.show.email_on_comment_reply_label") %> @@ -55,4 +57,4 @@
<% end %> - \ No newline at end of file + diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 466752044..af5a41897 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,7 +1,7 @@
- <%= image_tag('user_default_2.jpg', class: 'user-photo left', size: '32x32') %> + <%= avatar_image(comment.user, size: 32, class: 'left') %>
diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 782ecb040..5967e6e55 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -14,7 +14,7 @@

<%= @debate.title %>

- <%= image_tag('user_default.jpg', class: 'author-photo', size: '32x32') %> + <%= avatar_image(@debate.author, size: 32, class: 'author-photo') %> <%= @debate.author.name %> @@ -62,4 +62,4 @@ <%= render @debate.root_comments.recent %>
- \ No newline at end of file + diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index 59ee23f5b..14a5310ba 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -4,20 +4,22 @@ feature 'Account' do background do @user = create(:user, first_name: "Manuela", last_name:"Colau") + login_as(@user) end scenario 'Show' do - login_as(@user) visit root_path + click_link "My account" + expect(current_path).to eq(account_path) expect(page).to have_selector("input[value='Manuela']") expect(page).to have_selector("input[value='Colau']") + expect(page).to have_selector(avatar('Manuela Colau'), count: 1) end scenario "Failed Edit" do - login_as(@user) visit account_path fill_in 'account_first_name', with: '' @@ -31,7 +33,6 @@ feature 'Account' do end scenario 'Edit' do - login_as(@user) visit account_path fill_in 'account_first_name', with: 'Larry' diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 77444cf61..93547ffd2 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -17,6 +17,7 @@ feature 'Comments' do expect(page).to have_content comment.user.name expect(page).to have_content time_ago_in_words(comment.created_at) expect(page).to have_content comment.body + expect(page).to have_selector(avatar(comment.user.name), count: 1) end end diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index de3e05943..87856c457 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -25,6 +25,7 @@ feature 'Debates' do expect(page).to have_content "Debate description" expect(page).to have_content debate.author.name expect(page).to have_content I18n.l(Date.today) + expect(page).to have_selector(avatar(debate.author.name), count: 1) within('.social-share-button') do expect(page.all('a').count).to be(3) # Twitter, Facebook, Google+ diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 5e56d2cea..066e32b87 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -56,4 +56,8 @@ module CommonActions SimpleCaptcha::SimpleCaptchaData.first.value end + def avatar(name) + "img.initialjs-avatar[data-name='#{name}']" + end + end