From 6d0ccc1450049bd5e2cb2110ed36762f0eaaa6a2 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Wed, 29 Feb 2012 15:43:53 -0800 Subject: [PATCH] nav state, pjax nav state, refactor and cleanup --- Gemfile | 8 +- Gemfile.lock | 24 +++++- app/assets/javascripts/application.js.coffee | 9 ++- app/views/devise/shared/_links.erb | 14 ++-- app/views/fragments/_navigation.html.erb | 2 +- .../navigation/_application.html.erb | 75 +++++++------------ .../fragments/navigation/_public.html.erb | 51 +++++-------- config/initializers/navigasmic.rb | 42 +++++++++++ 8 files changed, 133 insertions(+), 92 deletions(-) create mode 100644 config/initializers/navigasmic.rb diff --git a/Gemfile b/Gemfile index 14d86d3..9a25111 100644 --- a/Gemfile +++ b/Gemfile @@ -12,11 +12,11 @@ gem 'cancan', '~> 1.6.7' gem 'squeel', '~> 0.9.3' gem 'sentient_user', '~> 0.3.2' gem 'userstamp_basic', '~> 0.1.0' -gem 'active_scaffold', :git => 'https://github.com/activescaffold/active_scaffold.git' +gem 'active_scaffold', git: 'https://github.com/activescaffold/active_scaffold.git' # :path => '/home/clyfe/dev/active_scaffold' # '~> 3.2.0' -gem 'pjax_rails', '~> 0.1.10' -gem 'validates_hostname', '~> 1.0.0', :git => 'https://github.com/KimNorgaard/validates_hostname.git' +gem 'pjax_rails', '~> 0.1.7', git: 'https://github.com/rails/pjax_rails.git' +gem 'validates_hostname', '~> 1.0.0', git: 'https://github.com/KimNorgaard/validates_hostname.git' gem 'nilify_blanks', '~> 1.0.0' gem 'rails_config', '~> 0.2.4' # gem 'rails-settings-cached', :require => 'rails-settings' @@ -25,6 +25,8 @@ gem 'mail_form', '~> 1.3.0' gem 'switch_user', '~> 0.6.0' gem 'simple_form', '~> 2.0.0' gem 'concerned_with', '~> 0.1.0' +gem 'navigasmic', '~> 0.5.6', git: 'https://github.com/jejacks0n/navigasmic.git' +gem 'rails-backbone', '~> 0.7.0' # Gems used only for assets and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index e8513ea..ccda4d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,19 @@ GIT active_scaffold (3.2.0) rails (>= 3.1.3) +GIT + remote: https://github.com/jejacks0n/navigasmic.git + revision: 6108afe7930fd4b3282cbe8942240bf4f70e2f74 + specs: + navigasmic (0.5.6) + +GIT + remote: https://github.com/rails/pjax_rails.git + revision: e79a1cf58a8935eb132f4910f300cf86d081ae6d + specs: + pjax_rails (0.1.7) + jquery-rails + GEM remote: http://rubygems.org/ specs: @@ -92,6 +105,7 @@ GEM railties (~> 3.1) warden (~> 1.1.1) diff-lcs (1.1.3) + ejs (1.0.0) erubis (2.7.0) execjs (1.3.0) multi_json (~> 1.0) @@ -146,8 +160,6 @@ GEM activesupport (>= 3.0.0) nokogiri (1.5.0) orm_adapter (0.0.6) - pjax_rails (0.1.10) - jquery-rails polyamorous (0.5.0) activerecord (~> 3.0) polyglot (0.3.3) @@ -166,6 +178,10 @@ GEM activesupport (= 3.2.0) bundler (~> 1.0) railties (= 3.2.0) + rails-backbone (0.7.0) + coffee-script (~> 2.2.0) + ejs (~> 1.0.0) + railties (>= 3.1.0) rails_config (0.2.5) activesupport (>= 3.0) railties (3.2.0) @@ -266,9 +282,11 @@ DEPENDENCIES mail_form (~> 1.3.0) mongrel (>= 1.2.0.pre2) mysql2 + navigasmic (~> 0.5.6)! nilify_blanks (~> 1.0.0) - pjax_rails (~> 0.1.10) + pjax_rails (~> 0.1.7)! rails (= 3.2.0) + rails-backbone (~> 0.7.0) rails_config (~> 0.2.4) rb-inotify (~> 0.8.8) rspec-rails (~> 2.8.1) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index cc368ee..402fb46 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -7,7 +7,8 @@ #= require jquery #= require jquery-ui #= require jquery_ujs -#= require pjax +#= require jquery.pjax +#= require pjax/page_triggers #= require active_scaffold #= require slides #= require twitter/bootstrap @@ -16,3 +17,9 @@ $ -> $('[rel=popover]').popover() $('[rel=tooltip]').tooltip() + + $('.pjax-nav a:not([data-remote]):not([data-behavior]):not([data-skip-pjax])').pjax('[data-pjax-container]') + + $(document).on 'pjax:success', (event, data, status, xhr, options) -> + $('ul.pjax-nav').find('li.active').removeClass 'active' + $("ul.pjax-nav a[href=\"#{window.location.pathname}\"]").parents('li').addClass 'active' diff --git a/app/views/devise/shared/_links.erb b/app/views/devise/shared/_links.erb index 22ff4e4..a9cd664 100644 --- a/app/views/devise/shared/_links.erb +++ b/app/views/devise/shared/_links.erb @@ -1,8 +1,8 @@ - +<% semantic_navigation :devise_nav, html: { class: 'nav nav-pills pjax-nav' } do |n| %> + <%= n.item "Sign in", link: new_session_path(resource_name) %> + <%= n.item "Sign up", link: new_registration_path(resource_name) %> + <%= n.item "Forgot your password?", link: new_password_path(resource_name) %> + <%= n.item "Didn't receive confirmation instructions?", link: new_confirmation_path(resource_name) %> + <%= n.item "Didn't receive unlock instructions?", link: new_unlock_path(resource_name) %> +<% end %> diff --git a/app/views/fragments/_navigation.html.erb b/app/views/fragments/_navigation.html.erb index e47c324..2c20af5 100644 --- a/app/views/fragments/_navigation.html.erb +++ b/app/views/fragments/_navigation.html.erb @@ -8,7 +8,7 @@ - <%= link_to('EntryDNS', root_path, class: 'brand', data: {pjax: '#main'}) %> + <%= link_to('EntryDNS', root_path, class: 'brand') %>