fancyviews 1.1 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
1
  task :default => :test
2
2
 
3
- desc "Run example test app"
4
- task :test do
5
- dir = File.dirname(__FILE__)
6
- system "cd #{dir} && ruby test/test.rb -p 2222"
3
+ %w(html4 html5).each do |version|
4
+ desc "Run example test app for #{version}"
5
+ task "test_#{version}" do
6
+ dir = File.dirname(__FILE__)
7
+ system "cd #{dir} && ruby test/#{version}.rb -p 2222"
8
+ end
7
9
  end
8
10
 
9
11
  begin
data/fancyviews.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "fancyviews"
3
3
  s.rubyforge_project = 'fancyviews'
4
- s.version = "1.1"
4
+ s.version = "1.3"
5
5
  s.summary = "Fancy Views"
6
6
  s.description = "Fancy Views"
7
7
  s.email = "myles@myles.id.au"
@@ -12,7 +12,8 @@ Gem::Specification.new do |s|
12
12
  Rakefile
13
13
  fancyviews.gemspec
14
14
  lib/sinatra/fancyviews.rb
15
- test/test.rb
15
+ test/html4.rb
16
+ test/html5.rb
16
17
  ]
17
18
  s.add_dependency("sinatra", [">= 0.9.1.1"])
18
19
  s.add_dependency("haml", [">= 2.2"])
@@ -78,16 +78,31 @@ module Sinatra
78
78
  eng = Sass::Engine.new(imported + "\n" + sass, :attribute_syntax => :normal)
79
79
  "\n/* -- #{name} -- */\n" + eng.render
80
80
  end.join
81
-
82
- capture_haml { haml_tag(:style, rendered_styles) }.strip
81
+
82
+ style_tag(rendered_styles, options[:media])
83
83
  end
84
-
84
+
85
+ def style_tag(styles, media=nil)
86
+ capture_haml do
87
+ haml_tag(:style, styles, :type => ("text/css" if haml_format != :html5), :media => media)
88
+ end.strip
89
+ end
90
+
85
91
  # renders all the scripts captured by the :script filter
86
92
  def scripts
87
- scripts = fancyviews.included_scripts.map do |name, js|
93
+ script_tag(fancyviews.included_scripts.map do |name, js|
88
94
  "\n/* -- #{name} -- */\n" + js
89
- end.join
90
- capture_haml { haml_tag(:script, scripts) }.strip
95
+ end.join)
96
+ end
97
+
98
+ def script_tag(scripts)
99
+ capture_haml do
100
+ haml_tag(:script, scripts, :type => ("text/javascript" if haml_format != :html5))
101
+ end.strip
102
+ end
103
+
104
+ def haml_format
105
+ (options.haml && options.haml[:format]) || :xhtml
91
106
  end
92
107
 
93
108
  def fancyviews
data/test/html4.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require File.dirname(__FILE__) + '/../lib/sinatra/fancyviews'
4
+
5
+ set :haml, :format => :html4
6
+
7
+ get('/') { page :home }
8
+
9
+ __END__
10
+
11
+ @@layout
12
+ !!!
13
+ %head
14
+ %title FancyTest
15
+ = styles :media => "screen, projection"
16
+ %body
17
+ = yield
18
+ = scripts
19
+
20
+ @@home
21
+ :style
22
+ body
23
+ :background-color goldenrod
24
+
25
+ :script
26
+ if (document.getElementsByTagName('style')[0].type != "text/css")
27
+ alert("Style tag doesn't have type = 'text/css'");
28
+ else if (document.getElementsByTagName('style')[0].media != "screen, projection")
29
+ alert("Style tag doesn't have media = 'screen, projection'");
30
+ else if (document.getElementsByTagName('script')[0].type != "text/javascript")
31
+ alert("Script tag doesn't have type = 'text/javascript'");
32
+ else
33
+ alert("All good!");
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancyviews
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.1"
4
+ version: "1.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myles Byrne
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-14 00:00:00 +10:00
12
+ date: 2009-09-03 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -44,7 +44,8 @@ files:
44
44
  - Rakefile
45
45
  - fancyviews.gemspec
46
46
  - lib/sinatra/fancyviews.rb
47
- - test/test.rb
47
+ - test/html4.rb
48
+ - test/html5.rb
48
49
  has_rdoc: false
49
50
  homepage:
50
51
  post_install_message: