rapper 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. data/README.markdown +11 -4
  2. data/VERSION +1 -1
  3. data/lib/rapper.rb +7 -2
  4. data/lib/rapper/compressors.rb +13 -9
  5. data/lib/rapper/config.rb +4 -3
  6. data/lib/rapper/definition.rb +45 -14
  7. data/lib/rapper/helpers.rb +45 -0
  8. data/lib/rapper/html_tags.rb +90 -0
  9. data/lib/rapper/logging.rb +1 -0
  10. data/lib/rapper/versioning.rb +1 -1
  11. data/rapper.gemspec +14 -12
  12. data/spec/fixtures/config/{assets → asset_definitions}/base/javascripts.yml +4 -4
  13. data/spec/fixtures/config/{assets → asset_definitions}/base/stylesheets.yml +4 -4
  14. data/spec/fixtures/config/assets.yml +17 -1
  15. data/spec/fixtures/test_cases/compression/definitions/css.yml +2 -2
  16. data/spec/fixtures/test_cases/compression/definitions/js.yml +2 -2
  17. data/spec/fixtures/test_cases/compression/expected/{base.js → javascripts/base.js} +0 -0
  18. data/spec/fixtures/test_cases/compression/expected/{base_reversed.js → javascripts/base_reversed.js} +0 -0
  19. data/spec/fixtures/test_cases/compression/expected/{base.css → stylesheets/base.css} +0 -0
  20. data/spec/fixtures/test_cases/compression/expected/{base_reversed.css → stylesheets/base_reversed.css} +0 -0
  21. data/spec/fixtures/test_cases/concatenation/definitions/css.yml +2 -2
  22. data/spec/fixtures/test_cases/concatenation/definitions/js.yml +2 -2
  23. data/spec/fixtures/test_cases/concatenation/expected/{base.js → javascripts/base.js} +0 -0
  24. data/spec/fixtures/test_cases/concatenation/expected/{base_reversed.js → javascripts/base_reversed.js} +0 -0
  25. data/spec/fixtures/test_cases/concatenation/expected/{base.css → stylesheets/base.css} +0 -0
  26. data/spec/fixtures/test_cases/concatenation/expected/{base_reversed.css → stylesheets/base_reversed.css} +0 -0
  27. data/spec/rapper_spec.rb +71 -21
  28. data/spec/spec_helper.rb +3 -7
  29. metadata +16 -14
data/README.markdown CHANGED
@@ -64,8 +64,8 @@ The following defaults are applied if not defined in your configuration:
64
64
  The `definition_root` setting in the rapper config is a path to a folder containing more YAML files that define the various types of bundles you want to build (eg. `stylesheets.yml`, `javascripts.yml`) Example definition file:
65
65
 
66
66
  ---
67
- - source_root: public/javascripts
68
- - destination_root: public/assets/javascripts
67
+ - root: public/javascripts
68
+ - tag_root: /javascripts
69
69
  - suffix: js
70
70
  - assets:
71
71
  - base:
@@ -85,8 +85,8 @@ The above definition will create two asset files: `public/assets/javascripts/bas
85
85
  If versioning is turned on in your config, version strings will be used to enforce better browser caching of assets. (Version numbers are always used in definition files.)
86
86
 
87
87
  ---
88
- - source_root: public/javascripts
89
- - destination_root: public/assets/javascripts
88
+ - root: public/javascripts
89
+ - tag_root: /javascripts
90
90
  - suffix: js
91
91
  - assets:
92
92
  - base:
@@ -111,6 +111,13 @@ When the contents of the asset change, the version will change in the query stri
111
111
 
112
112
  Browsers will automatically re-download and cache the new asset.
113
113
 
114
+ # Development
115
+
116
+ Rapper's got a Gemfile. You know what to do.
117
+
118
+ bundle install --path vendor
119
+ bundle exec rake spec
120
+
114
121
  ## To do soon
115
122
 
116
123
  * Merb view helpers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.1.0
data/lib/rapper.rb CHANGED
@@ -12,11 +12,15 @@ module Rapper
12
12
  # The main Rapper class. Handles, well, everything.
13
13
  class Engine
14
14
 
15
+ # Base
15
16
  include Rapper::Config
16
17
  include Rapper::Logging
17
18
  include Rapper::Utils
18
19
  include Rapper::Compressors
19
20
  include Rapper::Versioning
21
+ # View helpers
22
+ include Rapper::HtmlTags
23
+ include Rapper::HelperSetup
20
24
 
21
25
  # Load the configuration YAML file and set the current environment.
22
26
  #
@@ -29,6 +33,7 @@ module Rapper
29
33
  @config = {}
30
34
  @definitions = {}
31
35
  load_config( config_path )
36
+ setup_helpers
32
37
  log :verbose, "Loaded rappper with #{environment} environment from #{config_path}"
33
38
  end
34
39
 
@@ -42,14 +47,14 @@ module Rapper
42
47
 
43
48
  types.each do |type|
44
49
  definition = @definitions[type]
45
- source = File.expand_path( definition.source_root )
50
+ source = File.expand_path( definition.root )
46
51
  destination = definition.destination_root
47
52
  suffix = definition.suffix
48
53
 
49
54
  definition.assets.each do |name, spec|
50
55
  next unless needs_packaging?( type, name )
51
56
 
52
- source_files = definition.asset_component_paths( name )
57
+ source_files = definition.component_paths( name )
53
58
  destination_file = definition.asset_path( name )
54
59
 
55
60
  log :verbose, "Joining #{source_files.size} files to #{name}"
@@ -23,10 +23,12 @@ module Rapper
23
23
  class Compressor
24
24
  class << self
25
25
 
26
- # Get the compressor for a given file.
26
+ # Compress a file. Raises UnknownFileExtension if it doesn't know how
27
+ # to compress a file with the given file's file extension.
27
28
  #
28
- # @param [String] file Path to the file to fetch the Compressor for
29
- # @return [Types] Description
29
+ # @param [String] file_path Path to the file to compress.
30
+ #
31
+ # @param [Hash] opts Options to be passed to the compressor (optional).
30
32
  def compress( file_path, opts={} )
31
33
  unless compressor = @extensions[File.extname( file_path )]
32
34
  raise Rapper::Errors::UnknownFileExtension,
@@ -49,22 +51,24 @@ module Rapper
49
51
  end
50
52
 
51
53
  # Compress a file.
54
+ #
55
+ # @param [String] file_path Path to the file to compress.
52
56
  def do_compress( file_path )
53
57
  raise NotImplementedError
54
58
  end
55
59
 
56
- # @param [String] path Path to a file.
60
+ # @param [String] file_path Path to a file.
57
61
  #
58
62
  # @return [String] The contents of the file.
59
- def read_file( path )
60
- File.new( path, 'r' ).read
63
+ def read_file( file_path )
64
+ File.new( file_path, 'r' ).read
61
65
  end
62
66
 
63
- # @param [String] path Path to the desired file.
67
+ # @param [String] file_path Path to the desired file.
64
68
  #
65
69
  # @return [File] Writable file instance with 0644 permissions.
66
- def writable_file( path )
67
- File.new( path, 'w', 0644 )
70
+ def writable_file( file_path )
71
+ File.new( file_path, 'w', 0644 )
68
72
  end
69
73
  end
70
74
  end
data/lib/rapper/config.rb CHANGED
@@ -38,8 +38,8 @@ module Rapper
38
38
  # @param [String] key Configuration key.
39
39
  #
40
40
  # @return [String,Hash] If the current environment's config defines this
41
- # setting, return that value. If not, return the default setting. If the
42
- # default setting is a hash, return the default merged with the
41
+ # setting, returns that value. If not, returns the default setting. If
42
+ # the default setting is a hash, returns the default merged with the
43
43
  # environment's setting.
44
44
  def get_config( key )
45
45
  if default_config[key].is_a?( Hash )
@@ -53,7 +53,8 @@ module Rapper
53
53
  # versions.)
54
54
  #
55
55
  # @param [<String>] types Asset types to update the definition files for.
56
- # Defaults to all types.
56
+ # Defaults to all types (i.e. every type with a definition file in
57
+ # `definition_root`).
57
58
  def update_definitions( *types )
58
59
  types = types.empty? ? asset_types : types
59
60
  log :info, "Updating definitions for #{types.join( ', ' )}"
@@ -7,22 +7,37 @@ module Rapper
7
7
  @path = path
8
8
  @type = File.basename( path, ".yml" )
9
9
  @definition = YAML.load_file( @path )
10
+ # Create asset destination folder, if needed
11
+ Dir.mkdir( destination_root ) unless File.directory?( destination_root )
10
12
  end
11
13
 
12
14
  # =======================
13
15
  # = Definition settings =
14
16
  # =======================
15
17
 
16
- def source_root
17
- first_key_value( "source_root", @definition ) || ""
18
+ # @return [String] The root for asset component files.
19
+ def root
20
+ definition_value( "root" )
18
21
  end
19
22
 
20
23
  def destination_root
21
- first_key_value( "destination_root", @definition ) || ""
24
+ definition_value( "root" ).gsub( /\/$/, '' ) + "/assets"
22
25
  end
23
26
 
27
+ # @return [String] The public url root for the asset component files (used
28
+ # when bundling is off).
29
+ def component_tag_root
30
+ definition_value( "tag_root" )
31
+ end
32
+
33
+ # @return [String] The public url root for packaged asset files.
34
+ def asset_tag_root
35
+ definition_value( "tag_root" ).gsub( /\/$/, '' ) + "/assets"
36
+ end
37
+
38
+ # @return [String] The suffix of files used in this definition.
24
39
  def suffix
25
- first_key_value( "suffix", @definition )
40
+ definition_value( "suffix" )
26
41
  end
27
42
 
28
43
  # ==========
@@ -33,7 +48,7 @@ module Rapper
33
48
  def assets
34
49
  assets = {}
35
50
 
36
- first_key_value( "assets", @definition ).each do |spec|
51
+ definition_value( "assets" ).each do |spec|
37
52
  assets[spec.keys.first] = spec.values.first.inject({}) do |memo, item|
38
53
  memo.merge( item )
39
54
  end
@@ -48,13 +63,27 @@ module Rapper
48
63
  #
49
64
  # @param [String] version New version string for the asset.
50
65
  def set_version( name, version )
51
- first_key_value( "assets", @definition ).each do |spec|
66
+ name = name.to_s
67
+ definition_value( "assets" ).each do |spec|
52
68
  next unless spec[name]
53
69
  spec[name].each do |setting|
54
70
  next unless setting["version"]
55
71
  setting["version"] = version
56
72
  end
57
73
  end
74
+ end
75
+
76
+ def get_version( name )
77
+ name = name.to_s
78
+ definition_value( "assets" ).each do |spec|
79
+ next unless spec[name]
80
+ spec[name].each do |setting|
81
+ next unless setting["version"]
82
+ return setting["version"]
83
+ end
84
+ end
85
+
86
+ false
58
87
  end
59
88
 
60
89
  # ==========
@@ -75,17 +104,19 @@ module Rapper
75
104
  # @param [String] name The asset's name.
76
105
  #
77
106
  # @return [String] Path to the packaged asset file.
78
- def asset_path( name )
107
+ def asset_path( name, root=nil )
108
+ root ||= self.destination_root
79
109
  file_name = "#{name}.#{self.suffix}"
80
- File.join( self.destination_root, file_name )
110
+ File.join( root, file_name )
81
111
  end
82
112
 
83
113
  # @param [String] name Name of the asset.
84
114
  #
85
115
  # @return [Array<String>] Ordered list of the files that comprise the given
86
116
  # asset.
87
- def asset_component_paths( name )
88
- spec = self.assets[name]
117
+ def component_paths( name, root=nil )
118
+ root ||= self.root
119
+ spec = self.assets[name.to_s]
89
120
 
90
121
  if spec.nil?
91
122
  raise Rapper::Errors::InvalidAssetName,
@@ -94,7 +125,7 @@ module Rapper
94
125
 
95
126
  ( spec["files"] || [] ).map do |file|
96
127
  file_name = "#{file}.#{self.suffix}"
97
- File.join( self.source_root, file_name )
128
+ File.join( root, file_name )
98
129
  end
99
130
  end
100
131
 
@@ -106,9 +137,9 @@ module Rapper
106
137
  #
107
138
  # @return [Object,nil] The first value found for the key or nil of nothing
108
139
  # was found.
109
- def first_key_value( key, array )
110
- hash = array.find { |h| h.keys.include? key }
111
- hash ? hash[key] : nil
140
+ def definition_value( key )
141
+ hash = @definition.find { |h| h.keys.include? key }
142
+ hash ? hash[key] : ""
112
143
  end
113
144
  end
114
145
  end
@@ -0,0 +1,45 @@
1
+ module Rapper
2
+ # Set up view helpers for various web frameworks. Currently supported:
3
+ # * Merb
4
+ # To do:
5
+ # * Sinatra
6
+ module HelperSetup
7
+
8
+ # Loads view helpers for any/all available web frameworks available.
9
+ # TODO: Refactor.
10
+ def setup_helpers
11
+ if Rapper::ViewHelpers.const_defined?( :RAPPER )
12
+ Rapper::ViewHelpers.send( :remove_const, :RAPPER )
13
+ end
14
+ Rapper::ViewHelpers.const_set( :RAPPER, self )
15
+
16
+ # Merb
17
+ begin
18
+ Merb::Controller.send( :include, Rapper::ViewHelpers )
19
+ rescue NameError; end
20
+ end
21
+
22
+ private
23
+ end
24
+
25
+ module ViewHelpers
26
+
27
+ RAPPER = nil
28
+
29
+ def self.included( klass )
30
+ klass.class_eval do
31
+ # Define a "rapper_FOO_tag" method for each definition type. For
32
+ # example, if you have "stylesheets" and "javascripts" definitions,
33
+ # you'll have "rapper_stylesheets_tag( name )" and
34
+ # "rapper_javascripts_tag( name )" methods.
35
+ RAPPER.definitions.each do |type, definition|
36
+ tag_method = RAPPER.tag_method_for_type( type )
37
+ define_method "rapper_#{type}_tag".to_sym do |name|
38
+ RAPPER.send( tag_method, type, name )
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,90 @@
1
+ require 'erb'
2
+
3
+ module Rapper
4
+ module HtmlTags
5
+
6
+ def tag_method_for_type( type )
7
+ if @definitions[type].suffix =~ /css/
8
+ :css_tag
9
+ else
10
+ :js_tag
11
+ end
12
+ end
13
+
14
+ def js_tag( type, name )
15
+ self.get_tag( JsTag, type, name )
16
+ end
17
+
18
+ def css_tag( type, name )
19
+ self.get_tag( CssTag, type, name )
20
+ end
21
+
22
+ protected
23
+
24
+ def get_tag( klass, type, name )
25
+ definition = @definitions[type]
26
+ style = self.get_config( 'tag_style' ).to_sym
27
+ version = nil
28
+ if self.get_config( 'version' )
29
+ version = definition.get_version( name )
30
+ end
31
+
32
+ if self.get_config( "bundle" )
33
+ path = definition.asset_path( name, definition.asset_tag_root )
34
+ klass.send( :for, path, version, style )
35
+ else
36
+ paths = definition.component_paths( name, definition.component_tag_root )
37
+ paths.map do |path|
38
+ klass.send( :for, path, version, style )
39
+ end.join( "\n" )
40
+ end
41
+ end
42
+
43
+ class Tag
44
+ class << self
45
+ def templates
46
+ {}
47
+ end
48
+
49
+ def for( path, version, style )
50
+ @cache ||= {}
51
+ @cache[style] ||= {}
52
+
53
+ if version
54
+ path << "?v=#{version}"
55
+ end
56
+
57
+ unless @cache[style][path] && @cache[style][path]
58
+ @cache[style][path] = ERB.new( templates[style] ).result( binding )
59
+ end
60
+
61
+ @cache[style][path]
62
+ end
63
+ end
64
+ end
65
+
66
+ class JsTag < Tag
67
+ class << self
68
+ def templates
69
+ {
70
+ :html => '<script type="text/javascript" src="<%= path %>"></script>',
71
+ :html5 => "<script src=\"<%= path %>\"></script>",
72
+ :xhtml => '<script type="text/javascript" src="<%= path %>"></script>'
73
+ }
74
+ end
75
+ end
76
+ end
77
+
78
+ class CssTag < Tag
79
+ class << self
80
+ def templates
81
+ {
82
+ :html => '<link type="text/css" rel="stylesheet" href="<%= path %>">',
83
+ :html5 => "<link rel=\"stylesheet\" href=\"<%= path %>\">",
84
+ :xhtml => '<link type="text/css" rel="stylesheet" href="<%= path %>" />'
85
+ }
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -4,6 +4,7 @@ module Rapper
4
4
 
5
5
  protected
6
6
 
7
+ # Guess if a string is a path.
7
8
  PATHY_STRING = /\.|\//
8
9
 
9
10
  # Outputs all arguments (joined with spaces) to:
@@ -44,7 +44,7 @@ module Rapper
44
44
  #
45
45
  # @return [String] A four-character version hash for the given asset.
46
46
  def version( type, name )
47
- source_files = @definitions[type].asset_component_paths( name )
47
+ source_files = @definitions[type].component_paths( name )
48
48
  destination_file = Tempfile.new( 'rapper' )
49
49
  join_files( source_files, destination_file.path )
50
50
  version = Digest::MD5.file( destination_file.path ).to_s[0,4]
data/rapper.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rapper}
8
- s.version = "0.0.3"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tyson Tate"]
12
- s.date = %q{2011-02-19}
12
+ s.date = %q{2011-03-09}
13
13
  s.description = %q{Static asset packager and compressor with versioning and built-in view helpers. Easy to configure, easy to use, and easy to ignore when you want to. No crazy JavaScript comment DSLs, either.}
14
14
  s.email = %q{tyson@tysontate.com}
15
15
  s.extra_rdoc_files = [
@@ -30,14 +30,16 @@ Gem::Specification.new do |s|
30
30
  "lib/rapper/config.rb",
31
31
  "lib/rapper/definition.rb",
32
32
  "lib/rapper/errors.rb",
33
+ "lib/rapper/helpers.rb",
34
+ "lib/rapper/html_tags.rb",
33
35
  "lib/rapper/logging.rb",
34
36
  "lib/rapper/utils.rb",
35
37
  "lib/rapper/versioning.rb",
36
38
  "lib/yui/css_compressor.rb",
37
39
  "rapper.gemspec",
40
+ "spec/fixtures/config/asset_definitions/base/javascripts.yml",
41
+ "spec/fixtures/config/asset_definitions/base/stylesheets.yml",
38
42
  "spec/fixtures/config/assets.yml",
39
- "spec/fixtures/config/assets/base/javascripts.yml",
40
- "spec/fixtures/config/assets/base/stylesheets.yml",
41
43
  "spec/fixtures/javascripts/simple_1.js",
42
44
  "spec/fixtures/javascripts/simple_2.js",
43
45
  "spec/fixtures/stylesheets/simple_1.css",
@@ -45,17 +47,17 @@ Gem::Specification.new do |s|
45
47
  "spec/fixtures/test_cases/compression/assets.yml",
46
48
  "spec/fixtures/test_cases/compression/definitions/css.yml",
47
49
  "spec/fixtures/test_cases/compression/definitions/js.yml",
48
- "spec/fixtures/test_cases/compression/expected/base.css",
49
- "spec/fixtures/test_cases/compression/expected/base.js",
50
- "spec/fixtures/test_cases/compression/expected/base_reversed.css",
51
- "spec/fixtures/test_cases/compression/expected/base_reversed.js",
50
+ "spec/fixtures/test_cases/compression/expected/javascripts/base.js",
51
+ "spec/fixtures/test_cases/compression/expected/javascripts/base_reversed.js",
52
+ "spec/fixtures/test_cases/compression/expected/stylesheets/base.css",
53
+ "spec/fixtures/test_cases/compression/expected/stylesheets/base_reversed.css",
52
54
  "spec/fixtures/test_cases/concatenation/assets.yml",
53
55
  "spec/fixtures/test_cases/concatenation/definitions/css.yml",
54
56
  "spec/fixtures/test_cases/concatenation/definitions/js.yml",
55
- "spec/fixtures/test_cases/concatenation/expected/base.css",
56
- "spec/fixtures/test_cases/concatenation/expected/base.js",
57
- "spec/fixtures/test_cases/concatenation/expected/base_reversed.css",
58
- "spec/fixtures/test_cases/concatenation/expected/base_reversed.js",
57
+ "spec/fixtures/test_cases/concatenation/expected/javascripts/base.js",
58
+ "spec/fixtures/test_cases/concatenation/expected/javascripts/base_reversed.js",
59
+ "spec/fixtures/test_cases/concatenation/expected/stylesheets/base.css",
60
+ "spec/fixtures/test_cases/concatenation/expected/stylesheets/base_reversed.css",
59
61
  "spec/fixtures/yui_css/background-position.css",
60
62
  "spec/fixtures/yui_css/background-position.css.min",
61
63
  "spec/fixtures/yui_css/box-model-hack.css",
@@ -1,14 +1,14 @@
1
1
  ---
2
- - source_root: spec/fixtures/javascripts
3
- - destination_root: tmp
2
+ - root: spec/fixtures/javascripts
3
+ - tag_root: /javascripts
4
4
  - suffix: js
5
5
  - assets:
6
6
  - single_file:
7
7
  - files:
8
8
  - simple_1
9
- - version: 0
9
+ - version: abcd
10
10
  - multiple_files:
11
11
  - files:
12
12
  - simple_1
13
13
  - simple_2
14
- - version: 0
14
+ - version: efgh
@@ -1,14 +1,14 @@
1
1
  ---
2
- - source_root: spec/fixtures/stylesheets
3
- - destination_root: tmp
2
+ - root: spec/fixtures/stylesheets
3
+ - tag_root: /stylesheets
4
4
  - suffix: css
5
5
  - assets:
6
6
  - single_file:
7
7
  - files:
8
8
  - simple_1
9
- - version: 0
9
+ - version: abcd
10
10
  - multiple_files:
11
11
  - files:
12
12
  - simple_1
13
13
  - simple_2
14
- - version: 0
14
+ - version: efgh
@@ -1,5 +1,5 @@
1
1
  base: &base
2
- definition_root: spec/fixtures/config/assets/base
2
+ definition_root: spec/fixtures/config/asset_definitions/base
3
3
  test:
4
4
  <<: *base
5
5
  bundle: true
@@ -23,3 +23,19 @@ test_logging_verbose:
23
23
  test_logging_file:
24
24
  <<: *base
25
25
  log: tmp/test_logging_file.log
26
+ test_no_bundle:
27
+ <<: *base
28
+ version: false
29
+ bundle: false
30
+ xhtml_tags:
31
+ <<: *base
32
+ version: false
33
+ tag_style: xhtml
34
+ html5_tags:
35
+ <<: *base
36
+ version: false
37
+ tag_style: html5
38
+ versions:
39
+ <<: *base
40
+ version: true
41
+
@@ -1,6 +1,6 @@
1
1
  ---
2
- - source_root: spec/fixtures/stylesheets
3
- - destination_root: tmp
2
+ - root: spec/fixtures/stylesheets
3
+ - tag_root: /stylesheets
4
4
  - suffix: css
5
5
  - assets:
6
6
  - base:
@@ -1,6 +1,6 @@
1
1
  ---
2
- - source_root: spec/fixtures/javascripts
3
- - destination_root: tmp
2
+ - root: spec/fixtures/javascripts
3
+ - tag_root: /javascripts
4
4
  - suffix: js
5
5
  - assets:
6
6
  - base:
@@ -1,6 +1,6 @@
1
1
  ---
2
- - source_root: spec/fixtures/stylesheets
3
- - destination_root: tmp
2
+ - root: spec/fixtures/stylesheets
3
+ - tag_root: /stylesheets
4
4
  - suffix: css
5
5
  - assets:
6
6
  - base:
@@ -1,6 +1,6 @@
1
1
  ---
2
- - source_root: spec/fixtures/javascripts
3
- - destination_root: tmp
2
+ - root: spec/fixtures/javascripts
3
+ - tag_root: /javascripts
4
4
  - suffix: js
5
5
  - assets:
6
6
  - base:
data/spec/rapper_spec.rb CHANGED
@@ -51,17 +51,18 @@ describe Rapper do
51
51
  rapper.send( :asset_types ).sort.should == ["javascripts", "stylesheets"]
52
52
  rapper.definitions["javascripts"].should be_a( Rapper::Definition )
53
53
  rapper.definitions["stylesheets"].should be_a( Rapper::Definition )
54
- rapper.definitions["javascripts"].source_root.should == "spec/fixtures/javascripts"
55
- rapper.definitions["javascripts"].destination_root.should == "tmp"
54
+ rapper.definitions["javascripts"].root.should == "spec/fixtures/javascripts"
55
+ rapper.definitions["javascripts"].component_tag_root.should == "/javascripts"
56
+ rapper.definitions["javascripts"].asset_tag_root.should == "/javascripts/assets"
56
57
  rapper.definitions["javascripts"].suffix.should == "js"
57
58
  rapper.definitions["javascripts"].assets.should == {
58
59
  "single_file"=>{
59
60
  "files"=>["simple_1"],
60
- "version"=>0
61
+ "version"=>"abcd"
61
62
  },
62
63
  "multiple_files"=>{
63
64
  "files"=>["simple_1", "simple_2"],
64
- "version"=>0
65
+ "version"=>"efgh"
65
66
  }
66
67
  }
67
68
  end
@@ -130,22 +131,34 @@ describe Rapper do
130
131
  Dir["spec/fixtures/test_cases/*"].each do |folder|
131
132
  next unless File.directory?( folder )
132
133
  name = folder.split( "/" ).last
133
- results_path = "tmp/*.*"
134
- expecteds_path = "#{folder}/expected/*.*"
134
+
135
+ paths = [
136
+ {
137
+ :results => "spec/fixtures/javascripts/assets/*.*",
138
+ :expecteds => "#{folder}/expected/javascripts/*.*",
139
+ },
140
+ {
141
+ :results => "spec/fixtures/stylesheets/assets/*.*",
142
+ :expecteds => "#{folder}/expected/stylesheets/*.*",
143
+ }
144
+ ]
135
145
 
136
146
  it "passes the \"#{name}\" test case" do
137
147
  rapper = Rapper::Engine.new( "#{folder}/assets.yml", "test" )
138
148
  rapper.package
139
149
 
140
- # Produces the same exact individual files
141
- file_names( results_path ).should == file_names( expecteds_path )
142
- # Contents are all the same
143
- results = Dir[results_path]
144
- expecteds = Dir[expecteds_path]
150
+ paths.each do |path|
145
151
 
146
- results.each_index do |i|
147
- unless File.read( results[i] ) == File.read( expecteds[i] )
148
- raise "#{results[i]} did not match #{expecteds[i]}"
152
+ # Produces the same exact individual files
153
+ file_names( path[:results] ).should == file_names( path[:expecteds] )
154
+ # Contents are all the same
155
+ results = Dir[ path[:results] ]
156
+ expecteds = Dir[ path[:expecteds] ]
157
+
158
+ results.each_index do |i|
159
+ unless File.read( results[i] ) == File.read( expecteds[i] )
160
+ raise "#{results[i]} did not match #{expecteds[i]}"
161
+ end
149
162
  end
150
163
  end
151
164
  end
@@ -157,12 +170,49 @@ describe Rapper do
157
170
  end
158
171
 
159
172
  describe "view helpers" do
160
- it "returns tags for component files when bundling is off"
161
- it "returns tabs for asset when bundling is on"
162
- it "can return html"
163
- it "can return xhtml"
164
- it "can return html5"
165
- it "adds a version number if versioning is on"
166
- it "doesn't add a version number if versioning is off"
173
+
174
+ module Merb; class Controller; end; end
175
+
176
+ before :each do
177
+ @controller = Merb::Controller.new
178
+ end
179
+
180
+ it "returns tags for component files when bundling is off" do
181
+ Rapper::Engine.new( "spec/fixtures/config/assets.yml", "test_no_bundle" )
182
+ @controller.rapper_stylesheets_tag( :single_file ).should == "<link rel=\"stylesheet\" href=\"/stylesheets/simple_1.css\">"
183
+ @controller.rapper_stylesheets_tag( :multiple_files ).should == "<link rel=\"stylesheet\" href=\"/stylesheets/simple_1.css\">\n<link rel=\"stylesheet\" href=\"/stylesheets/simple_2.css\">"
184
+ @controller.rapper_javascripts_tag( :single_file ).should == "<script src=\"/javascripts/simple_1.js\"></script>"
185
+ @controller.rapper_javascripts_tag( :multiple_files ).should == "<script src=\"/javascripts/simple_1.js\"></script>\n<script src=\"/javascripts/simple_2.js\"></script>"
186
+ end
187
+
188
+ it "returns tags for asset when bundling is on" do
189
+ Rapper::Engine.new( "spec/fixtures/config/assets.yml", "test" )
190
+ @controller.rapper_stylesheets_tag( :single_file ).should == "<link type=\"text/css\" rel=\"stylesheet\" href=\"/stylesheets/assets/single_file.css\">"
191
+ @controller.rapper_stylesheets_tag( :multiple_files ).should == "<link type=\"text/css\" rel=\"stylesheet\" href=\"/stylesheets/assets/multiple_files.css\">"
192
+ @controller.rapper_javascripts_tag( :single_file ).should == "<script type=\"text/javascript\" src=\"/javascripts/assets/single_file.js\"></script>"
193
+ @controller.rapper_javascripts_tag( :multiple_files ).should == "<script type=\"text/javascript\" src=\"/javascripts/assets/multiple_files.js\"></script>"
194
+ end
195
+
196
+ it "can return xhtml tags" do
197
+ Rapper::Engine.new( "spec/fixtures/config/assets.yml", "xhtml_tags" )
198
+ @controller.rapper_stylesheets_tag( :single_file ).should == "<link type=\"text/css\" rel=\"stylesheet\" href=\"/stylesheets/assets/single_file.css\" />"
199
+ @controller.rapper_stylesheets_tag( :multiple_files ).should == "<link type=\"text/css\" rel=\"stylesheet\" href=\"/stylesheets/assets/multiple_files.css\" />"
200
+ @controller.rapper_javascripts_tag( :single_file ).should == "<script type=\"text/javascript\" src=\"/javascripts/assets/single_file.js\"></script>"
201
+ @controller.rapper_javascripts_tag( :multiple_files ).should == "<script type=\"text/javascript\" src=\"/javascripts/assets/multiple_files.js\"></script>"
202
+ end
203
+
204
+ it "can return html5 tags" do
205
+ Rapper::Engine.new( "spec/fixtures/config/assets.yml", "html5_tags" )
206
+ @controller.rapper_stylesheets_tag( :single_file ).should == "<link rel=\"stylesheet\" href=\"/stylesheets/assets/single_file.css\">"
207
+ @controller.rapper_stylesheets_tag( :multiple_files ).should == "<link rel=\"stylesheet\" href=\"/stylesheets/assets/multiple_files.css\">"
208
+ @controller.rapper_javascripts_tag( :single_file ).should == "<script src=\"/javascripts/assets/single_file.js\"></script>"
209
+ @controller.rapper_javascripts_tag( :multiple_files ).should == "<script src=\"/javascripts/assets/multiple_files.js\"></script>"
210
+ end
211
+
212
+ it "adds a version number if versioning is on" do
213
+ Rapper::Engine.new( "spec/fixtures/config/assets.yml", "versions" )
214
+ @controller.rapper_stylesheets_tag( :single_file ).should == "<link rel=\"stylesheet\" href=\"/stylesheets/assets/single_file.css?v=abcd\">"
215
+ @controller.rapper_javascripts_tag( :single_file ).should == "<script src=\"/javascripts/assets/single_file.js?v=abcd\"></script>"
216
+ end
167
217
  end
168
218
  end
data/spec/spec_helper.rb CHANGED
@@ -6,14 +6,10 @@ require 'fileutils'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
8
 
9
- # Setup and tear down tmp files.
10
-
11
- config.before :all do
12
- Dir::mkdir( "tmp" ) unless FileTest::directory?( "tmp" )
13
- end
14
-
9
+ # Tear down test case assets folders
15
10
  config.after :each do
16
- Dir[ "tmp/*" ].each { |f| FileUtils.rm( f ) }
11
+ FileUtils.rm_r( Dir[ "tmp/*" ] )
12
+ FileUtils.rm_r( Dir[ "spec/fixtures/*/assets" ] )
17
13
  end
18
14
  end
19
15
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 0.0.3
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyson Tate
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-19 00:00:00 -08:00
18
+ date: 2011-03-09 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -233,14 +233,16 @@ files:
233
233
  - lib/rapper/config.rb
234
234
  - lib/rapper/definition.rb
235
235
  - lib/rapper/errors.rb
236
+ - lib/rapper/helpers.rb
237
+ - lib/rapper/html_tags.rb
236
238
  - lib/rapper/logging.rb
237
239
  - lib/rapper/utils.rb
238
240
  - lib/rapper/versioning.rb
239
241
  - lib/yui/css_compressor.rb
240
242
  - rapper.gemspec
243
+ - spec/fixtures/config/asset_definitions/base/javascripts.yml
244
+ - spec/fixtures/config/asset_definitions/base/stylesheets.yml
241
245
  - spec/fixtures/config/assets.yml
242
- - spec/fixtures/config/assets/base/javascripts.yml
243
- - spec/fixtures/config/assets/base/stylesheets.yml
244
246
  - spec/fixtures/javascripts/simple_1.js
245
247
  - spec/fixtures/javascripts/simple_2.js
246
248
  - spec/fixtures/stylesheets/simple_1.css
@@ -248,17 +250,17 @@ files:
248
250
  - spec/fixtures/test_cases/compression/assets.yml
249
251
  - spec/fixtures/test_cases/compression/definitions/css.yml
250
252
  - spec/fixtures/test_cases/compression/definitions/js.yml
251
- - spec/fixtures/test_cases/compression/expected/base.css
252
- - spec/fixtures/test_cases/compression/expected/base.js
253
- - spec/fixtures/test_cases/compression/expected/base_reversed.css
254
- - spec/fixtures/test_cases/compression/expected/base_reversed.js
253
+ - spec/fixtures/test_cases/compression/expected/javascripts/base.js
254
+ - spec/fixtures/test_cases/compression/expected/javascripts/base_reversed.js
255
+ - spec/fixtures/test_cases/compression/expected/stylesheets/base.css
256
+ - spec/fixtures/test_cases/compression/expected/stylesheets/base_reversed.css
255
257
  - spec/fixtures/test_cases/concatenation/assets.yml
256
258
  - spec/fixtures/test_cases/concatenation/definitions/css.yml
257
259
  - spec/fixtures/test_cases/concatenation/definitions/js.yml
258
- - spec/fixtures/test_cases/concatenation/expected/base.css
259
- - spec/fixtures/test_cases/concatenation/expected/base.js
260
- - spec/fixtures/test_cases/concatenation/expected/base_reversed.css
261
- - spec/fixtures/test_cases/concatenation/expected/base_reversed.js
260
+ - spec/fixtures/test_cases/concatenation/expected/javascripts/base.js
261
+ - spec/fixtures/test_cases/concatenation/expected/javascripts/base_reversed.js
262
+ - spec/fixtures/test_cases/concatenation/expected/stylesheets/base.css
263
+ - spec/fixtures/test_cases/concatenation/expected/stylesheets/base_reversed.css
262
264
  - spec/fixtures/yui_css/background-position.css
263
265
  - spec/fixtures/yui_css/background-position.css.min
264
266
  - spec/fixtures/yui_css/box-model-hack.css