Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 406751f4e58ecf1758b0429f9e1a405ee98b5dea 1 parent 14befc8
Chris Parrish authored October 18, 2008
99  spec/models/extended_page_tags_spec.rb
... ...
@@ -0,0 +1,99 @@
  1
+require File.dirname(__FILE__) + '/../spec_helper'
  2
+
  3
+[ {:name => 'stylesheet',
  4
+   :main_scenario => 'main.css',
  5
+   :default_mime_type => 'text/css',
  6
+   :inline_element => 'style' },
  7
+
  8
+  {:name => 'javascript',
  9
+   :main_scenario => 'main.js',
  10
+   :default_mime_type => 'text/javascript',
  11
+   :inline_element => 'script' }
  12
+].each do |current_tag|
  13
+  describe Page, "with <r:#{current_tag[:name]}> tags" do
  14
+    scenario :pages, :javascripts, :stylesheets
  15
+  
  16
+    before :each do
  17
+      create_page "text_asset_tags"
  18
+      @page = pages(:text_asset_tags)
  19
+    end
  20
+  
  21
+  
  22
+    it 'should render an error if no filename provided' do
  23
+      @page.should render(%{<r:#{current_tag[:name]} />}).with_error("`#{current_tag[:name]}' tag must contain a `name' attribute.")
  24
+    end
  25
+  
  26
+  
  27
+    it 'should render an error with an invalid filename provided' do
  28
+      @page.should render(%{<r:#{current_tag[:name]} name="bogus asset name" />}).with_error("#{current_tag[:name]} not found")
  29
+    end
  30
+  
  31
+  
  32
+    it "should render the content of the #{current_tag[:name]} when the 'as' attribute is not provided" do
  33
+      @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" />}).as("Main #{current_tag[:name]} content")
  34
+    end
  35
+  
  36
+  
  37
+    it "should render the content of the #{current_tag[:name]} when the 'as' attribute is set to 'content'" do
  38
+      @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="content" />}).as("Main #{current_tag[:name]} content")
  39
+    end
  40
+  
  41
+  
  42
+    it "should render the url of the #{current_tag[:name]} when the 'as' attribute is set to 'url'" do
  43
+      StylesNScripts::Config["#{current_tag[:name]}_directory"] = 'foo/bar/baz'
  44
+      ActionController::Routing::Routes.reload!
  45
+      @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="url" />}).as("foo/bar/baz/#{current_tag[:main_scenario]}")
  46
+  
  47
+      StylesNScripts::Config.restore_defaults
  48
+      ActionController::Routing::Routes.reload!
  49
+      @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]}")
  50
+    end  
  51
+  
  52
+  
  53
+    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
  54
+      StylesNScripts::Config["#{current_tag[:name]}_mime_type"] = 'bologna'
  55
+      ActionController::Routing::Routes.reload!
  56
+      @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" />}).as(
  57
+%{<#{current_tag[:inline_element]} type="bologna">
  58
+<!--
  59
+Main #{current_tag[:name]} content
  60
+-->
  61
+</#{current_tag[:inline_element]}>}
  62
+      )
  63
+
  64
+      StylesNScripts::Config.restore_defaults
  65
+      ActionController::Routing::Routes.reload!
  66
+      @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" />}).as(
  67
+%{<#{current_tag[:inline_element]} type="#{current_tag[:default_mime_type]}">
  68
+<!--
  69
+Main #{current_tag[:name]} content
  70
+-->
  71
+</#{current_tag[:inline_element]}>}
  72
+      )
  73
+  
  74
+    end
  75
+  
  76
+  
  77
+    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
  78
+      @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" type="oscar" />}).as(
  79
+%{<#{current_tag[:inline_element]} type="oscar">
  80
+<!--
  81
+Main #{current_tag[:name]} content
  82
+-->
  83
+</#{current_tag[:inline_element]}>}
  84
+      )
  85
+    end
  86
+  
  87
+  
  88
+    it %{should pass additional attributes into the <#{current_tag[:inline_element]}> element (and downcase the attribute name)} do
  89
+      @page.should render(%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" as="inline" another="mayer" ATTRIB="WEINER" />}).as(
  90
+%{<#{current_tag[:inline_element]} type="#{current_tag[:default_mime_type]}" another="mayer" attrib="WEINER">
  91
+<!--
  92
+Main #{current_tag[:name]} content
  93
+-->
  94
+</#{current_tag[:inline_element]}>}
  95
+      )
  96
+    end
  97
+  
  98
+  end
  99
+end
45  spec/models/text_asset_tags_spec.rb
... ...
@@ -0,0 +1,45 @@
  1
+require File.dirname(__FILE__) + '/../spec_helper'
  2
+
  3
+[ { :asset_class => Stylesheet,
  4
+    :name => 'stylesheet',
  5
+    :main_scenario => 'main.css' },
  6
+
  7
+  { :asset_class => Javascript,
  8
+    :name => 'javascript',
  9
+    :main_scenario => 'main.js' }
  10
+].each do |current_tag|
  11
+  describe current_tag[:asset_class], "with <r:#{current_tag[:name]}> tags" do
  12
+    scenario :pages, :javascripts, :stylesheets
  13
+
  14
+    before :each do
  15
+#      @text_asset = create_stylesheet "text_asset_tags" if current_tag[:name] == 'stylesheet'
  16
+#      @text_asset = create_javascript "text_asset_tags" if current_tag[:name] == 'javascript'
  17
+      @text_asset = current_tag[:asset_class].new
  18
+    end
  19
+
  20
+
  21
+    it 'should render an error if no filename provided' do
  22
+      @text_asset.content = %{<r:#{current_tag[:name]} />}
  23
+      lambda{@text_asset.render}.should raise_error(
  24
+          current_tag[:asset_class]::TagError,
  25
+          "`#{current_tag[:name]}' tag must contain a `name' attribute."
  26
+      )
  27
+    end
  28
+  
  29
+  
  30
+    it 'should render an error with an invalid filename provided' do
  31
+      @text_asset.content = %{<r:#{current_tag[:name]} name="bogus asset name" />}
  32
+      lambda{@text_asset.render}.should raise_error(
  33
+          current_tag[:asset_class]::TagError,
  34
+          "#{current_tag[:name]} not found"
  35
+      )
  36
+    end
  37
+  
  38
+  
  39
+    it "should render the content of the #{current_tag[:name]} when a valid filename is provided" do
  40
+      @text_asset.content =%{<r:#{current_tag[:name]} name="#{current_tag[:main_scenario]}" />}
  41
+      @text_asset.render.should == "Main #{current_tag[:name]} content"
  42
+    end
  43
+  
  44
+  end
  45
+end

0 notes on commit 406751f

Please sign in to comment.
Something went wrong with that request. Please try again.