Permalink
Browse files

Version 0.3 (exported from SVN)

  • Loading branch information...
1 parent 406751f commit 2518f90be02c1e7ce1fbcfb033f3e0b42405b54d @chrisparrish chrisparrish committed Oct 18, 2008
Showing with 931 additions and 547 deletions.
  1. +48 −0 CHANGELOG
  2. +41 −13 README
  3. +0 −8 app/controllers/admin/css_controller.rb
  4. +0 −8 app/controllers/admin/js_controller.rb
  5. +22 −8 app/controllers/admin/text_asset_controller.rb
  6. +3 −3 app/controllers/text_asset_site_controller.rb
  7. +1 −18 app/models/javascript.rb
  8. +1 −18 app/models/stylesheet.rb
  9. +35 −42 app/models/text_asset.rb
  10. +6 −0 app/models/text_asset_dependencies.rb
  11. +38 −0 app/models/text_asset_observer.rb
  12. +0 −74 app/models/text_asset_tags.rb
  13. +0 −3 app/views/admin/text_asset/edit.html.erb
  14. +2 −2 app/views/admin/text_asset/remove.html.erb
  15. +30 −8 db/migrate/002_add_dependencies_to_text_assets.rb
  16. +3 −3 lib/extended_page_tags.rb
  17. +134 −63 spec/controllers/admin/{css_and_js_controllers_common_spec.rb → text_asset_controller_spec.rb}
  18. +165 −98 spec/controllers/text_asset_site_controller_spec.rb
  19. +3 −0 spec/lib/config_spec.rb
  20. +0 −99 spec/models/extended_page_tags_spec.rb
  21. +157 −0 spec/models/stylesheet_and_javascript_dependency_spec.rb
  22. +11 −2 spec/models/{css_asset_and_js_asset_common_spec.rb → stylesheet_and_javascript_spec.rb}
  23. +186 −0 spec/models/stylesheet_and_javascript_tags_spec.rb
  24. +15 −9 spec/models/text_asset_response_cache_spec.rb
  25. +0 −45 spec/models/text_asset_tags_spec.rb
  26. +7 −4 spec/models/user_action_observer_spec.rb
  27. +5 −6 spec/scenarios/javascripts_scenario.rb
  28. +5 −6 spec/scenarios/stylesheets_scenario.rb
  29. +13 −7 styles_n_scripts_extension.rb
