Permalink
Browse files

Added <r:javascript> and <r:stylesheet tags to both pages and the tex…

…t assets.

This includes some fancy tracking of dependencies to keep from mimicking the Radiant 5-minute-cache-per-page.
  • Loading branch information...
1 parent 14befc8 commit 406751f4e58ecf1758b0429f9e1a405ee98b5dea @chrisparrish chrisparrish committed Oct 18, 2008
Showing with 144 additions and 0 deletions.
  1. +99 −0 spec/models/extended_page_tags_spec.rb
  2. +45 −0 spec/models/text_asset_tags_spec.rb
@@ -0,0 +1,99 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+[ {:name => 'stylesheet',
+ :main_scenario => 'main.css',
+ :default_mime_type => 'text/css',
+ :inline_element => 'style' },
+
+ {:name => 'javascript',
+ :main_scenario => 'main.js',
+ :default_mime_type => 'text/javascript',
+ :inline_element => 'script' }
+].each do |current_tag|
+ describe Page, "with <r:#{current_tag[:name]}> tags" do
+ scenario :pages, :javascripts, :stylesheets
+
+ before :each do
+ create_page "text_asset_tags"
+ @page = pages(:text_asset_tags)
+ end
+
+
+ it 'should render an error if no filename provided' do
+ @page.should render(%{<r:#{current_tag[:name]} />}).with_error("`#{current_tag[:name]}' tag must contain a `name' attribute.")
+ end
+
+
+ it 'should render an error with an invalid filename provided' do
+ @page.should render(%{<r:#{current_tag[:name]} name="bogus asset name" />}).with_error("#{current_tag[:name]} not found")
+ end
+
+
+ it "should render the content of the #{current_tag[:name]} when the 'as' attribute is not provided" do
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" />}).as("Main #{current_tag[:name]} content")
+ end
+
+
+ it "should render the content of the #{current_tag[:name]} when the 'as' attribute is set to 'content'" do
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="content" />}).as("Main #{current_tag[:name]} content")
+ end
+
+
+ it "should render the url of the #{current_tag[:name]} when the 'as' attribute is set to 'url'" do
+ StylesNScripts::Config["#{current_tag[:name]}_directory"] = 'foo/bar/baz'
+ ActionController::Routing::Routes.reload!
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="url" />}).as("foo/bar/baz/#{current_tag[:main_scenario]}")
+
+ StylesNScripts::Config.restore_defaults
+ ActionController::Routing::Routes.reload!
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="url" />}).as("#{StylesNScripts::Config["#{current_tag[:name]}_directory"]}/#{current_tag[:main_scenario]}")
+ end
+
+
+ it "should render a <#{current_tag[:inline_element]}> element containing the content of the #{current_tag[:name]} and with the type attribute matching the #{current_tag[:name]}_mime_type setting when the 'as' attribute is set to 'inline'" do
+ StylesNScripts::Config["#{current_tag[:name]}_mime_type"] = 'bologna'
+ ActionController::Routing::Routes.reload!
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" />}).as(
+%{<#{current_tag[:inline_element]} type="bologna">
+<!--
+Main #{current_tag[:name]} content
+-->
+</#{current_tag[:inline_element]}>}
+ )
+
+ StylesNScripts::Config.restore_defaults
+ ActionController::Routing::Routes.reload!
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" />}).as(
+%{<#{current_tag[:inline_element]} type="#{current_tag[:default_mime_type]}">
+<!--
+Main #{current_tag[:name]} content
+-->
+</#{current_tag[:inline_element]}>}
+ )
+
+ end
+
+
+ it %{should override the default <#{current_tag[:inline_element]}> element's 'type' attribute if one is defined in the <r:#{current_tag[:name]}> tag} do
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" type="oscar" />}).as(
+%{<#{current_tag[:inline_element]} type="oscar">
+<!--
+Main #{current_tag[:name]} content
+-->
+</#{current_tag[:inline_element]}>}
+ )
+ end
+
+
+ it %{should pass additional attributes into the <#{current_tag[:inline_element]}> element (and downcase the attribute name)} do
+ @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" another="mayer" ATTRIB="WEINER" />}).as(
+%{<#{current_tag[:inline_element]} type="#{current_tag[:default_mime_type]}" another="mayer" attrib="WEINER">
+<!--
+Main #{current_tag[:name]} content
+-->
+</#{current_tag[:inline_element]}>}
+ )
+ end
+
+ end
+end
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+[ { :asset_class => Stylesheet,
+ :name => 'stylesheet',
+ :main_scenario => 'main.css' },
+
+ { :asset_class => Javascript,
+ :name => 'javascript',
+ :main_scenario => 'main.js' }
+].each do |current_tag|
+ describe current_tag[:asset_class], "with <r:#{current_tag[:name]}> tags" do
+ scenario :pages, :javascripts, :stylesheets
+
+ before :each do
+# @text_asset = create_stylesheet "text_asset_tags" if current_tag[:name] == 'stylesheet'
+# @text_asset = create_javascript "text_asset_tags" if current_tag[:name] == 'javascript'
+ @text_asset = current_tag[:asset_class].new
+ end
+
+
+ it 'should render an error if no filename provided' do
+ @text_asset.content = %{<r:#{current_tag[:name]} />}
+ lambda{@text_asset.render}.should raise_error(
+ current_tag[:asset_class]::TagError,
+ "`#{current_tag[:name]}' tag must contain a `name' attribute."
+ )
+ end
+
+
+ it 'should render an error with an invalid filename provided' do
+ @text_asset.content = %{<r:#{current_tag[:name]} name="bogus asset name" />}
+ lambda{@text_asset.render}.should raise_error(
+ current_tag[:asset_class]::TagError,
+ "#{current_tag[:name]} not found"
+ )
+ end
+
+
+ it "should render the content of the #{current_tag[:name]} when a valid filename is provided" do
+ @text_asset.content =%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" />}
+ @text_asset.render.should == "Main #{current_tag[:name]} content"
+ end
+
+ end
+end

0 comments on commit 406751f

Please sign in to comment.