assetify 0.0.2 → 0.1.1

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/README.md CHANGED
@@ -22,7 +22,7 @@ This will create a Jsfile if not found.
22
22
 
23
23
 
24
24
  Jsfile
25
- ------
25
+ ======
26
26
 
27
27
  Just like a Gemfile, but you choose the filetype before:
28
28
 
@@ -33,12 +33,44 @@ Just like a Gemfile, but you choose the filetype before:
33
33
 
34
34
  Now just run assetify to make sure everything is installed/up-to-date.
35
35
 
36
- Options:
37
36
 
38
- newname true || false
39
- jspath "new/path"
40
- csspath "new/path"
41
- imgpath "new/path"
37
+ Groups
38
+ ------
39
+
40
+ When using some compressor/minimizer (Jammit/Smurf...) namespaces come
41
+ in handy:
42
+
43
+ group "forms" do
44
+ js "validator", "link"
45
+ end
46
+
47
+
48
+ This will install as "public/javascripts/forms/validator.js"
49
+
50
+
51
+ Pkgs
52
+ ----
53
+
54
+ Big projects makes you download tons of files for some .min files and css.
55
+
56
+ pkg "fancy", "http://to.tgz.or.zip" do
57
+ js "cool", "internal/js/cool"
58
+ css "cool", "internal/css/cool"
59
+ end
60
+
61
+ This downloads and 'cherry pick' the files.
62
+
63
+
64
+
65
+ Options
66
+ -------
67
+
68
+ Change some default settings:
69
+
70
+ newname true || false
71
+ jspath "public/javascripts"
72
+ csspath "public/stylesheets"
73
+ imgpath "public/images"
42
74
 
43
75
 
44
76
  If newname is set to true (default) the file will be renamed. Ex:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.1
data/assetify.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{assetify}
8
- s.version = "0.0.2"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcos Piccinini"]
12
- s.date = %q{2011-05-12}
12
+ s.date = %q{2011-05-15}
13
13
  s.default_executable = %q{assetify}
14
14
  s.description = %q{Downloads/updates assets based on a Jsfile. Any framework.}
15
15
  s.email = %q{x@nofxx.com}
@@ -30,7 +30,13 @@ Gem::Specification.new do |s|
30
30
  "lib/assetify.rb",
31
31
  "lib/assetify/asset.rb",
32
32
  "lib/assetify/dsl.rb",
33
+ "lib/assetify/helpers.rb",
34
+ "lib/assetify/pkg.rb",
35
+ "spec/assetify/asset_spec.rb",
36
+ "spec/assetify/dsl_spec.rb",
37
+ "spec/assetify/pkg_spec.rb",
33
38
  "spec/assetify_spec.rb",
39
+ "spec/fixtures/fancy.tgz",
34
40
  "spec/spec_helper.rb"
35
41
  ]
