revans-gini 0.2.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.
data/ChangeLog.rdoc ADDED
@@ -0,0 +1,16 @@
1
+
2
+ Version 0.1.4
3
+
4
+ * Added Mootools
5
+ * Added Prototype
6
+ * Added more documentation
7
+
8
+ Version 0.1.2
9
+
10
+ * Fixed fetch bugs
11
+ * Changed some classnames so the read better
12
+
13
+ Version 0.1.0
14
+
15
+ * Initial Creation
16
+ * jQuery is the only library currently supported
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Code Wranglers, Inc. & Robert R Evans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,49 @@
1
+ # Gini
2
+
3
+ Gini is a way to grab those files that you are tired of copying and pasting everytime, like the
4
+ latest jQuery or Prototype. You tell gini what library you want, that is supported, and where you
5
+ want it installed, unless you want it in the current directory and it will go get it for you.
6
+
7
+ Additional options is downloading a compressed version, if it exists.
8
+
9
+ ## Libraries Currently Supported
10
+
11
+ * jQuery
12
+ * Prototype
13
+ * MooTools
14
+ * 960 CSS Framework
15
+
16
+ ## Usage
17
+
18
+ To choose the directory you want the library installed at (it will create any files that don't already exist)
19
+
20
+ gini --install jquery --path /Users/yourname/project/public/javascripts
21
+
22
+ To install in your current directory:
23
+
24
+ gini --install prototype
25
+
26
+ Ask for a compressed version of the library, if it exists
27
+
28
+ gini --install jquery -c
29
+
30
+ Need some help?
31
+
32
+ gini -h
33
+
34
+ That will show you all available options.
35
+
36
+ ## Install
37
+
38
+ git clone git://github.com/revans/gini.git
39
+ cd gini
40
+ gem build gini.gemspec
41
+ sudo gem install gini-0.2.0.gem
42
+
43
+
44
+ ## Future Features
45
+
46
+ * More Libraries
47
+ * Hooks for using Github to grab libraries
48
+ * Ability to download zip/tar files and unpack them
49
+ * Possible support for your own libraries that live on your local machine in, say, a ~/.templates folder
data/Rakefile ADDED
File without changes
data/bin/gini ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'gini'
5
+
6
+ options = Gini::Options.parse(ARGV)
7
+ Gini::Fetch.library(options)
data/lib/gini.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Gini
2
+ Version = "0.2.0"
3
+
4
+ class LibraryNotSupported < StandardError; end
5
+ class LibraryNotSpecified < StandardError; end
6
+
7
+ module Supported
8
+ Archives = %w[tar tar.gz tar.bz2 zip]
9
+ end
10
+ end
11
+
12
+ # Required Gems
13
+ %w[fileutils optparse ostruct uri net/http pathname].each { |library| require library }
14
+
15
+ # Gem specific Requires
16
+ require File.dirname(__FILE__) + "/gini/extensions/string"
17
+ require File.dirname(__FILE__) + "/gini/library"
18
+ require File.dirname(__FILE__) + "/gini/parser"
19
+ require File.dirname(__FILE__) + "/gini/extract"
20
+ require File.dirname(__FILE__) + "/gini/fetch"
@@ -0,0 +1,18 @@
1
+ class String
2
+
3
+ # change a pharse ('test it now') or ("test_it_now") to a classname ('TestItNow')
4
+ def classify
5
+ clean.split(' ').each { |word| word.capitalize! }.join('')
6
+ end
7
+
8
+ # change a phrase ('testing now') to an instance variable name ('testing_now')
9
+ def instantify
10
+ clean.gsub(/\s+/, '_').downcase
11
+ end
12
+
13
+ # clean a string of unwanted characters before we turn into a class or variable name
14
+ def clean
15
+ gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join(' ')
16
+ end
17
+
18
+ end
@@ -0,0 +1,41 @@
1
+ module Gini
2
+ class Extract
3
+
4
+ def self.file(path, ext, library_name)
5
+ f = new
6
+ command = f.uncompress_with(ext)
7
+ path_to_file = f.search_for_file(path, library_name)
8
+
9
+ system("#{command} #{path_to_file}")
10
+ end
11
+
12
+
13
+ def uncompress_with(extension)
14
+ case extension
15
+ when "tar" then "tar xvf"
16
+ when "tar.gz" then "tar xzvf"
17
+ when "tar.bz2" then "tar xvjf"
18
+ when "zip" then "unzip"
19
+ else
20
+ raise Exception, "I don't know that extension" and exit(0)
21
+ end
22
+ end
23
+
24
+
25
+ def search_for_file(path, lib)
26
+ path = Pathname.new(path)
27
+ path.children.each do |p|
28
+ @archive_path = p.to_s if p.to_s =~ /#{lib}/
29
+ end
30
+ @archive_path
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ # API
37
+ #
38
+ # Takes the location of archived file and determines what type of un-archiving method should be used and does so.
39
+ # That is all this class should do!
40
+ #
41
+ # Gini::Extract.file(archived_file)
data/lib/gini/fetch.rb ADDED
@@ -0,0 +1,208 @@
1
+ module Gini
2
+ class Fetch
3
+
4
+ attr_reader :options, :url
5
+
6
+
7
+ # Initialize
8
+ #
9
+ # ==== Description
10
+ #
11
+ # Checks to make sure a library is specified and we support it.
12
+ # Maps options and setups up the path, if it is not given.
13
+ #
14
+ def initialize(options)
15
+ raise LibraryNotSpecified, "You need to specify what Library you want to install" if options.library.nil?
16
+ raise LibraryNotSupported, "#{options.library} is not supported." unless Gini::Libraries.include?(options.library)
17
+
18
+ @options = options
19
+ check_library_name
20
+ @options.path = @options.path.nil? ? Dir.pwd : @options.path
21
+ @options.extension = Gini::Library.const_get(@options.library.capitalize).const_get("Extension")
22
+ @options.installation_path = File.join(@options.path, "#{@options.library.downcase}.#{@options.extension}")
23
+ end
24
+
25
+
26
+ # Gini::Fetch.library(options)
27
+ #
28
+ # ==== Description
29
+ #
30
+ # A Class method for installing a library
31
+ #
32
+ # ==== Returns
33
+ #
34
+ # Returns our exit message to let the user
35
+ # know what took place and where they can find the library
36
+ # on their system.
37
+ #
38
+ def self.library(options)
39
+ init = new(options)
40
+ init.install
41
+ # init.need_extraction
42
+ init.send_exit_message
43
+ end
44
+
45
+
46
+ # Install
47
+ #
48
+ # ==== Description
49
+ #
50
+ # Checks for a compressed version and if the user specified a compressed version
51
+ # Pulls the cooresponding Repo and downloads it and writes it to a file in the
52
+ # specified path, given by the user
53
+ #
54
+ def install
55
+ check_directory
56
+ check_compression
57
+ # archived? ? grab_archive : grab_single_file
58
+ grab_archive
59
+ end
60
+
61
+
62
+ # Grab a Single File
63
+ #
64
+ # ==== Description
65
+ #
66
+ # If it is a single, file, we'll use the traditional Ruby way
67
+ # of grabbing a file.
68
+ #
69
+ def grab_single_file
70
+ File.open(@options.installation_path, "w+") do |f|
71
+ f.write( Net::HTTP.get( URI.parse(@url) ) )
72
+ end
73
+ end
74
+
75
+
76
+ # Grab an Archived File
77
+ #
78
+ # ==== Description
79
+ #
80
+ # This uses a system call, curl, to grab an archive off of a server.
81
+ # It will then un-archive it (zip, tar, tar.gz, tar.bz2)
82
+ #
83
+ def grab_archive
84
+ FileUtils.cd @options.path
85
+ system("curl -L -O #{@url}")
86
+ extract_archive
87
+ end
88
+
89
+
90
+ # Check Directory
91
+ #
92
+ # ==== Description
93
+ #
94
+ # Check to see if a directory exists, if it does not
95
+ # then create it.
96
+ #
97
+ def check_directory
98
+ unless File.exists?(@options.path)
99
+ FileUtils.mkdir_p(@options.path)
100
+ end
101
+ end
102
+
103
+
104
+ # Check Compression
105
+ #
106
+ # ==== Description
107
+ #
108
+ # Checks to see if the user specified a compressed version and then sees if
109
+ # a compressed version is available. The url instance variable is instanstiated
110
+ # accordingly.
111
+ #
112
+ # ==== Returns
113
+ #
114
+ # Returns the @url instance variable with the cooresponding url for the
115
+ # specified library repo.
116
+ #
117
+ def check_compression
118
+ if compression_is_used?
119
+ @url = Gini::Library.const_get(@options.library.capitalize).const_get("Compressed")
120
+ else
121
+ @url = Gini::Library.const_get(@options.library.capitalize).const_get("Repo")
122
+ end
123
+ end
124
+
125
+
126
+ # Extract the Archived File
127
+ #
128
+ # ==== Description
129
+ #
130
+ # Extracts the archived file into the current directory
131
+ # that it was downloaded into.
132
+ #
133
+ def extract_archive
134
+ name = Gini::Library.const_get(@options.library.capitalize).const_get("Name")
135
+ Gini::Extract.file(@options.path, @options.extension, name)
136
+ end
137
+
138
+
139
+ # Archived?
140
+ #
141
+ # ==== Description
142
+ #
143
+ # Is this an archived file?
144
+ #
145
+ # ==== Returns
146
+ #
147
+ # Returns a boolean value
148
+ #
149
+ def archived?
150
+ Gini::Supported::Archives.include?(@options.extension)
151
+ end
152
+
153
+
154
+ # Library Compression
155
+ #
156
+ # ==== Description
157
+ #
158
+ # Checks to see if we can offer a compressed version of the Library specified.
159
+ #
160
+ # ==== Returns
161
+ #
162
+ # A Boolean value
163
+ #
164
+ def library_compression?
165
+ !!Gini::Library.const_get(@options.library.capitalize).const_get("Compressed")
166
+ end
167
+
168
+
169
+ # Compression is Used?
170
+ #
171
+ # ==== Description
172
+ #
173
+ # Boolean method to check if the user has specified compression and the library
174
+ # has a compressed version of the library.
175
+ #
176
+ # ==== Return
177
+ #
178
+ # Returns a boolean response
179
+ #
180
+ def compression_is_used?
181
+ library_compression? && @options.compress
182
+ end
183
+
184
+
185
+ # Exit Message to let the User know what took place
186
+ #
187
+ def send_exit_message
188
+ puts "\n#{@options.library.capitalize} was installed at #{@options.installation_path} and compression was #{translate_to_words}.\n\n"
189
+ end
190
+
191
+
192
+ # Translate to Words
193
+ #
194
+ def translate_to_words
195
+ compression_is_used? ? "used" : "was not used"
196
+ end
197
+
198
+
199
+ def check_library_name
200
+ case @options.library
201
+ when "960"
202
+ @options.library = "grid960"
203
+ else
204
+ end
205
+ end
206
+
207
+ end
208
+ end
@@ -0,0 +1,60 @@
1
+ module Gini
2
+
3
+ # Supported Libraries
4
+ Libraries = %w[jquery prototype mootools 960]
5
+
6
+ module Library
7
+
8
+ # jQuery Repository Information
9
+ module Jquery
10
+ URL = "http://jqueryjs.googlecode.com/files"
11
+ Version = "1.2.6"
12
+ Repo = "#{URL}/jquery-#{Version}.js"
13
+ Compressed = "#{URL}/jquery-#{Version}.min.js"
14
+ Extension = "js" # TODO: crappy hack
15
+ end
16
+
17
+
18
+ # Prototype Repository Information
19
+ module Prototype
20
+ URL = "http://www.prototypejs.org/assets"
21
+ Version = "1.6.0.3"
22
+ Repo = "#{URL}/2008/9/29/prototype-#{Version}.js"
23
+ Compressed = nil
24
+ Extension = "js"
25
+ end
26
+
27
+
28
+ # MooTools Repository Information
29
+ module Mootools
30
+ URL = "http://mootools.net/download/get"
31
+ Version = "1.2.1"
32
+ Repo = "#{URL}/mootools-#{Version}-core-nc.js"
33
+ Compressed = "#{URL}/mootools-#{Version}-core-yc.js"
34
+ Extension = "js"
35
+ end
36
+
37
+
38
+ # 960 Grid CSS Framework
39
+ module Grid960
40
+ URL = "http://960.gs/files/960_download.zip"
41
+ Name = "960"
42
+ Version = nil
43
+ Repo = "#{URL}"
44
+ Compressed = nil
45
+ Extension = "zip"
46
+ end
47
+
48
+
49
+ # Blueprint CSS Framework
50
+ # module Blueprint
51
+ # URL = "http://github.com/joshuaclayton/blueprint-css/tarball/master"
52
+ # Name = "blueprint"
53
+ # Version = "0.8"
54
+ # Repo = "#{URL}"
55
+ # Compressed = nil
56
+ # Extension = "tar.gz"
57
+ # end
58
+
59
+ end
60
+ end
@@ -0,0 +1,72 @@
1
+ module Gini
2
+ class Options
3
+
4
+ def self.parse(args)
5
+ options = OpenStruct.new
6
+
7
+ # Parse Options
8
+ opts = OptionParser.new do |opts|
9
+ opts.banner = "\nGini Usage: gini --install jquery --path /Users/rrevans/Desktop -f"
10
+ opts.separator ""
11
+ opts.separator "Required Options"
12
+
13
+
14
+ # Install a specific library
15
+ opts.on("--install NAME", "Install a Library. Use gini -l to see available libraries.") do |ext|
16
+ raise Gini::LibraryNotSupported, "#{ext} is not a supported Library" and exit(0) unless Gini::Libraries.include?(ext)
17
+ options.library = ext
18
+ end
19
+
20
+
21
+ # Specify the location to install the library
22
+ opts.on("--path NAME", "Specify the path to install the library.") do |ext|
23
+ options.path = ext
24
+ end
25
+
26
+
27
+ # Show available libraries that Gini supports to install
28
+ opts.on("-l", "--libraries", "Show available libraries to install. Use the names listed as the name to be passed in to install.\n\t\t\t\t e.g. gini --install 960") do |lib|
29
+ puts "\nAvailable Libraries:\n\n"
30
+ Gini::Libraries.each { |lib| puts "#{lib}\n" }
31
+ puts "\n"
32
+ exit(0)
33
+ end
34
+
35
+
36
+ # Boolean Switch to force overwrite
37
+ # opts.on("-f", "--force", "Force an Overwrite of a current file") do |ext|
38
+ # options.force = ext
39
+ # end
40
+
41
+
42
+ # Boolean Switch to compression, if supported
43
+ opts.on("-c", "--compress", "Pull a compressed version, if available") do |ext|
44
+ options.compress = ext
45
+ end
46
+
47
+
48
+ # Simple Separator
49
+ opts.separator ""
50
+ opts.separator "Common Options"
51
+
52
+
53
+ # Help Screen
54
+ opts.on_tail("-h", "--help", "Show the help screen") do
55
+ puts opts
56
+ exit(0)
57
+ end
58
+
59
+
60
+ # Show Version
61
+ opts.on_tail("-v", "--version", "Show Gini's current version") do
62
+ puts "Gini is currently at Version #{Gini::Version}"
63
+ exit(0)
64
+ end
65
+ end
66
+
67
+ opts.parse!(args)
68
+ options
69
+ end
70
+
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: revans-gini
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert R Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-18 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A basic code generator for various existing libraries
17
+ email: revans@robertrevans.com
18
+ executables:
19
+ - gini
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ - ChangeLog.rdoc
25
+ - LICENSE
26
+ files:
27
+ - README.markdown
28
+ - LICENSE
29
+ - ChangeLog.rdoc
30
+ - Rakefile
31
+ - bin/gini
32
+ - lib/gini.rb
33
+ - lib/gini/extensions/string.rb
34
+ - lib/gini/parser.rb
35
+ - lib/gini/library.rb
36
+ - lib/gini/fetch.rb
37
+ - lib/gini/extract.rb
38
+ has_rdoc: true
39
+ homepage: http://www.robertrevans.com
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: gini
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: A basic code generator for various existing libraries
64
+ test_files: []
65
+