spar 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -144,3 +144,9 @@ module Spar
144
144
  end
145
145
 
146
146
  end
147
+
148
+ module Sprockets
149
+ class Context
150
+ include Spar::Helpers
151
+ end
152
+ end
@@ -2,6 +2,8 @@ module Spar
2
2
 
3
3
  class DirectiveProcessor < Sprockets::Processor
4
4
 
5
+ include Spar::Helpers
6
+
5
7
  def evaluate(context, locals, &block)
6
8
  @result = data
7
9
 
@@ -13,21 +15,21 @@ module Spar
13
15
  protected
14
16
 
15
17
  def process_methods
16
- @result.gsub!(/\[\{(.*?)\}\]/) do
18
+ Spar.settings['interpolator_regex'] ||= '\[\{(.*?)\}\]'
19
+ @result.gsub!(/#{Spar.settings['interpolator_regex']}/) do
17
20
  command = $1.strip
18
21
  case command
19
22
  when /^path_to\((?<file_name>.*)\)$/
20
- Spar::Helpers.path_to($~[:file_name])
23
+ path_to($~[:file_name])
21
24
  when /^javascript_include_tag\((?<file_names>.*)\)$/
22
- Spar::Helpers.javascript_include_tag(*($~[:file_names]).split(',').map(&:strip))
25
+ javascript_include_tag(*($~[:file_names]).split(',').map(&:strip))
23
26
  when /^stylesheet_link_tag\((?<file_names>.*)\)$/
24
- Spar::Helpers.stylesheet_link_tag(*($~[:file_names]).split(',').map(&:strip))
25
- else
26
- if variable = Spar.settings[command]
27
- variable
28
- else
29
- raise "Could not find a value for: '#{command}'"
30
- end
27
+ stylesheet_link_tag(*($~[:file_names]).split(',').map(&:strip))
28
+ else
29
+ variable = Spar.settings
30
+ command.split('.').each { |key| variable = variable[key] }
31
+ raise "Could not find a value for: '#{command}'" unless variable
32
+ variable
31
33
  end
32
34
  end
33
35
  end
@@ -3,19 +3,34 @@ require 'sprockets'
3
3
  module Spar
4
4
  module Helpers
5
5
 
6
- def self.paths
7
- @paths ||= Spar::Helpers::Paths.new()
6
+ class << self
7
+
8
+ def paths
9
+ @paths ||= Spar::Helpers::Paths.new()
10
+ end
11
+
12
+ def append_features(context) # :nodoc:
13
+ context.class_eval do
14
+ context_methods = context.instance_methods(false)
15
+ Helpers.public_instance_methods.each do |method|
16
+ remove_method(method) if context_methods.include?(method)
17
+ end
18
+ end
19
+
20
+ super(context)
21
+ end
22
+
8
23
  end
9
24
 
10
- def self.path_to(asset_name, options={})
25
+ def path_to(asset_name, options={})
11
26
  asset_name = asset_name.logical_path if asset_name.respond_to?(:logical_path)
12
- path = paths.compute_public_path(asset_name, options.merge(:body => true))
27
+ path = Helpers.paths.compute_public_path(asset_name, options.merge(:body => true))
13
28
  options[:body] ? "#{path}?body=1" : path
14
29
  end
15
30
 
16
- def self.javascript_include_tag(*sources)
31
+ def javascript_include_tag(*sources)
17
32
  sources.collect do |source|
18
- if Spar.settings['debug'] && asset = paths.asset_for(source, 'js')
33
+ if Spar.settings['debug'] && asset = Helpers.paths.asset_for(source, 'js')
19
34
  asset.to_a.map { |dep|
20
35
  javascript_tag(path_to(dep, :ext => 'js', :body => true))
21
36
  }
@@ -25,13 +40,13 @@ module Spar
25
40
  end.join("\n")
26
41
  end
27
42
 
28
- def self.javascript_tag(src)
43
+ def javascript_tag(src)
29
44
  "<script src='#{src}' charset='utf-8'></script>"
30
45
  end
31
46
 
32
- def self.stylesheet_link_tag(*sources)
47
+ def stylesheet_link_tag(*sources)
33
48
  sources.collect do |source|
34
- if Spar.settings['debug'] && asset = paths.asset_for(source, 'css')
49
+ if Spar.settings['debug'] && asset = Helpers.paths.asset_for(source, 'css')
35
50
  asset.to_a.map { |dep|
36
51
  stylesheet_tag(path_to(dep, :ext => 'css', :body => true, :protocol => :request))
37
52
  }
@@ -41,10 +56,41 @@ module Spar
41
56
  end.join("\n")
42
57
  end
43
58
 
44
- def self.stylesheet_tag(src)
59
+ def stylesheet_tag(src)
45
60
  "<link href='#{src}' rel='stylesheet'>"
46
61
  end
47
62
 
63
+ ## Helper methods for the spar context
64
+ def audio_path(source, options = {})
65
+ path_to source, { :dir => 'audios' }.merge(options)
66
+ end
67
+ alias_method :path_to_audio, :audio_path
68
+
69
+ def font_path(source, options = {})
70
+ path_to source, { :dir => 'fonts' }.merge(options)
71
+ end
72
+ alias_method :path_to_font, :font_path
73
+
74
+ def image_path(source, options = {})
75
+ path_to source, { :dir => 'images' }.merge(options)
76
+ end
77
+ alias_method :path_to_image, :image_path
78
+
79
+ def javascript_path(source, options = {})
80
+ path_to source, { :dir => 'javascripts', :ext => 'js' }.merge(options)
81
+ end
82
+ alias_method :path_to_javascript, :javascript_path
83
+
84
+ def stylesheet_path(source, options = {})
85
+ path_to source, { :dir => 'stylesheets', :ext => 'css' }.merge(options)
86
+ end
87
+ alias_method :path_to_stylesheet, :stylesheet_path
88
+
89
+ def video_path(source, options = {})
90
+ path_to source, { :dir => 'videos' }.merge(options)
91
+ end
92
+ alias_method :path_to_video, :video_path
93
+
48
94
  class Paths
49
95
  URI_REGEXP = %r{^[-a-z]+://|^cid:|^//}
50
96
 
@@ -1,3 +1,3 @@
1
1
  module Spar
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-12 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -482,4 +482,3 @@ specification_version: 3
482
482
  summary: A simple framework for developing single page web apps with support for haml,
483
483
  sass, coffeescript, and pretty much anything else.
484
484
  test_files: []
485
- has_rdoc: