Skip to content

Commit

Permalink
Asset pipeline support, small theme change required [THEME] [DEPLOY]
Browse files Browse the repository at this point in the history
It should now be possible to develop themes which take advantage of the
asset pipeline for non-view resources such as stylesheets using SASS/SCSS
or javascript using CoffeeScript (add to :assets group in Gemfile).

[THEME] If you are maintaining a theme or fork of calagator, you will
need to make a small change to your templates, due to incompatibilities
between the asset pipeline and the ':cache => true' attribute.

  1. Change following line in themes/*/views/layouts/application.html.erb:
       <%= javascript_include_tag  :defaults, :cache => true %>
     to look like:
       <%= javascript_include_tag 'application' %>

  2. Remove any additional ':cache => true' attributes used in your
     theme; most likely you won't find any beyond #1 above.

[DEPLOY] Deploying calagator now requires you to precompile assets using:

  $> rake assets:precompile

Conflicts:
	config/environments/development.rb
  • Loading branch information
dhedlund committed Jun 22, 2013
1 parent c93288a commit 1677936
Show file tree
Hide file tree
Showing 57 changed files with 66 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ db/*.sqlite3.*
index/*
log/*
nbproject/*
public/assets
public/images/active_scaffold
public/images/record_select
public/javascripts/active_scaffold
Expand Down
15 changes: 15 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ group :development, :test do
gem 'pry'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
# gem 'sass-rails', '~> 3.2.3'
# gem 'coffee-rails', '~> 3.2.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby

# Minify assets. Requires a javascript runtime, such as 'therubyracer'
# above. You will also need to set 'config.assets.compress' to true in
# config/environments/production.rb
# gem 'uglifier', '>= 1.0.3'
end

# Some dependencies are activated through server settings.
require "#{basedir}/lib/secrets_reader"
secrets = SecretsReader.read(:silent => true)
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 13 additions & 6 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

require 'rails/all'

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end

module Calagator
class Application < Rails::Application
Expand Down Expand Up @@ -87,6 +90,13 @@ class Application < Rails::Application
config.cache_store = :file_store, cache_path
FileUtils.mkdir_p(cache_path)

#---[ Asset Pipeline ]--------------------------------------------------
# Enable the asset pipeline
config.assets.enabled = true

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

#---[ Secrets and settings ]--------------------------------------------

config.before_initialize do
Expand Down Expand Up @@ -123,9 +133,6 @@ def theme_file(filename)
# Activate search engine
require 'search_engine'
SearchEngine.kind = SECRETS.search_engine

# Enable Asset Pipeline
config.assets.enabled = true
end

# Set timezone for OS
Expand Down
6 changes: 6 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin

# Do not compress assets
config.assets.compress = false

# Expands the lines which load the assets
config.assets.debug = true

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end

26 changes: 21 additions & 5 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false

# Compress JavaScripts and CSS
#config.assets.compress = true
config.assets.compress = false

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH

# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"

Expand All @@ -27,13 +43,13 @@
# Use a different cache store in production
# config.cache_store = :mem_cache_store

# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = false

# Enable serving of images, stylesheets, and javascripts from an asset server
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
config.assets.precompile += %w( *.js *.css )

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false

Expand Down
4 changes: 4 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true

# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

Expand Down
4 changes: 4 additions & 0 deletions config/initializers/themes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ThemesForRails.config do |config|
# your static assets on Rails.root/themes/pink/assets/{stylesheets,javascripts,images}
config.assets_dir = ":root/themes/:name"
end
1 change: 1 addition & 0 deletions public/images
1 change: 0 additions & 1 deletion public/themes

This file was deleted.

2 changes: 1 addition & 1 deletion themes/default/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= yield :css_insert %>

<!-- JavaScripts, static -->
<%= javascript_include_tag :defaults, :cache => true %>
<%= javascript_include_tag 'application' %>
<%# TODO figure out how to fix 'theme_support' plugin to make a working include tag AND make the server actually send the contents, because both of these are broken. %>
<%#= theme_javascript_include_tag 'application'%>

Expand Down

0 comments on commit 1677936

Please sign in to comment.