rapper 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -51,6 +51,7 @@ The `definition_root` setting in the rapper config is a path to a folder contain
51
51
 
52
52
  --- !omap
53
53
  - root: public/javascripts
54
+ - destination_root: public/assets # optional, default: root + "/assets"
54
55
  - tag_root: /javascripts
55
56
  - suffix: js
56
57
  - assets: !omap
@@ -64,10 +65,14 @@ The `definition_root` setting in the rapper config is a path to a folder contain
64
65
  - ext_js_full
65
66
  - version: db62
66
67
 
67
- The above definition will create two asset files: `public/javascripts/assets/base.js` and `public/javascripts/assets/stats.js` from the component files in `public/javascripts` (in this case: `public/javascripts/protovis.js` and `public/javascripts/ext_js_full.js`).
68
+ The above definition will create two asset files: `public/assets/base.js` and `public/assets/stats.js` from the component files in `public/javascripts` (in this case: `public/javascripts/protovis.js` and `public/javascripts/ext_js_full.js`).
68
69
 
69
70
  **Note:** Definition files are YAML ordered mapping documents. This is so that version updates (which involves rapper updating the version numbers and writing out the updated definition as YAML) don't change the order of the file. This is especially useful when using git and merging branches because it prevents nasty merge conflicts.
70
71
 
72
+ ## View helpers
73
+
74
+ Rapper provides helper methods to generate HTML include tags for your assets in the `Rapper::ViewHelpers`. Simply `include` it in the appropriate place for your web app / framework / widget / whatever. It's automaticallly included for Merb.
75
+
71
76
  ## Versioning
72
77
 
73
78
  Version strings are short hashes of the before-compression asset file. This means that they will only change when the contents of the component files for an asset change and time-consuming compression will only happen when a bundle needs to be re-packaged.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/rapper.rb CHANGED
@@ -9,7 +9,6 @@ require File.dirname( __FILE__ ) + "/tasks.rb"
9
9
  # No holds barred, no time for move fakin' /
10
10
  # Gots to get the loot so I can bring home the bacon
11
11
  module Rapper
12
-
13
12
  # The main Rapper class. Handles, well, everything.
14
13
  class Engine
15
14
 
@@ -27,8 +26,8 @@ module Rapper
27
26
  #
28
27
  # @param [String] config_path Path to the configuration YAML file.
29
28
  #
30
- # @param [String,Symbol] environment The current environment. This must
31
- # map to an environment configured in the Rapper configuration file.
29
+ # @param [String,Symbol] environment The current environment. This must map
30
+ # to an environment configured in the Rapper configuration file.
32
31
  def initialize( config_path, environment )
33
32
  @environment = environment
34
33
  @config = {}
@@ -49,7 +48,6 @@ module Rapper
49
48
  types.each do |type|
50
49
  definition = @definitions[type]
51
50
  source = File.expand_path( definition.root )
52
- destination = definition.destination_root
53
51
  suffix = definition.suffix
54
52
 
55
53
  definition.assets.each do |name, spec|
@@ -58,7 +56,7 @@ module Rapper
58
56
  source_files = definition.component_paths( name )
59
57
  destination_file = definition.asset_path( name )
60
58
 
61
- log :verbose, "Joining #{source_files.size} files to #{name}"
59
+ log :verbose, "Joining #{source_files.size} files to #{destination_file}"
62
60
  join_files( source_files, destination_file )
63
61
 
64
62
  if get_config( "compress" )
@@ -21,7 +21,8 @@ module Rapper
21
21
  end
22
22
 
23
23
  def destination_root
24
- @definition["root"].gsub( /\/$/, '' ) + "/assets"
24
+ @default_destination_root ||= @definition["root"].gsub( /\/$/, '' ) + "/assets"
25
+ @definition["destination_root"] || @default_destination_root
25
26
  end
26
27
 
27
28
  # @return [String] The public url root for the asset component files (used
@@ -44,6 +45,8 @@ module Rapper
44
45
  # = Assets =
45
46
  # ==========
46
47
 
48
+ # @return [YAML::Omap] Ordered mapping of definition keys to definition
49
+ # configuration (as a `YAML::Omap`).
47
50
  def assets
48
51
  @definition["assets"]
49
52
  end