View
@@ -0,0 +1,48 @@
+v0.3 Big new features plus code refactoring and a bug fix. First, the new
+ fetures include:
+
+ * Added <r:stylesheet> and <r:javascript> tags for use in pages. This
+ lets you inject your stylesheet or javascript code into your Page
+ much like using a snippet or just render the URL to the referenced
+ CSS or JS file (see the readme for more on this).
+
+ * Added <r:stylesheet> and <r:javascript> tags for use in other
+ Stylesheets or Javascripts. This lets you maintain mulitple files
+ yet just serve one master-stylesheet or master-javascript to your
+ end users (cut down on server requests)
+
+ Along with this, I did a fancy trick with tracking dependencies so
+ that the cache knows when to update (add, edit, or remove a file
+ referenced by a <r:stylesheet> or <r:javascript> tag and the
+ dependant file's effectively_updated_at time changes to reflect it).
+
+
+v0.2.2 Bugfix - I added the UserActionObserver behavior and accompanying specs
+ to the Stylesheet and Javascript models
+
+v0.2.1 Bugfix - I corrected the ActionController::InvalidAuthenticityToken that
+ comes from my not using the form helpers in my templates. I also weakly
+ spec-ed it.
+
+ NOTE: This was only a partial fix. I corrected the edit.html.erb
+ template but not the remove.html.erb one. See v0.3 for the completely
+ fixed version.
+
+
+v0.2 Initial public release. Complete rebuild of the extension to work with
+ Rails 2.0 and Radiant 0.6.6. Added *lots* of specs and focused on
+ making this thing robust.
+
+ Basic functionality included:
+
+ * Stores stylesheet and javascript files
+
+ * Caches them with their own, improved response cache (improved in
+ that it handles this file type better)
+
+ * Configuration management utility to allow extension users to adjust
+ default settings
+
+
+v0.1 Private release to John and Sean as a proof-of-concept (initially called
+ the Files extension).
View
54 README
@@ -1,13 +1,46 @@
= Styles 'n Scripts Extension
-The Styles 'n Scripts extension is a proof-of-concept suggested by John Long
+The Styles 'n Scripts extension was an extension requested by John Long
as a means of separating javascripts & stylesheets from other site content
stored in pages.
-Even though I call it "proof-of-concept," it's already been through one
-iteration with John and is pretty thoroughly tested so don't think that it's not
-usable yet. (The versioning is more to denote the other features that I still
-want to put in it).
+
+
+CONTENTS
+========
+In this README you'll find:
+ 1. Usage
+ 2. Why Change Things?
+ 3. Installation
+ 4. To Do
+
+
+
+USAGE
+=====
+Using this extension is rather painless. If you can use the rest of Radiant,
+these additions will seem obvious. There are a couple of things to take note
+of, however.
+
+ * The CSS and JS tabs are where you create, edit, and delete stylesheets and
+ javascripts. But you need Administrator or Developer permissions to see
+ these tabs.
+
+ * If you want to reference or otherwise use your script or stylesheet in one
+ of your pages, there are <r:stylesheet> and <r:javascript> tags. These tags
+ can be used to inject your CSS or JS code into the page or just render a
+ link to the file itself. (See the 'available tags' link on the Page edit
+ form to learn more about options for these tags).
+
+ * If you want to cut down on server requests for CSS and JS files, you can
+ also create a master CSS or JS file for each and use the appropriate
+ <r:stylesheet> or <r:javascript> tags to incorporate other files of the same
+ type. Viola, now Radiant offers asset packaging just like Rails!
+
+
+That's it. Everything else is either too obvious to bother with here or
+automagical and too top secret to disclose.
+
WHY CHANGE THINGS?
@@ -33,7 +66,7 @@ There are a number of interesting benefits gained by this approach:
stylesheet page (I mean, do javascripts really need a layout?).
* Makes it easy to include search functionality across your pages without
- terms like "background" turning up all your stylesheets.
+ terms like "background" yielding all your stylesheets.
* Declutter the pages tree view so that it truly only shows what your clients
see -- the things they'd aim their browser at.
@@ -47,6 +80,7 @@ There are a number of interesting benefits gained by this approach:
flash, and the like.
+
INSTALLATION
============
1. Copy this extension into your existing Radiant project (place it at:
@@ -72,6 +106,7 @@ INSTALLATION
file.
+
TO-DO
=====
Create a way for users to upload stylesheets and javascripts (maybe even upload
@@ -81,13 +116,6 @@ Improve caching. I'd like to see a scenario where files are cached-on-save.
Rails page caching might be a great choice. (Maintaining the cache -- sweepers,
etc. -- wouldn't be all that hard for these items.).
-Create <r:stylesheet> (or maybe <r:text_asset>) tag to let users reference
-stylesheets from pages, snippets, and layouts. Is this really helpful?
-
-Create a <r:include_stylesheet> tag for stylesheets and one for scripts (similar
-to the <r:content> tag for pages) to merge stylesheets/scripts into one big file
-to reduce the number of requests and speed serving.
-
Add file minification to strip out comments and whitespace (and maybe obfuscate)
javascripts and stylesheets. (I already have this started).
@@ -1,8 +0,0 @@
-class Admin::CssController < Admin::TextAssetController
- model_class Stylesheet
-
- only_allow_access_to :index, :new, :edit, :remove,
- :when => [:developer, :admin],
- :denied_url => { :controller => 'page', :action => 'index' },
- :denied_message => 'You must have developer or administrator privileges to perform this action.'
-end
@@ -1,8 +0,0 @@
-class Admin::JsController < Admin::TextAssetController
- model_class Javascript
-
- only_allow_access_to :index, :new, :edit, :remove,
- :when => [:developer, :admin],
- :denied_url => { :controller => 'page', :action => 'index' },
- :denied_message => 'You must have developer or administrator privileges to perform this action.'
-end
@@ -1,5 +1,13 @@
class Admin::TextAssetController < Admin::AbstractModelController
+ only_allow_access_to :index, :new, :edit, :remove,
+ :when => [:developer, :admin],
+ :denied_url => { :controller => 'page', :action => 'index' },
+ :denied_message => 'You must have developer or administrator privileges to perform this action.'
+
+ before_filter :set_model
+
+
def initialize()
super
# overwrite @cache from super with our special cache
@@ -11,22 +19,20 @@ def index
# we CANNOT use the plural 'self.models' as this creates a @stylesheets
# instance variable which conflictss with Radiants admin @stylesheets
@text_assets = self.model = model_class.find(:all)
- # force child controllers to render template in the admin/text_asset directory
- render :template => "admin/text_asset/index", :object => @model_name = model_name
+ @model_name = model_name
end
def new
@text_asset = self.model = model_class.new
# force child controllers to render template in the admin/text_asset directory
- render :template => "admin/text_asset/edit" if handle_new_or_edit_post
+ render :action => :edit if handle_new_or_edit_post
end
def edit
@text_asset = self.model = model_class.find_by_id(params[:id])
- # force child controllers to render template in the admin/text_asset directory
- render :template => "admin/text_asset/edit" if handle_new_or_edit_post
+ handle_new_or_edit_post
end
@@ -37,10 +43,18 @@ def remove
announce_removed
clear_model_cache # <-- Added this line to clear cache on remove
redirect_to model_index_url
- else
- # force child controllers to render template in the admin/text_asset directory
- render :template => "admin/text_asset/remove"
end
end
+
+ private
+
+ # since the model name comes from the params, the model_class cannot
+ # be set until after initialization (seems like params are only available
+ # to the action methods). So we'll process 'em as part of a before_filter
+ def set_model
+ self.class.model_class params[:asset_type].camelize.constantize
+ end
+
+
end
@@ -19,7 +19,7 @@ def show_text_asset
@text_asset_cache.update_response(url, response, request)
@performed_render = true
else
- show_uncached_text_asset(filename, params[:asset_class], url)
+ show_uncached_text_asset(filename, params[:asset_type], url)
end
end
@@ -39,10 +39,10 @@ def show_uncached_text_asset(filename, asset_class, url)
response.headers['Content-Type'] = mime_type
# set the last modified date based on updated_at time for the asset
# we can do this as long as there is no dynamic content in the assets
- response.headers['Last-Modified'] = @text_asset.updated_at
+ response.headers['Last-Modified'] = @text_asset.effectively_updated_at
response.body = @text_asset.render
- # for text_assets, we cache no matter what (there's no status setting for them)
+ # for text_assets, we cache no matter what (no 'status' setting for them)
text_asset_cache.cache_response(url, response) if request.get?
@performed_render = true
else
View
@@ -1,18 +1 @@
-class Javascript < TextAsset
-
- class TagError < StandardError; end
-
- tag('javascript') do |tag|
- if name = tag.attr['name']
- self.dependencies << tag.attr['name'].strip
- if javascript = Javascript.find_by_filename(tag.attr['name'].strip)
- javascript.render
- else
- raise TagError.new("javascript not found")
- end
- else
- raise TagError.new("`javascript' tag must contain a `name' attribute.") unless tag.attr.has_key?('name')
- end
- end
-
-end
+class Javascript < TextAsset; end
View
@@ -1,18 +1 @@
-class Stylesheet < TextAsset
-
- class TagError < StandardError; end
-
- tag('stylesheet') do |tag|
- if name = tag.attr['name']
- self.dependencies << tag.attr['name'].strip
- if stylesheet = Stylesheet.find_by_filename(tag.attr['name'].strip)
- stylesheet.render
- else
- raise TagError.new("stylesheet not found")
- end
- else
- raise TagError.new("`stylesheet' tag must contain a `name' attribute.") unless tag.attr.has_key?('name')
- end
- end
-
-end
+class Stylesheet < TextAsset; end
Oops, something went wrong.

0 comments on commit 2518f90

Please sign in to comment.