is_gd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 2008-10-07
2
+
3
+ * 0.1.0 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,27 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README
5
+ README.rdoc
6
+ README.txt
7
+ Rakefile
8
+ config/hoe.rb
9
+ config/requirements.rb
10
+ lib/is_gd.rb
11
+ lib/is_gd/version.rb
12
+ script/console
13
+ script/destroy
14
+ script/generate
15
+ script/txt2html
16
+ setup.rb
17
+ tasks/deployment.rake
18
+ tasks/environment.rake
19
+ tasks/website.rake
20
+ test/fixtures.yaml
21
+ test/test_helper.rb
22
+ test/test_is_gd.rb
23
+ website/index.html
24
+ website/index.txt
25
+ website/javascripts/rounded_corners_lite.inc.js
26
+ website/stylesheets/screen.css
27
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,3 @@
1
+
2
+ For more information on is_gd, see http://is-gd.rubyforge.org
3
+
data/README ADDED
@@ -0,0 +1,36 @@
1
+ =is_gd library
2
+
3
+ # is_gd is a library to minify URLs using "http://is.gd":http://is.gd service, so you'll (obviously) need a network connection.
4
+ # More info here on the API itself: "http://is.gd/api_info.php":http://is.gd/api_info.php
5
+
6
+ This is such a simple library, it doesn't need much explanation at all. There are two modes:
7
+ #You give it a URL, and it will give you back a URL minified with "http://is.gd":http://is.gd
8
+ IsGd.minify('www.google.com') (returns: 'http://is.gd/2')
9
+ #You give it an is.gd minified URL and it will tell you the source URL.
10
+ IsGd.un_minify('http://is.gd/2') (returns: 'http://www.google.com')
11
+
12
+
13
+ LICENSE:
14
+
15
+ (The MIT License)
16
+
17
+ Copyright (c) 2008 JT Zemp and Thrive Information Solutions
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining
20
+ a copy of this software and associated documentation files (the
21
+ 'Software'), to deal in the Software without restriction, including
22
+ without limitation the rights to use, copy, modify, merge, publish,
23
+ distribute, sublicense, and/or sell copies of the Software, and to
24
+ permit persons to whom the Software is furnished to do so, subject to
25
+ the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be
28
+ included in all copies or substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
31
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
34
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
35
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
36
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,41 @@
1
+ = is_gd
2
+
3
+ # is_gd is a library to minify URLs using "http://is.gd":http://is.gd service, so you'll (obviously) need a network connection.
4
+ # More info here on the API itself: "http://is.gd/api_info.php":http://is.gd/api_info.php
5
+
6
+ == DESCRIPTION:
7
+
8
+ This is such a simple library, it doesn't need much explanation at all. There are two modes:
9
+ #You give it a URL, and it will give you back a URL minified with "http://is.gd":http://is.gd
10
+ IsGd.minify('www.google.com') (returns: 'http://is.gd/2')
11
+ #You give it an is.gd minified URL and it will tell you the source URL.
12
+ IsGd.un_minify('http://is.gd/2') (returns: 'http://www.google.com')
13
+
14
+ == INSTALL:
15
+
16
+ sudo gem install is_gd
17
+
18
+ == LICENSE:
19
+
20
+ (The MIT License)
21
+
22
+ Copyright (c) 2008 JT Zemp and Thrive Information Solutions
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining
25
+ a copy of this software and associated documentation files (the
26
+ 'Software'), to deal in the Software without restriction, including
27
+ without limitation the rights to use, copy, modify, merge, publish,
28
+ distribute, sublicense, and/or sell copies of the Software, and to
29
+ permit persons to whom the Software is furnished to do so, subject to
30
+ the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be
33
+ included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
36
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
39
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
40
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.txt ADDED
@@ -0,0 +1,41 @@
1
+ = is_gd
2
+
3
+ # is_gd is a library to minify URLs using "http://is.gd":http://is.gd service, so you'll (obviously) need a network connection.
4
+ # More info here on the API itself: "http://is.gd/api_info.php":http://is.gd/api_info.php
5
+
6
+ == DESCRIPTION:
7
+
8
+ This is such a simple library, it doesn't need much explanation at all. There are two modes:
9
+ #You give it a URL, and it will give you back a URL minified with "http://is.gd":http://is.gd
10
+ IsGd.minify('www.google.com') (returns: 'http://is.gd/2')
11
+ #You give it an is.gd minified URL and it will tell you the source URL.
12
+ IsGd.un_minify('http://is.gd/2') (returns: 'http://www.google.com')
13
+
14
+ == INSTALL:
15
+
16
+ sudo gem install is_gd
17
+
18
+ == LICENSE:
19
+
20
+ (The MIT License)
21
+
22
+ Copyright (c) 2008 JT Zemp and Thrive Information Solutions
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining
25
+ a copy of this software and associated documentation files (the
26
+ 'Software'), to deal in the Software without restriction, including
27
+ without limitation the rights to use, copy, modify, merge, publish,
28
+ distribute, sublicense, and/or sell copies of the Software, and to
29
+ permit persons to whom the Software is furnished to do so, subject to
30
+ the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be
33
+ included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
36
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
39
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
40
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'is_gd/version'
2
+
3
+ AUTHOR = 'JT Zemp' # can also be an array of Authors
4
+ EMAIL = "jt.zemp@thriveis.com"
5
+ DESCRIPTION = "A lightweight ruby wrapper around the is.gd service. It will minify and expand urls."
6
+ GEM_NAME = 'is_gd' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'is-gd' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['open-uri', '>=0.0.0']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "jtzemp"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = IsGd::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'is_gd documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
data/lib/is_gd.rb ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require 'rubygems'
4
+ require 'open-uri'
5
+ require 'net/http'
6
+
7
+ # is_gd is a library to minify URLs using http://is.gd service
8
+ # More info here: http://is.gd/api_info.php
9
+ class IsGd
10
+ IS_GD_URL = "http://is.gd/api.php?longurl="
11
+ USER_AGENT = "is_gd ruby library http://is-gd.rubyforge.org"
12
+ attr_reader :original_url, :minified_url
13
+ def initialize(url=nil)
14
+ @original_url = url
15
+ @minified_url = nil
16
+ @un_minified_url = nil
17
+ end
18
+
19
+ # Take a URL and return a minified url
20
+ def minify(url=nil)
21
+ unless @minified_url
22
+ url_to_minify = url || @original_url
23
+ encoded_url_to_minify = self.url_encode(url_to_minify)
24
+ @minified_url = open(IS_GD_URL + encoded_url_to_minify, 'r') { |file| file.read }
25
+ else
26
+ @minified_url
27
+ end
28
+ end
29
+
30
+ # Class method to minify a URL
31
+ def self.minify(url)
32
+ is_gd = self.new(url)
33
+ is_gd.minify
34
+ end
35
+
36
+ # Un-minify by following the redirect. If there is no redirect, then it returns the original URL
37
+ def un_minify(url=nil)
38
+ uri_str = url || @original_url
39
+
40
+ unless @un_minified_url
41
+ url_obj = URI.parse(uri_str)
42
+ Net::HTTP.start(url_obj.host, url_obj.port) do |http|
43
+ response = http.request_head(url_obj.request_uri, {'User-Agent' => USER_AGENT})
44
+
45
+ case response
46
+ when Net::HTTPSuccess then @un_minified_url = uri_str
47
+ when Net::HTTPRedirection then @un_minified_url = response['location']
48
+ end
49
+
50
+ @un_minified_url
51
+ end
52
+
53
+ else
54
+ @un_minified_url
55
+ end
56
+ end
57
+
58
+ def self.un_minify(url)
59
+ is_gd = IsGd.new(url)
60
+ is_gd.un_minify
61
+ end
62
+
63
+ protected
64
+
65
+ # encode a url based on is.gd's very lenient guidelines
66
+ def url_encode(url)
67
+ url.gsub(':','%3B').gsub('#', '%23')
68
+ end
69
+ end
70
+
71
+ # if the file is called directly
72
+ if __FILE__ == $0
73
+ STDERR.puts "Getting smaller url for #{ARGV[0]}."
74
+ puts IsGd.minify(ARGV[0])
75
+ end
@@ -0,0 +1,10 @@
1
+ module IsGd
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ self
9
+ end
10
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/is_gd.rb'}"
9
+ puts "Loading is_gd gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_NAME = 'is_gd' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'is_gd'
5
+
6
+ require 'rubygems'
7
+ begin
8
+ require 'newgem'
9
+ require 'rubyforge'
10
+ rescue LoadError
11
+ puts "\n\nGenerating the website requires the newgem RubyGem"
12
+ puts "Install: gem install newgem\n\n"
13
+ exit(1)
14
+ end
15
+ require 'redcloth'
16
+ require 'syntax/convertors/html'
17
+ require 'erb'
18
+ require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
19
+
20
+ version = IsGd::VERSION::STRING
21
+ download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
+
23
+ def rubyforge_project_id
24
+ RubyForge.new.configure.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
+ end
26
+
27
+ class Fixnum
28
+ def ordinal
29
+ # teens
30
+ return 'th' if (10..19).include?(self % 100)
31
+ # others
32
+ case self % 10
33
+ when 1: return 'st'
34
+ when 2: return 'nd'
35
+ when 3: return 'rd'
36
+ else return 'th'
37
+ end
38
+ end
39
+ end
40
+
41
+ class Time
42
+ def pretty
43
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
44
+ end
45
+ end
46
+
47
+ def convert_syntax(syntax, source)
48
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
49
+ end
50
+
51
+ if ARGV.length >= 1
52
+ src, template = ARGV
53
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
54
+ else
55
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
56
+ exit!
57
+ end
58
+
59
+ template = ERB.new(File.open(template).read)
60
+
61
+ title = nil
62
+ body = nil
63
+ File.open(src) do |fsrc|
64
+ title_text = fsrc.readline
65
+ body_text_template = fsrc.read
66
+ body_text = ERB.new(body_text_template).result(binding)
67
+ syntax_items = []
68
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
69
+ ident = syntax_items.length
70
+ element, syntax, source = $1, $2, $3
71
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
72
+ "syntax-temp-#{ident}"
73
+ }
74
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
75
+ body = RedCloth.new(body_text).to_html
76
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
77
+ end
78
+ stat = File.stat(src)
79
+ created = stat.ctime
80
+ modified = stat.mtime
81
+
82
+ $stdout << template.result(binding)