@@ -54,11 +57,11 @@ module Rapper
54
57
  #
55
58
  # @param [String] version New version string for the asset.
56
59
  def set_version( name, version )
57
- @definition["assets"][name.to_s]["version"] = version
60
+ assets[name.to_s]["version"] = version
58
61
  end
59
62
 
60
63
  def get_version( name )
61
- @definition["assets"][name.to_s]["version"]
64
+ assets[name.to_s]["version"]
62
65
  end
63
66
 
64
67
  # ==========
@@ -1,8 +1,5 @@
1
1
  module Rapper
2
- # Set up view helpers for various web frameworks. Currently supported:
3
- # * Merb
4
- # To do:
5
- # * Sinatra
2
+ # Helpers for setting up view helpers.
6
3
  module HelperSetup
7
4
 
8
5
  # Loads view helpers for any/all available web frameworks available.
@@ -22,8 +19,8 @@ module Rapper
22
19
  private
23
20
  end
24
21
 
22
+ # View helpers.
25
23
  module ViewHelpers
26
-
27
24
  RAPPER = nil
28
25
 
29
26
  def self.included( klass )
@@ -41,5 +38,4 @@ module Rapper
41
38
  end
42
39
  end
43
40
  end
44
-
45
41
  end
@@ -1,8 +1,13 @@
1
1
  require 'erb'
2
2
 
3
3
  module Rapper
4
+ # HTML tag generators.
4
5
  module HtmlTags
5
6
 
7
+ # @param [Symbol] type Definition type.
8
+ #
9
+ # @return [Symbol] Tag type for the given definition type. One of `:css_tag`
10
+ # or `:js_tag`
6
11
  def tag_method_for_type( type )
7
12
  if @definitions[type].suffix =~ /css/
8
13
  :css_tag
@@ -11,10 +16,26 @@ module Rapper
11
16
  end
12
17
  end
13
18
 
19
+ # Build a JS tag for an asset.
20
+ #
21
+ # @param [Symbol] type Definition type.
22
+ #
23
+ # @param [Symbol] name Name of the asset to build a `<script>` tag for.
24
+ #
25
+ # @return [String] A `<script>` tag for the given asset in the configured
26
+ # HTML style.
14
27
  def js_tag( type, name )
15
28
  self.get_tag( JsTag, type, name )
16
29
  end
17
30
 
31
+ # Build a CSS tag for an asset.
32
+ #
33
+ # @param [Symbol] name Name of the asset to build a `<link>` tag for.
34
+ #
35
+ # @param [Symbol] name Name of the asset to build a `<link>` tag for.
36
+ #
37
+ # @return [String] A `<link>` tag for the given asset in the configured
38
+ # HTML style.
18
39
  def css_tag( type, name )
19
40
  self.get_tag( CssTag, type, name )
20
41
  end
@@ -40,12 +61,27 @@ module Rapper
40
61
  end
41
62
  end
42
63
 
64
+ # Represents an HTML tag.
43
65
  class Tag
44
66
  class << self
67
+
68
+ # @return [Hash] A mapping of HTML styles to their appropriate HTML
69
+ # tag template strings.
45
70
  def templates
46
- {}
71
+ { :html => '', :html5 => '', :xhtml => '' }
47
72
  end
48
73
 
74
+ # Build an HTML tag for a given resource in a given HTML style.
75
+ #
76
+ # @param [String] path Publically accessible path to the asset file.
77
+ #
78
+ # @param [String,nil] version Version string to append as a query
79
+ # string.
80
+ #
81
+ # @param [Symbol] style HTML tag style. One of `:html`, `:html5`, or
82
+ # `:xhtml`.
83
+ #
84
+ # @return [String] The appropriate HTML tag to include the resource.
49
85
  def for( path, version, style )
50
86
  @cache ||= {}
51
87
  @cache[style] ||= {}
@@ -63,6 +99,7 @@ module Rapper
63
99
  end
64
100
  end
65
101
 
102
+ # JavaScript tag.
66
103
  class JsTag < Tag
67
104
  class << self
68
105
  def templates
@@ -75,6 +112,7 @@ module Rapper
75
112
  end
76
113
  end
77
114
 
115
+ # CSS tag.
78
116
  class CssTag < Tag
79
117
  class << self
80
118
  def templates
