haml-more 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Haml::More and Sass::More
2
2
  =========================
3
3
 
4
- Adds more functionality to Haml and Sass.
4
+ Adds more functionality to Haml and Sass. Haml helpers detect if called from another context, so they are usable with Erb and friends.
5
5
 
6
6
  BigBand
7
7
  -------
@@ -1,6 +1,14 @@
1
1
  require "haml"
2
2
  require "sass/more"
3
- require "monkey"
3
+ require "monkey-lib"
4
+
5
+ begin
6
+ require 'escape_utils/html/haml'
7
+ rescue LoadError
8
+ if Monkey::Engine.mri? or Monkey::Engine.rbx?
9
+ warn "Please run 'gem install escape_utils' to speed up Haml!"
10
+ end
11
+ end
4
12
 
5
13
  module Haml
6
14
  module More
@@ -35,7 +43,7 @@ module Haml
35
43
 
36
44
  def self.included(klass)
37
45
  Haml::More::CoffeeScript.activate
38
- klass.send :include, Haml::More::ContentFor
46
+ klass.send :include, Haml::More::ContentFor, Haml::More::Javascript
39
47
  super
40
48
  end
41
49
 
@@ -1,5 +1,5 @@
1
1
  require "haml/more"
2
- require "monkey"
2
+ require "monkey-lib"
3
3
 
4
4
  module Haml::More::CoffeeScript
5
5
  include Haml::Filters::Base
@@ -0,0 +1,102 @@
1
+ require 'haml/more'
2
+ require 'forwardable'
3
+
4
+ module Haml::More::JavaScript
5
+ class Pattern
6
+ attr_accessor :pattern, :default_version
7
+
8
+ def self.google(default_version = 1, minified = false)
9
+ new "http://ajax.googleapis.com/ajax/libs/%1$s/%2$s/%1$s#{'.min' if minified}.js",
10
+ default_version
11
+ end
12
+
13
+ def new(pattern, default_version = 1)
14
+ return super if pattern.respond_to? :to_str
15
+ send(pattern, default_version)
16
+ end
17
+
18
+ def initialize(pattern, default_version = 1)
19
+ @pattern, @default_version = pattern, default_version
20
+ end
21
+
22
+ def %(values)
23
+ pattern.gsub("%V", "%2$s") % [values[0], values[1] || default_version, *values[2..-1]]
24
+ end
25
+ end
26
+
27
+ module ClassMethods
28
+ # here is an idea: map to hash, store in haml file
29
+ DEFAULTS = [
30
+ # http://code.google.com/apis/ajaxlibs/documentation/
31
+ # lib, pattern, v, min
32
+ [ :jquery, :google, 1, true ],
33
+ [ :jqueryui, :google, 1, true ],
34
+ [ :prototype, :google, 1 ],
35
+ [ :scriptaculous, :google, 1 ],
36
+ [ :mootools, :google, 1, true ],
37
+ [ :dojo, :google, 1, true ],
38
+ [ :swfobject, :google, 2, true ],
39
+ [ :yui, :google, 2, true ], # for 3.x, see below
40
+ [ "ext-core", :google, 3 ],
41
+ [ :webfont, :google, 1 ],
42
+
43
+ # others
44
+ [ "chrome-frame", "http://ajax.googleapis.com/ajax/libs/chrome-frame/%V/CFInstall.min.js" ],
45
+ [ :modernizr, "http://github.com/Modernizr/Modernizr/raw/v%V/modernizr.js", '1.1' ],
46
+ [ :hyphenator, "http://hyphenator.googlecode.com/svn/tags/Version%%20%V/Hyphenator.js", '3.0.0' ],
47
+ [ :yui3, "http://yui.yahooapis.com/combo?%V/build/yui/yui-min.js", '3.1.1' ],
48
+ [ :sizzle, "http://github.com/jeresig/sizzle/raw/master/sizzle.js" ],
49
+ [ :underscore, "http://github.com/documentcloud/underscore/raw/%V/underscore-min.js", '1.0.2' ],
50
+ [ :raphael, "http://github.com/DmitryBaranovskiy/raphael/raw/v%V/raphael-min.js", '1.4.3' ],
51
+ [ :cufon, "http://cufon.shoqolate.com/js/cufon-yui.js" ],
52
+ [ "coffee-script", "http://github.com/jashkenas/coffee-script/raw/%V/extras/coffee-script.js", '0.6.2' ],
53
+ [ :sammy, "http://github.com/quirkey/sammy/raw/v%V/lib/min/sammy-%V.min.js", '0.5.4' ]
54
+ ]
55
+
56
+ def included(klass)
57
+ klass.send :include, Haml::More::JavaScript::InstanceMethods
58
+ super
59
+ end
60
+
61
+ def javascript_default_pattern
62
+ @javascript_default_pattern ||= Haml::More::JavaScript::Pattern.google
63
+ end
64
+
65
+ def javascript_guessing?
66
+ true
67
+ end
68
+
69
+ def javascript_url_for(name, version = nil, *args)
70
+ return javascript_url_map[name] % [name, version, *args] if javascript_url_map.includes? name
71
+ javascript_default_pattern % [name, version, *args] if javascript_guessing?
72
+ end
73
+
74
+ def set_javascript(name, *args)
75
+ javascript_url_map[name.to_s] = Haml::More::JavaScript::Pattern.new(*args)
76
+ end
77
+
78
+ def javascript_url_map
79
+ return @javascript_url_map if @javascript_url_map
80
+ @javascript_url_map = Hash.new { |h,k| h[k.to_s] unless k.respond_to? :to_str }
81
+ DEFAULTS.each { |args| set_javascript(*args) }
82
+ end
83
+ end
84
+
85
+ module InstanceMethods
86
+ include Haml::More::AbstractHelper
87
+
88
+ def javascript(*list)
89
+ return javascript(list) if list.size == 2 and list.last.to_s =~ /^\d[\.\d]*$/
90
+ haml_helper do
91
+ list.each do |entry|
92
+ entry = entry.to_a if entry.respond_to? to_a
93
+ haml_tag :script, :type => "text/javascript", :src => self.class.javascript_url_for(*entry)
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ def self.append_features(klass)
100
+ klass.extend ClassMethods
101
+ end
102
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-more
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 4
8
+ - 5
8
9
  - 0
