From ea3067ff36c3beba69f4d788949b36939bb01e26 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 18 Sep 2012 18:52:37 +0100 Subject: [PATCH 1/4] Replace most of the HTML-in-HAML - We do this by moving code between files such that every tag starts and ends within a single file. This seems like a good invariant to maintain from a robustness point-of-view. - One consequence is that I had to split _header into _meta (metadata - the HTML head tag) and _header (the visible page header). These probably aren't the best names. - I've left some HTML in _meta, on the grounds that it maintains the file-contains-whole-tag invariant and the HTML code is fractionally shorter than the HAML required to generate it. --- app/views/layouts/_footer.html.haml | 6 ------ app/views/layouts/_header.html.haml | 16 ---------------- app/views/layouts/_meta.html.haml | 10 ++++++++++ app/views/layouts/application.html.haml | 23 ++++++++++++++--------- 4 files changed, 24 insertions(+), 31 deletions(-) create mode 100644 app/views/layouts/_meta.html.haml diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index a92d8777c..5e728baaf 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -1,6 +1,3 @@ - -- # There are some tags here, such as these close div tags and the close body and html tags below, which were opened in the header fragment. HAML can't handle this, so they're done in HTML instead. - .row .ten.columns %ul.link-list @@ -14,6 +11,3 @@ = link_to "Mailing list", "http://lists.growstuff.org/mailman/listinfo/discuss" %li = link_to "Community Guidelines", "https://github.com/Growstuff/policy/blob/master/community-guidelines.md" - - - diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 0ed4e4aa2..ef413ee18 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -1,18 +1,3 @@ - -- # There are some tags here, such as html, body, etc, which are opened in this file and closed in the footer fragment. HAML can't handle this, so they're left as HTML. If you were wondering. - -%head - - - - %title - = content_for?(:title) ? yield(:title) : "Growstuff" - = stylesheet_link_tag "application", :media => "all" - = javascript_include_tag "application" - = csrf_meta_tags - - - .row .ten.columns - if user_signed_in? @@ -34,4 +19,3 @@ %h1 = link_to('Growstuff', root_path) -
diff --git a/app/views/layouts/_meta.html.haml b/app/views/layouts/_meta.html.haml new file mode 100644 index 000000000..89ca1c3d8 --- /dev/null +++ b/app/views/layouts/_meta.html.haml @@ -0,0 +1,10 @@ +%head + + + + %title + = content_for?(:title) ? yield(:title) : "Growstuff" + = stylesheet_link_tag "application", :media => "all" + = javascript_include_tag "application" + = csrf_meta_tags + diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 119cb0e26..01c9e37ad 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -1,9 +1,14 @@ -= render :partial => "layouts/header" -- if notice - %p.notice - = notice -- if alert - %p.alert - = alert -= yield -= render :partial => "layouts/footer" +%html + = render :partial => "layouts/meta" + %body + = render :partial => "layouts/header" + .row + .ten.columns + - if notice + %p.notice + = notice + - if alert + %p.alert + = alert + = yield + = render :partial => "layouts/footer" From 387d68185d957d90a2cad27844486a3bd7ff3f5a Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 17 Sep 2012 22:50:08 +0100 Subject: [PATCH 2/4] Wrap dev/test Rake tasks in error recovery Rake was dying due to missing gems in production. --- lib/tasks/testing.rake | 16 +++++++++------- lib/tasks/watchr.rake | 9 ++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index cc082b0be..e2a99ea9b 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -1,12 +1,14 @@ require 'rake' -require 'rspec/core/rake_task' +begin + require 'rspec/core/rake_task' -RSpec::Core::RakeTask.new(:spec) + RSpec::Core::RakeTask.new(:spec) -task :default => :spec + task :default => :spec -task :run_tests do - system("rspec spec/") - system("rake test") + task :run_tests do + system("rspec spec/") + system("rake test") + end +rescue LoadError end - diff --git a/lib/tasks/watchr.rake b/lib/tasks/watchr.rake index 498b82be8..4f48a3761 100644 --- a/lib/tasks/watchr.rake +++ b/lib/tasks/watchr.rake @@ -1,4 +1,7 @@ -desc "Run watchr" -task :watchr do - sh %{bundle exec watchr .watchr} +begin + desc "Run watchr" + task :watchr do + sh %{bundle exec watchr .watchr} + end +rescue LoadError end From a2fede15e974186f49005779ca8e35a480e381ec Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 17 Sep 2012 22:55:27 +0100 Subject: [PATCH 3/4] Don't connect to the DB when precompiling assets. See https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar#troubleshooting --- config/application.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/application.rb b/config/application.rb index 11c1375cd..16f4ae061 100644 --- a/config/application.rb +++ b/config/application.rb @@ -58,5 +58,8 @@ module Growstuff # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' + + # Don't try to connect to the database when precompiling assets + config.assets.initialize_on_precompile = false end end From f6bc259c6836708b59f99765a9323fa0e0d00f37 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 24 Sep 2012 21:17:11 +0100 Subject: [PATCH 4/4] precompile assets after deploying --- config/deploy.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/deploy.rb b/config/deploy.rb index e69edc538..8f39167d3 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -48,6 +48,8 @@ Cape do mirror_rake_tasks 'db:migrate', :roles => :app do |env| env['RAILS_ENV'] = rails_env end + mirror_rake_tasks :assets end after :deploy, 'db:migrate' +after :deploy, 'assets:precompile'