js2bookmarklet 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +47 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/bin/js2bookmarklet +41 -0
- data/js2bookmarklet.gemspec +51 -0
- data/lib/js2bookmarklet.rb +50 -0
- data/test/fixtures/script.js +3 -0
- data/test/test_js2bookmarklet.rb +23 -0
- metadata +71 -0
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= js2bookmarklet
|
2
|
+
|
3
|
+
http://github.com/smith/js2bookmarklet
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Utility to create a bookmarklet from a JavaScript file
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
js2bookmarklet [options] [input file]
|
12
|
+
-o, --output [file name] Output file
|
13
|
+
-a, --link-text [text] Link text
|
14
|
+
-t, --link-title [title] Link title
|
15
|
+
|
16
|
+
== REQUIREMENTS:
|
17
|
+
|
18
|
+
* jsmin gem
|
19
|
+
|
20
|
+
== INSTALL:
|
21
|
+
|
22
|
+
gem install smith-js2bookmarklet (make sure GitHub is included in your sources with gem sources -a http://gems.github.com)
|
23
|
+
|
24
|
+
== LICENSE:
|
25
|
+
|
26
|
+
(The MIT License)
|
27
|
+
|
28
|
+
Copyright (c) 2009 Nathan L Smith
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
'Software'), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
44
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
45
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
46
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
47
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rake/testtask"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gemspec|
|
6
|
+
gemspec.name = "js2bookmarklet"
|
7
|
+
gemspec.description = "Utility to create a bookmarklet from a JavaScript file"
|
8
|
+
gemspec.summary = ""
|
9
|
+
gemspec.email = "nlloyds@gmail.com"
|
10
|
+
gemspec.homepage = "http://github.com/smith/js2bookmarklet/"
|
11
|
+
gemspec.authors = ["Nathan L Smith"]
|
12
|
+
gemspec.add_dependency("jsmin")
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
17
|
+
|
18
|
+
Rake::TestTask.new do |t|
|
19
|
+
t.libs << "test"
|
20
|
+
t.test_files = FileList["test/test*.rb"]
|
21
|
+
t.verbose = true
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => [:test]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/js2bookmarklet
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
begin
|
5
|
+
require 'js2bookmarklet'
|
6
|
+
rescue LoadError => e
|
7
|
+
puts "Error: The js2bookmarklet gem is required"
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
input_file = ARGV.last
|
13
|
+
output_file = nil
|
14
|
+
usage = "Usage: js2bookmarklet [options] [input file]"
|
15
|
+
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.banner = usage
|
18
|
+
opts.on("-o [file name]", "--output [file name]", "Output file") do |o|
|
19
|
+
output_file = o
|
20
|
+
end
|
21
|
+
opts.on("-a [text]", "--link-text [text]", "Link text") do |t|
|
22
|
+
options["text"] = t
|
23
|
+
end
|
24
|
+
opts.on("-t [title]", "--link-title [title]", "Link title") do |t|
|
25
|
+
options["title"] = t
|
26
|
+
end
|
27
|
+
end.parse!
|
28
|
+
|
29
|
+
if File.exists?(input_file.to_s)
|
30
|
+
input = open(input_file).read
|
31
|
+
output = Js2bookmarklet.new(input, options).to_bookmarklet
|
32
|
+
if output_file
|
33
|
+
open(output_file, "w").write(output)
|
34
|
+
else
|
35
|
+
puts output
|
36
|
+
end
|
37
|
+
else
|
38
|
+
puts usage
|
39
|
+
puts "Error: Input file does not exist"
|
40
|
+
exit 1
|
41
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{js2bookmarklet}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nathan L Smith"]
|
12
|
+
s.date = %q{2009-11-12}
|
13
|
+
s.default_executable = %q{js2bookmarklet}
|
14
|
+
s.description = %q{Utility to create a bookmarklet from a JavaScript file}
|
15
|
+
s.email = %q{nlloyds@gmail.com}
|
16
|
+
s.executables = ["js2bookmarklet"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bin/js2bookmarklet",
|
25
|
+
"lib/js2bookmarklet.rb",
|
26
|
+
"test/fixtures/script.js",
|
27
|
+
"test/test_js2bookmarklet.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/smith/js2bookmarklet/}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{}
|
34
|
+
s.test_files = [
|
35
|
+
"test/test_js2bookmarklet.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<jsmin>, [">= 0"])
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<jsmin>, [">= 0"])
|
46
|
+
end
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<jsmin>, [">= 0"])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'jsmin'
|
4
|
+
rescue LoadError => e
|
5
|
+
puts 'JSMin is required. Install it with gem install jsmin'
|
6
|
+
exit
|
7
|
+
end
|
8
|
+
|
9
|
+
class Js2bookmarklet
|
10
|
+
LINK_TEXT = "Drag me to your bookmarks"
|
11
|
+
|
12
|
+
def initialize(input = "", options = {})
|
13
|
+
@in = input
|
14
|
+
@out = ""
|
15
|
+
@options = options
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_bookmarklet
|
19
|
+
minify
|
20
|
+
escape
|
21
|
+
add_link
|
22
|
+
@out
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def minify
|
27
|
+
@out = JSMin::minify(@in).sub(/\A\n/, "") # Minify & remove 1st blank line
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_link
|
31
|
+
title = @options["title"] ? " title=\"#{@options["title"]}\"" : ""
|
32
|
+
text = @options["text"] ? @options["text"] : LINK_TEXT
|
33
|
+
|
34
|
+
@out = "<a href='javascript:#{@out}'#{title}>#{text}</a>"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Taken from rails escape_javascript
|
38
|
+
def escape
|
39
|
+
escape_map = {
|
40
|
+
'\\' => '\\\\',
|
41
|
+
'</' => '<\/',
|
42
|
+
"\r\n" => '\n',
|
43
|
+
"\n" => '\n',
|
44
|
+
"\r" => '\n',
|
45
|
+
'"' => '\\"',
|
46
|
+
"'" => "\\'" }
|
47
|
+
|
48
|
+
@out.gsub!(/(\\|<\/|\r\n|[\n\r"'])/) { escape_map[$1] }
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/js2bookmarklet'
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class TestJs2bookmarklet < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@in = File.open("test/fixtures/script.js").read
|
7
|
+
@out = Js2bookmarklet.new(@in).to_bookmarklet
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_minify
|
11
|
+
# Is the output a string?
|
12
|
+
assert_equal(String, @out.class)
|
13
|
+
|
14
|
+
# Is the output one line?
|
15
|
+
line_count = 0
|
16
|
+
@out.each_line {|line| line_count += 1 }
|
17
|
+
assert_equal(1, line_count)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_to_bookmarklet
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: js2bookmarklet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan L Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-12 00:00:00 -06:00
|
13
|
+
default_executable: js2bookmarklet
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jsmin
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Utility to create a bookmarklet from a JavaScript file
|
26
|
+
email: nlloyds@gmail.com
|
27
|
+
executables:
|
28
|
+
- js2bookmarklet
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- bin/js2bookmarklet
|
38
|
+
- js2bookmarklet.gemspec
|
39
|
+
- lib/js2bookmarklet.rb
|
40
|
+
- test/fixtures/script.js
|
41
|
+
- test/test_js2bookmarklet.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/smith/js2bookmarklet/
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: ""
|
70
|
+
test_files:
|
71
|
+
- test/test_js2bookmarklet.rb
|