9
- version: 0.4.0
10
+ version: 0.5.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Konstantin Haase
@@ -14,30 +15,34 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-02 00:00:00 +02:00
18
+ date: 2010-07-09 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: monkey-lib
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 11
27
30
  segments:
28
31
  - 0
29
- - 4
32
+ - 5
30
33
  - 0
31
- version: 0.4.0
34
+ version: 0.5.0
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: haml
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 47
41
46
  segments:
42
47
  - 2
43
48
  - 2
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: rspec
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 27
55
62
  segments:
56
63
  - 1
57
64
  - 3
@@ -70,6 +77,7 @@ extra_rdoc_files: []
70
77
  files:
71
78
  - lib/haml/more/coffee_script.rb
72
79
  - lib/haml/more/content_for.rb
80
+ - lib/haml/more/javascript.rb
73
81
  - lib/haml/more.rb
74
82
  - lib/haml-more.rb
75
83
  - lib/sass/more.rb
@@ -304,23 +312,27 @@ rdoc_options: []
304
312
  require_paths:
305
313
  - lib
306
314
  required_ruby_version: !ruby/object:Gem::Requirement
315
+ none: false
307
316
  requirements:
308
317
  - - ">="
309
318
  - !ruby/object:Gem::Version
319
+ hash: 3
310
320
  segments:
311
321
  - 0
312
322
  version: "0"
313
323
  required_rubygems_version: !ruby/object:Gem::Requirement
324
+ none: false
314
325
  requirements:
315
326
  - - ">="
316
327
  - !ruby/object:Gem::Version
328
+ hash: 3
317
329
  segments:
318
330
  - 0
319
331
  version: "0"
320
332
  requirements: []
321
333
 
322
334
  rubyforge_project:
323
- rubygems_version: 1.3.6
335
+ rubygems_version: 1.3.7
324
336
  signing_key:
325
337
  specification_version: 3
326
338
  summary: Adds more functionality to Haml and Sass (part of BigBand).