@@ -14,7 +14,7 @@ module Rapper
14
14
  # period in it).
15
15
  #
16
16
  # @param [Symbol] level Log level. :info or :verbose. :verbose level log
17
- # messages are only emitted if the "verbose_logging" setting is truthy.
17
+ # messages are only emitted if the "verbose_logging" setting is truthy.
18
18
  #
19
19
  # @param [String] message Message to be logged.
20
20
  def log( level, message )
data/lib/rapper/utils.rb CHANGED
@@ -11,7 +11,7 @@ module Rapper
11
11
  # Concatenate one or more files. Uses <code>cat</code>.
12
12
  #
13
13
  # @param [Array<String>,String] source_files A path or array of paths to
14
- # files to concatenate.
14
+ # files to concatenate.
15
15
  #
16
16
  # @param [String] destination_file Destination for concatenated output.
17
17
  def join_files( source_files, destination_file )
data/lib/tasks.rb CHANGED
@@ -3,6 +3,14 @@ module Rapper
3
3
  # Rake tasks for building / refreshing packages
4
4
  class Tasks
5
5
 
6
+ # Set up rapper asset packaging Rake tasks.
7
+ #
8
+ # @param [Symbol] namespace The Rake namespace to put the generated
9
+ # tasks under.
10
+ #
11
+ # @yield [config] Configuration hash. `:path` should be the path to the
12
+ # configuration YAML file. `:env` is the optional environment. Defaults to
13
+ # `:production`.
6
14
  def initialize( namespace = :rapper, &block )
7
15
  @namespace = namespace
8
16
  @config = {}
@@ -14,6 +22,8 @@ module Rapper
14
22
 
15
23
  private
16
24
 
25
+ # Creates all rapper rake tasks: package all assets, package assets for
26
+ # each type.
17
27
  def define
18
28
  namespace @namespace do
19
29
  desc "Package all assets that need re-packaging"
@@ -24,7 +34,7 @@ module Rapper
24
34
  namespace :package do
25
35
  @rapper.definitions.each do |type, definition|
26
36
  desc "Package all #{type} assets that need re-packaging"
27
- task key do
37
+ task type do
28
38
  @rapper.package( type )
29
39
  end
30
40
  end
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.1.1"
8
+ s.version = "0.2.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-03-23}
12
+ s.date = %q{2011-04-02}
13
13
  s.description = %q{Static asset packager and compressor with versioning and built-in view helpers. Compresses files only when they need compressing.}
14
14
  s.email = %q{tyson@tysontate.com}
