assetify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", ">= 2.3.0"
10
+ gem "bundler", ">= 1.0.0"
11
+ gem "jeweler", ">= 1.6.0"
12
+ # gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.0)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rspec (2.5.0)
12
+ rspec-core (~> 2.5.0)
13
+ rspec-expectations (~> 2.5.0)
14
+ rspec-mocks (~> 2.5.0)
15
+ rspec-core (2.5.2)
16
+ rspec-expectations (2.5.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.5.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (>= 1.0.0)
25
+ jeweler (>= 1.6.0)
26
+ rspec (>= 2.3.0)
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ Assetify
2
+ ========
3
+
4
+ Downloads/updates assets. Any framework.
5
+
6
+
7
+ Install
8
+ -------
9
+
10
+ gem install assetify
11
+
12
+
13
+ Use
14
+ ---
15
+
16
+ On any project`s root:
17
+
18
+ assetify
19
+
20
+
21
+ This will create a Jsfile if not found.
22
+
23
+
24
+ Jsfile
25
+ ------
26
+
27
+ Just like a Gemfile, but you choose the filetype before:
28
+
29
+ type "name", "url", <version>
30
+
31
+ js "jquery", "http://code.jquery.com/jquery-{VERSION}.min.js", "1.6"
32
+ js "tipsy", "https://github.com/jaz303/tipsy/.../jquery.tipsy.js"
33
+
34
+ Now just run assetify to make sure everything is installed/up-to-date.
35
+
36
+ Options:
37
+
38
+ newname true || false
39
+ jspath "new/path"
40
+ csspath "new/path"
41
+ imgpath "new/path"
42
+
43
+
44
+ If newname is set to true (default) the file will be renamed. Ex:
45
+
46
+ js "validator", "http//.../jquery.validator.min.js"
47
+
48
+ Filename will be: "validator.js"
49
+
50
+
51
+ Contributing
52
+ ------------
53
+
54
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
55
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
56
+ * Fork the project
57
+ * Start a feature/bugfix branch
58
+ * Commit and push until you are happy with your contribution
59
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
60
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
61
+
62
+
63
+ Copyright
64
+ ---------
65
+
66
+ Copyright (c) 2011 Marcos Piccinini. See LICENSE.txt for
67
+ further details.
68
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "assetify"
18
+ gem.homepage = "http://github.com/nofxx/assetify"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Downloads/updates assets. Any framework.}
21
+ gem.description = %Q{Downloads/updates assets based on a Jsfile. Any framework.}
22
+ gem.email = "x@nofxx.com"
23
+ gem.authors = ["Marcos Piccinini"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "assetify #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/assetify.gemspec ADDED
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{assetify}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Marcos Piccinini"]
12
+ s.date = %q{2011-05-12}
13
+ s.default_executable = %q{assetify}
14
+ s.description = %q{TODO: longer description of your gem}
15
+ s.email = %q{x@nofxx.com}
16
+ s.executables = ["assetify"]
17
+ s.extra_rdoc_files = [
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "README.md",
26
+ "Rakefile",
27
+ "bin/assetify",
28
+ "lib/assetify.rb",
29
+ "lib/assetify/asset.rb",
30
+ "lib/assetify/dsl.rb",
31
+ "spec/assetify_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/nofxx/assetify}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{TODO: one-line summary of your gem}
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
46
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, [">= 1.6.0"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 2.3.0"])
50
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, [">= 1.6.0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 2.3.0"])
55
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, [">= 1.6.0"])
57
+ end
58
+ end
59
+
data/bin/assetify ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ #require 'rubygems'
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'optparse'
5
+ require 'assetify'
6
+
7
+ opt = OptionParser.new do |o|
8
+ o.banner = <<BANNER
9
+ Bugs Bunny - RabbitMQ Playground
10
+
11
+ Usage: #{File.basename($0)} command [args]
12
+
13
+ Commands:
14
+
15
+ install - All assets
16
+ update - Outdated assets
17
+ check - Prints changes
18
+
19
+ Options:
20
+
21
+ BANNER
22
+
23
+
24
+ o.on('-h', "Show help") { puts o; exit }
25
+ o.parse!
26
+ end
27
+
28
+
29
+ begin
30
+ Assetify.work!(ARGV)
31
+ rescue Interrupt => e
32
+ puts "\nQuitting..."
33
+ puts e.backtrace.join("\n")
34
+ exit 1
35
+ end
36
+
37
+
data/lib/assetify.rb ADDED
@@ -0,0 +1,76 @@
1
+ require "assetify/asset"
2
+ require "assetify/dsl"
3
+
4
+ module Assetify
5
+
6
+ class NoJSFile < StandardError
7
+ end
8
+
9
+ Opt = {
10
+ :jspath => "public/javascripts",
11
+ :csspath => "public/stylesheets",
12
+ :imgpath => "public/images",
13
+ :newname => true
14
+ }
15
+
16
+ class << self
17
+
18
+ def no_jsfile!
19
+ print "Jsfile not found, create one? [Y/n] "
20
+ res = gets.chomp
21
+ unless res =~ /n|N/
22
+ File.open("Jsfile", "w+") do |f|
23
+ f.print <<TXT
24
+ a :foox, "http://foox.com"
25
+ TXT
26
+ end
27
+ puts "Jsfile created!"
28
+ end
29
+ end
30
+
31
+ def find_jsfile
32
+ no_jsfile! unless File.exists?("Jsfile")
33
+ end
34
+
35
+ def read_jsfile
36
+ file = File.open("Jsfile") # ruby 1.8/1.9 (ugly) fix
37
+ file.send(file.respond_to?(:lines) ? :lines : :readlines).map do |line|
38
+ next if line =~ /^\w*\#|^#/
39
+ if line =~ /^\w{2,3}path/
40
+ key, val = line.split(" ")
41
+ Opt[key.to_sym] = val
42
+ next
43
+ end
44
+ DSL.instance_eval(line)
45
+ end.reject(&:nil?)
46
+ end
47
+
48
+ def check_param params, string
49
+ unless string.include? params[0]
50
+ puts "Did you mean #{string}?"
51
+ exit 0
52
+ end
53
+ end
54
+
55
+ def work_on params
56
+ case params.first
57
+ when /^i/, nil
58
+ check_param params, "install"
59
+ @assets.map(&:install!)
60
+ when /^u/
61
+ check_param params, "update"
62
+ @assets.map { |a| a.install! :force }
63
+ else
64
+ puts "Dunno how to #{params.join}."
65
+ end
66
+ end
67
+
68
+ def work!(params)
69
+ find_jsfile
70
+ @assets = read_jsfile
71
+ work_on params
72
+ end
73
+
74
+
75
+ end
76
+ end
@@ -0,0 +1,50 @@
1
+ require 'net/http'
2
+
3
+ module Assetify
4
+ class Asset
5
+ attr_accessor :type, :name, :url
6
+
7
+ def initialize(type, name, url, ver = nil, params={})
8
+ raise "NoType" unless type
9
+ raise "NoName" unless name
10
+ raise "NoURL" unless url
11
+ @type, @name = type, name
12
+ @ver = ver
13
+ @url = @ver ? url.gsub(/{VERSION}/, @ver) : url
14
+ @new_name = params[:name]
15
+ @version = params[:version]
16
+ end
17
+
18
+ def filename
19
+ fname = Opt[:newname] ? name : url.split("/").last
20
+ fname += ".#{type}" unless fname =~ /\.#{type}$/
21
+ end
22
+
23
+ def fullpath
24
+ path = Opt["#{type}path".to_sym]
25
+ File.join(path, filename) #Dir.pwd,
26
+ end
27
+
28
+ def check?
29
+ File.exists? fullpath
30
+ end
31
+
32
+ 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"
44
+ end
45
+
46
+ end
47
+
48
+
49
+
50
+ end
@@ -0,0 +1,22 @@
1
+ module Assetify
2
+
3
+
4
+ class DSL
5
+
6
+ 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
+
15
+ def method_missing(method, name, url, ver=nil, params={})
16
+ Asset.new method.to_sym, name, url, ver
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
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
+
10
+ it "shoud read_jsfile" do
11
+ mock_jsfile
12
+ Assetify.read_jsfile.should have(1).asset
13
+ end
14
+
15
+ it "should skip comments" do
16
+ mock_jsfile("#\n# Oi\n#\n")
17
+ Assetify.read_jsfile.should be_empty
18
+ end
19
+
20
+ it "should work with versions url" do
21
+ mock_jsfile("#\n# Oi\n#\njs 'down', 'http://js.com/down-{VERSION}.js', '1.6'")
22
+ Assetify.read_jsfile.first.url.should eql("http://js.com/down-1.6.js")
23
+ end
24
+
25
+ describe "read css" do
26
+ before do
27
+ mock_jsfile("#\n# CSS\n#\ncss 'grid', 'http://grid.com/down'")
28
+ end
29
+ let(:asset) { Assetify.read_jsfile[0] }
30
+
31
+ it "should read css" do
32
+ Assetify.read_jsfile.should have(1).asset
33
+ end
34
+
35
+ it "should read css" do
36
+ Assetify.read_jsfile.first.type.should eql(:css)
37
+ end
38
+
39
+ it "should have fullpath" do
40
+ asset.fullpath.should eql("public/stylesheets/grid.css")
41
+ end
42
+
43
+ end
44
+
45
+ describe "readjs" do
46
+
47
+ let(:asset) { mock_jsfile; Assetify.read_jsfile[0] }
48
+
49
+ it "should be an asset" do
50
+ asset.should be_an Assetify::Asset
51
+ end
52
+
53
+ it "should be a js file" do
54
+ asset.type.should eql(:js)
55
+ end
56
+
57
+ it "should have an url" do
58
+ asset.url.should eql("http://cool.js/down")
59
+ end
60
+
61
+ it "should have a name" do
62
+ asset.name.should eql("cool")
63
+ end
64
+
65
+ it "should have fullpath" do
66
+ asset.fullpath.should eql("public/javascripts/cool.js")
67
+ end
68
+
69
+
70
+ end
71
+
72
+
73
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'assetify'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assetify
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Marcos Piccinini
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-12 00:00:00 -03:00
18
+ default_executable: assetify
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 0
31
+ version: 2.3.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 6
60
+ - 0
61
+ version: 1.6.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ description: Downloads/updates assets based on a Jsfile. Any framework.
66
+ email: x@nofxx.com
67
+ executables:
68
+ - assetify
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - README.md
73
+ files:
74
+ - .document
75
+ - .rspec
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.md
79
+ - Rakefile
80
+ - VERSION
81
+ - assetify.gemspec
82
+ - bin/assetify
83
+ - lib/assetify.rb
84
+ - lib/assetify/asset.rb
85
+ - lib/assetify/dsl.rb
86
+ - spec/assetify_spec.rb
87
+ - spec/spec_helper.rb
88
+ has_rdoc: true
89
+ homepage: http://github.com/nofxx/assetify
90
+ licenses:
91
+ - MIT
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: -2235412938694436506
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project:
117
+ rubygems_version: 1.3.7
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Downloads/updates assets. Any framework.
121
+ test_files: []
122
+