githubbish_assets 0.1.1 → 0.1.2

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{githubbish_assets}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Dashevskii"]
12
- s.date = %q{2011-01-06}
12
+ s.date = %q{2011-01-07}
13
13
  s.description = %q{Github style assets bundling in a Rails 3 engine}
14
14
  s.email = %q{olegdashevski@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "githubbish_assets.gemspec",
28
28
  "lib/githubbish_assets.rb",
29
29
  "lib/githubbish_assets/helper.rb",
30
+ "lib/githubbish_assets/lister.rb",
30
31
  "lib/githubbish_assets/packer.rb",
31
32
  "lib/vendor/js_minimizer.rb",
32
33
  "test/helper.rb",
@@ -1,5 +1,6 @@
1
1
  require 'rails'
2
2
  require 'active_support'
3
+ require 'githubbish_assets/lister'
3
4
  require 'githubbish_assets/packer'
4
5
  require 'githubbish_assets/helper'
5
6
 
@@ -28,15 +28,7 @@ module GithubbishAssets
28
28
  end
29
29
 
30
30
  def javascript_include_files(bundles)
31
- output = ""
32
- bundles.each do |bundle|
33
- files = GithubbishAssets::Packer.recursive_file_list("public/javascripts/#{bundle}", ".js")
34
- files.each do |file|
35
- file = file.gsub('public/javascripts/', '')
36
- output << javascript_src_tag(file, {}) + "\n"
37
- end
38
- end
39
- output.html_safe
31
+ _gh_include_files("public/javascripts", ".js", bundles) { |file| javascript_src_tag(file) }
40
32
  end
41
33
 
42
34
  def javascript_dev(*sources)
@@ -60,14 +52,22 @@ module GithubbishAssets
60
52
  end
61
53
 
62
54
  def stylesheet_include_files(bundles)
55
+ _gh_include_files("public/stylesheets", ".css", bundles) { |file| stylesheet_link_tag(file) }
56
+ end
57
+
58
+ private
59
+
60
+ def _gh_include_files(asset_root, ext, bundles)
61
+ p_asset_root = Rails.root + asset_root
63
62
  output = ""
63
+
64
64
  bundles.each do |bundle|
65
- files = GithubbishAssets::Packer.recursive_file_list("public/stylesheets/#{bundle}", ".css")
65
+ files = RecursiveLister[p_asset_root + bundle.to_s, ext]
66
66
  files.each do |file|
67
- file = file.gsub('public/stylesheets/', '')
68
- output << stylesheet_link_tag(file) + "\n"
67
+ output << yield(file.relative_path_from(p_asset_root).to_s) << "\n"
69
68
  end
70
69
  end
70
+
71
71
  output.html_safe
72
72
  end
73
73
  end
@@ -0,0 +1,13 @@
1
+ module GithubbishAssets
2
+ class RecursiveLister
3
+ def self.[](root, ext)
4
+ files = []
5
+
6
+ root.find do |path|
7
+ files << path if path.file? && path.extname == ext
8
+ end
9
+
10
+ files.sort
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,4 @@
1
1
  require 'yui/compressor'
2
- require 'find'
3
2
 
4
3
  module GithubbishAssets
5
4
  class Packer
@@ -11,7 +10,7 @@ module GithubbishAssets
11
10
  require 'closure-compiler'
12
11
  end
13
12
 
14
- pack('public/javascripts', '.js') do |target, files|
13
+ pack(Rails.root + 'public/javascripts', '.js') do |target, files|
15
14
  case GithubbishAssets.js_compressor
16
15
  when :closure
17
16
  opts = [ [:js_output_file, target] ]
@@ -36,38 +35,23 @@ module GithubbishAssets
36
35
  end
37
36
 
38
37
  def self.css
39
- pack('public/stylesheets', '.css') do |target, files|
38
+ pack(Rails.root + 'public/stylesheets', '.css') do |target, files|
40
39
  compress_with_yui(YUI::CssCompressor.new(:line_break => 0), files, target)
41
40
  end
42
41
  end
43
42
 
44
- def self.recursive_file_list(basedir, ext)
45
- files = []
46
- Find.find(basedir) do |path|
47
- if FileTest.directory?(path)
48
- if File.basename(path)[0] == ?. # Skip dot directories
49
- Find.prune
50
- else
51
- next
52
- end
53
- end
54
- files << path if File.extname(path) == ext
55
- end
56
- files.sort
57
- end
58
-
59
-
60
43
  private
61
44
 
62
- def self.pack(relpath, ext)
45
+ def self.pack(path, ext)
63
46
  targets = []
64
- get_top_level_directories(relpath).each do |bundle_directory|
47
+ get_top_level_directories(path).each do |bundle_directory|
65
48
  bundle_name = bundle_directory.basename
49
+ next if bundle_name.to_s == 'dev'
66
50
 
67
- files = recursive_file_list(bundle_directory, ext)
68
- next if files.empty? || bundle_name == 'dev'
51
+ files = RecursiveLister[bundle_directory, ext]
52
+ next if files.empty?
69
53
 
70
- target = Rails.root + relpath + "bundle_#{bundle_name}#{ext}"
54
+ target = path + "bundle_#{bundle_name}#{ext}"
71
55
 
72
56
  yield target, files
73
57
 
@@ -77,12 +61,8 @@ module GithubbishAssets
77
61
  targets
78
62
  end
79
63
 
80
- def self.get_top_level_directories(base_path)
81
- Dir.entries(Rails.root + base_path).collect do |path|
82
- if path[0] != ?. && (Rails.root + base_path + path).directory?
83
- path
84
- end
85
- end.compact
64
+ def self.get_top_level_directories(root_path)
65
+ root_path.children.select { |path| path.directory? }
86
66
  end
87
67
 
88
68
  def self.compress_with_yui(compressor, files, target)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: githubbish_assets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oleg Dashevskii
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-06 00:00:00 +06:00
18
+ date: 2011-01-07 00:00:00 +06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -128,6 +128,7 @@ files:
128
128
  - githubbish_assets.gemspec
129
129
  - lib/githubbish_assets.rb
130
130
  - lib/githubbish_assets/helper.rb
131
+ - lib/githubbish_assets/lister.rb
131
132
  - lib/githubbish_assets/packer.rb
132
133
  - lib/vendor/js_minimizer.rb
133
134
  - test/helper.rb