15
15
  s.extra_rdoc_files = [
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  "rapper.gemspec",
41
41
  "spec/fixtures/config/asset_definitions/base/javascripts.yml",
42
42
  "spec/fixtures/config/asset_definitions/base/stylesheets.yml",
43
+ "spec/fixtures/config/asset_definitions/custom_destination/javascripts.yml",
43
44
  "spec/fixtures/config/assets.yml",
44
45
  "spec/fixtures/javascripts/simple_1.js",
45
46
  "spec/fixtures/javascripts/simple_2.js",
@@ -0,0 +1,11 @@
1
+ --- !omap
2
+ - root: spec/fixtures/javascripts
3
+ - destination_root: tmp/custom_destination
4
+ - tag_root: /javascripts
5
+ - suffix: js
6
+ - assets: !omap
7
+ - multiple_files: !omap
8
+ - files:
9
+ - simple_1
10
+ - simple_2
11
+ - version: f3d9
@@ -27,6 +27,11 @@ test_no_bundle:
27
27
  <<: *base
28
28
  version: false
29
29
  bundle: false
30
+ test_custom_destination:
31
+ <<: *base
32
+ definition_root: spec/fixtures/config/asset_definitions/custom_destination
33
+ bundle: true
34
+ compress: false
30
35
  xhtml_tags:
31
36
  <<: *base
32
37
  version: false
data/spec/rapper_spec.rb CHANGED
@@ -127,6 +127,14 @@ describe Rapper do
127
127
  end
128
128
  end
129
129
 
130
+ describe "custom definition destination" do
131
+ it "works" do
132
+ rapper = Rapper::Engine.new( "spec/fixtures/config/assets.yml", "test_custom_destination" )
133
+ rapper.package
134
+ Dir[ "tmp/custom_destination/*" ].should == ["tmp/custom_destination/multiple_files.js"]
135
+ end
136
+ end
137
+
130
138
  describe "packaging test cases" do
131
139
  Dir["spec/fixtures/test_cases/*"].each do |folder|
132
140
  next unless File.directory?( folder )
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: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyson Tate
@@ -15,13 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-23 00:00:00 -07:00
18
+ date: 2011-04-02 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  prerelease: false
23
- name: closure-compiler
24
- type: :runtime
25
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
26
24
  none: false
27
25
  requirements:
@@ -33,11 +31,11 @@ dependencies:
33
31
  - 0
34
32
  - 0
35
33
  version: 1.0.0
34
+ type: :runtime
36
35
  requirement: *id001
36
+ name: closure-compiler
37
37
  - !ruby/object:Gem::Dependency
38
38
  prerelease: false
39
- name: rspec
40
- type: :development
41
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
42
40
  none: false
43
41
  requirements:
@@ -49,11 +47,11 @@ dependencies:
49
47
  - 3
50
48
  - 1
51
49
  version: 1.3.1
50
+ type: :development
52
51
  requirement: *id002
52
+ name: rspec
53
53
  - !ruby/object:Gem::Dependency
54
54
  prerelease: false
55
- name: yard
56
- type: :development
57
55
  version_requirements: &id003 !ruby/object:Gem::Requirement
58
56
  none: false
59
57
  requirements:
@@ -65,11 +63,11 @@ dependencies:
65
63
  - 6
66
64
  - 4
67
65
  version: 0.6.4
66
+ type: :development
68
67
  requirement: *id003
68
+ name: yard
69
69
  - !ruby/object:Gem::Dependency
70
70
  prerelease: false
71
- name: bluecloth
72
- type: :development
73
71
  version_requirements: &id004 !ruby/object:Gem::Requirement
74
72
  none: false
75
73
  requirements:
@@ -81,11 +79,11 @@ dependencies:
81
79
  - 0
82
80
  - 10
83
81
  version: 2.0.10
82
+ type: :development
84
83
  requirement: *id004
84
+ name: bluecloth
85
85
  - !ruby/object:Gem::Dependency
86
86
  prerelease: false
87
- name: bundler
88
- type: :development
89
87
  version_requirements: &id005 !ruby/object:Gem::Requirement
90
88
  none: false
91
89
  requirements:
@@ -97,11 +95,11 @@ dependencies:
97
95
  - 0
98
96
  - 0
99
97
  version: 1.0.0
98
+ type: :development
100
99
  requirement: *id005
100
+ name: bundler
101
101
  - !ruby/object:Gem::Dependency
102
102
  prerelease: false
103
- name: jeweler
104
- type: :development
105
103
  version_requirements: &id006 !ruby/object:Gem::Requirement
106
104
  none: false
107
105
  requirements:
@@ -113,11 +111,11 @@ dependencies:
113
111
  - 5
114
112
  - 2
115
113
  version: 1.5.2
114
+ type: :development
116
115
  requirement: *id006
116
+ name: jeweler
117
117
  - !ruby/object:Gem::Dependency
118
118
  prerelease: false
119
- name: rake
120
- type: :development
121
119
  version_requirements: &id007 !ruby/object:Gem::Requirement
122
120
  none: false
123
121
  requirements:
@@ -129,7 +127,9 @@ dependencies:
129
127
  - 8
130
128
  - 7
131
129
  version: 0.8.7
130
+ type: :development
132
131
  requirement: *id007
132
+ name: rake
133
133
  description: Static asset packager and compressor with versioning and built-in view helpers. Compresses files only when they need compressing.
134
134
  email: tyson@tysontate.com
135
135
  executables: []
@@ -163,6 +163,7 @@ files:
163
163
  - rapper.gemspec
164
164
  - spec/fixtures/config/asset_definitions/base/javascripts.yml
165
165
  - spec/fixtures/config/asset_definitions/base/stylesheets.yml
166
+ - spec/fixtures/config/asset_definitions/custom_destination/javascripts.yml
166
167
  - spec/fixtures/config/assets.yml
167
168
  - spec/fixtures/javascripts/simple_1.js
168
169
  - spec/fixtures/javascripts/simple_2.js