36
42
  s.homepage = %q{http://github.com/nofxx/assetify}
data/bin/assetify CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #require 'rubygems'
3
- # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  require 'optparse'
5
5
  require 'assetify'
6
6
 
data/lib/assetify.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require "assetify/helpers"
1
2
  require "assetify/asset"
2
3
  require "assetify/dsl"
4
+ require "assetify/pkg"
3
5
 
4
6
  module Assetify
5
7
 
@@ -21,10 +23,21 @@ module Assetify
21
23
  unless res =~ /n|N/
22
24
  File.open("Jsfile", "w+") do |f|
23
25
  f.print <<TXT
24
- a :foox, "http://foox.com"
26
+ #
27
+ # #{Dir.pwd.split('/').last.capitalize} Jsfile
28
+ #
29
+
30
+ js :jquery, "http://jquery.com"
31
+ css :reset, "http://prefered/rset/url"
32
+
33
+ group :forms do
34
+ js :validator, "http://..."
35
+ end
36
+
25
37
  TXT
26
38
  end
27
39
  puts "Jsfile created!"
40
+ exit 0
28
41
  end
29
42
  end
30
43
 
@@ -34,15 +47,16 @@ TXT
34
47
 
35
48
  def read_jsfile
36
49
  file = File.open("Jsfile") # ruby 1.8/1.9 (ugly) fix
37
- file.send(file.respond_to?(:lines) ? :lines : :readlines).map do |line|
50
+ code = file.send(file.respond_to?(:lines) ? :lines : :readlines).map do |line|
38
51
  next if line =~ /^\w*\#|^#/
39
52
  if line =~ /^\w{2,3}path/
40
53
  key, val = line.split(" ")
41
54
  Opt[key.to_sym] = val
42
55
  next
43
56
  end
44
- DSL.instance_eval(line)
57
+ line
45
58
  end.reject(&:nil?)
59
+ DSL.parse code.join(";")
46
60
  end
47
61
 
48
62
  def check_param params, string
@@ -65,10 +79,19 @@ TXT
65
79
  end
66
80
  end
67
81
 
82
+ def bar
83
+ puts "-" * 50
84
+ end
85
+
68
86
  def work!(params)
87
+ start = Time.now
88
+ puts "Assetify"
89
+ bar
69
90
  find_jsfile
70
91
  @assets = read_jsfile
71
92
  work_on params
93
+ bar
94
+ puts "Done in #{Time.now - start}s"
72
95
  end
73
96
 
74
97
 
@@ -1,8 +1,10 @@
1
1
  require 'net/http'
2
+ require 'fileutils'
2
3
 
3
4
  module Assetify
4
5
  class Asset
5
- attr_accessor :type, :name, :url
6
+ include Helpers
7
+ attr_accessor :type, :name, :url, :ns
6
8
 
7
9
  def initialize(type, name, url, ver = nil, params={})
8
10
  raise "NoType" unless type
@@ -11,18 +13,23 @@ module Assetify
11
13
  @type, @name = type, name
12
14
  @ver = ver
13
15
  @url = @ver ? url.gsub(/{VERSION}/, @ver) : url
14
- @new_name = params[:name]
15
- @version = params[:version]
16
+ @ns = params[:ns] || ""
17
+ @pkg = params[:pkg]
16
18
  end
17
19
 
18
20
  def filename
19
- fname = Opt[:newname] ? name : url.split("/").last
20
- fname += ".#{type}" unless fname =~ /\.#{type}$/
21
+ return @filename if @filename
22
+ @filename = Opt[:newname] ? name : url.split("/").last
23
+ @filename += ".#{type}" unless @filename =~ /\.#{type}$/
24
+ @filename
25
+ end
26
+
27
+ def path
28
+ @path = File.join(Opt["#{type}path".to_sym], @ns ? @ns.to_s : "")
21
29
  end
22
30
 
23
31
  def fullpath
24
- path = Opt["#{type}path".to_sym]
25
- File.join(path, filename) #Dir.pwd,
32
+ @fullpath ||= File.join(path, filename)
26
33
  end
27
34
 
28
35
  def check?
@@ -30,21 +37,15 @@ module Assetify
30
37
  end
31
38
 
32
39
  def install!(force = false)
33
- print "Installing #{name}..."
34
- return puts "Installed" if !force && check?
35
- unless @data
36
- uri = URI.parse url
37
- Net::HTTP.start(uri.host) do |http|
38
- @data = http.get(uri.path)
39
- end
40
- end
41
- #puts "Writing to #{fullpath}"
42
- File.open(fullpath, "w") { |f| f.puts(@data) }
43
- puts "DONE"
40
+ print "-> #{name}"
41
+ # points = Thread.new { loop do; print "."; sleep 1; end }
42
+ return print_result "Installed" if !force && check?
43
+ @data ||= @pkg ? @pkg.get(url) : download
44
+ write
45
+ print_result :ok
44
46
  end
45
47
 
46
- end
47
-
48
48
 
49
+ end
49
50
 
50
51
  end
data/lib/assetify/dsl.rb CHANGED
@@ -1,22 +1,36 @@
1
1
  module Assetify
2
2
 
3
-
4
3
  class DSL
5
4
 
5
+ def pkg name, url, &block
6
+ @pkg = Pkg.new name, url
7
+ instance_exec(&block)
8
+ @pkg = nil
9
+ end
10
+
11
+ def group name, &block
12
+ @ns = name
13
+ instance_exec(&block)
14
+ @ns = nil
15
+ assets
16
+ end
17
+
18
+ def assets
19
+ @assets
20
+ end
21
+
22
+ def method_missing method, name, uri, ver=nil, params={}
23
+ (@assets ||= []) << Asset.new(method.to_sym, name, uri, ver, params.merge({ :ns => @ns, :pkg => @pkg}))
24
+ end
25
+
6
26
  class << self
7
- def group name, &block
8
- ns = name
9
- def st.method_missing method, name, url
10
- Asset.new method.to_sym, ns + name, url
11
- end
12
- st.instance_exec(&block)
13
- end
14
27
 
15
- def method_missing(method, name, url, ver=nil, params={})
16
- Asset.new method.to_sym, name, url, ver
28
+ def parse io
29
+ new.instance_eval(io) #.assets
17
30
  end
31
+
18
32
  end
19
- end
20
33
 
34
+ end
21
35
 
22
36
  end
@@ -0,0 +1,24 @@
1
+ module Assetify
2
+ module Helpers
3
+
4
+ private
5
+
6
+ def print_result(txt, varchars = name)
7
+ puts "[#{txt}]".rjust (47 - varchars.size)
8
+ end
9
+
10
+ def download
11
+ uri = URI.parse url
12
+ Net::HTTP.start(uri.host) do |http|
13
+ @data = http.get(uri.path)
14
+ end
15
+ end
16
+
17
+ def write
18
+ FileUtils.mkdir_p path unless Dir.exists? path
19
+ File.open(fullpath, "w") { |f| f.puts(@data) }
20
+ end
21
+
22
+
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ require 'libarchive'
2
+
3
+ module Assetify
4
+
5
+ class Pkg
6
+ include Helpers
7
+ attr_accessor :name, :url
8
+
9
+ PATH = "/tmp/"
10
+
11
+ def initialize(name, url)
12
+ @name = name
13
+ @pkgname = url.split("/").last
14
+ @url = URI.parse(url)
15
+ end
16
+
17
+ def path
18
+ File.join(PATH, name)
19
+ end
20
+
21
+ def fullpath
22
+ File.join(path, @pkgname)
23
+ end
24
+
25
+ def get(file)
26
+ data = nil
27
+ Archive.read_open_filename(fullpath) do |ar|
28
+ while entry = ar.next_header
29
+ if entry.pathname =~ /#{file}/
30
+ data = ar.read_data
31
+ return data
32
+ end
33
+ end
34
+ end
35
+ data
36
+ end
37
+
38
+ def ensure
39
+ download unless File.exists? File.join(PATH, @pkgname)
40
+ unpack
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Asset do
4
+
5
+ it "should spawn!" do
6
+ as = Asset.new :js, "cool", "http://cool.js"
7
+ as.should be_instance_of Asset
8
+ end
9
+
10
+ describe "Instantiated" do
11
+
12
+ let (:as) { Asset.new :js, "sweet", "http://candy.js" }
13
+
14
+ it "should have filename" do
15
+ as.filename.should eql("sweet.js")
16
+ end
17
+
18
+ it "should have fullpath" do
19
+ as.fullpath.should eql("public/javascripts/sweet.js")
20
+ end
21
+
22
+ end
23
+
24
+
25
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DSL do
4
+
5
+ it "should group and use a namespace" do
6
+ a = Assetify::DSL.parse("js 'foo', 'foolink'")[0]
7
+ a.should be_an Asset
8
+ a.fullpath.should eql("public/javascripts/foo.js")
9
+ end
10
+
11
+
12
+ describe "Group Assets" do
13
+
14
+ it "should group and use a namespace" do
15
+ a = Assetify::DSL.parse "group 'common' do; js 'foo', 'foolink'; end"
16
+ a[0].should be_an Asset
17
+ a[0].fullpath.should eql("public/javascripts/common/foo.js")
18
+ end
19
+
20
+ it "should group and use a namespace 2" do
21
+ a = Assetify::DSL.parse "group 'common' do; js 'foo', 'foolink'; js 'rock', 'rocklink'; end"
22
+ a[0].should be_an Asset
23
+ a[0].fullpath.should eql("public/javascripts/common/foo.js")
24
+ end
25
+
26
+ it "should go back to root" do
27
+ a = Assetify::DSL.parse "group 'common' do; js 'foo', 'foolink'; end; js 'rock', 'rocklink'"
28
+ a[1].should be_an Asset
29
+ a[1].fullpath.should eql("public/javascripts/rock.js")
30
+ end
31
+
32
+ end
33
+
34
+ describe "Pkg Assets" do
35
+
36
+ it "should group and use a namespace" do
37
+ a = Assetify::DSL.parse "pkg 'fancy', 'http://fancy.zip' do; js 'foo', 'foolink'; end"
38
+ a[0].should be_an Asset
39
+ a[0].fullpath.should eql("public/javascripts/common/foo.js")
40
+ end
41
+
42
+ end
43
+
44
+
45
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Pkg do
4
+
5
+ it "should spawn!" do
6
+ as = Pkg.new "cool", "http://cool.js"
7
+ as.should be_instance_of Pkg
8
+ end
9
+
10
+ it "should spawn!" do
11
+ as = Pkg.new "cool", "http://cool.js"
12
+ as.should be_instance_of Pkg
13
+ end
14
+
15
+ it "should get file from unpack" do
16
+ `mkdir /tmp/fancy` unless Dir.exists? "/tmp/fancy"
17
+ `cp spec/fixtures/fancy.tgz /tmp/fancy`
18
+ as = Pkg.new "fancy", "http://fancy.tgz"
19
+ as.get("fancy/fancy.css").should eql("// Fancy css!\n\n#foo {\n padding: 10px;\n}\n")
20
+
21
+ end
22
+
23
+ end
@@ -1,11 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Assetify do
4
- include Assetify
5
-
6
- def mock_jsfile(d = 'js "cool", "http://cool.js/down"')
7
- File.should_receive(:open).once.with("Jsfile").and_return(d)
8
- end
9
4
 
10
5
  it "shoud read_jsfile" do
11
6
  mock_jsfile
@@ -14,7 +9,7 @@ describe Assetify do
14
9
 
15
10
  it "should skip comments" do
16
11
  mock_jsfile("#\n# Oi\n#\n")
17
- Assetify.read_jsfile.should be_empty
12
+ Assetify.read_jsfile.should be_nil
18
13
  end
19
14
 
20
15
  it "should work with versions url" do
Binary file
data/spec/spec_helper.rb CHANGED
@@ -2,11 +2,15 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'assetify'
5
+ include Assetify
6
+ def mock_jsfile(d = 'js "cool", "http://cool.js/down"')
7
+ File.should_receive(:open).once.with("Jsfile").and_return(d)
8
+ end
5
9
 
6
10
  # Requires supporting files with custom matchers and macros, etc,
7
11
  # in ./support/ and its subdirectories.
8
12
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
13
 
10
14
  RSpec.configure do |config|
11
-
15
+
12
16
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marcos Piccinini
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-12 00:00:00 -03:00
17
+ date: 2011-05-15 00:00:00 -03:00
18
18
  default_executable: assetify
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -83,7 +83,13 @@ files:
83
83
  - lib/assetify.rb
84
84
  - lib/assetify/asset.rb
85
85
  - lib/assetify/dsl.rb
86
+ - lib/assetify/helpers.rb
87
+ - lib/assetify/pkg.rb
88
+ - spec/assetify/asset_spec.rb
89
+ - spec/assetify/dsl_spec.rb
90
+ - spec/assetify/pkg_spec.rb
86
91
  - spec/assetify_spec.rb
92
+ - spec/fixtures/fancy.tgz
87
93
  - spec/spec_helper.rb
88
94
  has_rdoc: true
89
95
  homepage: http://github.com/nofxx/assetify
@@ -99,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
105
  requirements:
100
106
  - - ">="
101
107
  - !ruby/object:Gem::Version
102
- hash: 2822937878022070943
108
+ hash: -4081184387591617148
103
109
  segments:
104
110
  - 0
105
111
  version: "0"