jhc 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +42 -24
- data/TODO +3 -0
- data/VERSION +1 -1
- data/bin/jhc +57 -47
- data/lib/index.haml +15 -0
- metadata +98 -94
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,49 @@
|
|
1
1
|
# jhc
|
2
2
|
|
3
3
|
## USAGE
|
4
|
-
|
5
|
-
Usage: jhc -t HTML_TITLE -j
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
|
5
|
+
Usage: jhc -t HTML_TITLE -j jquery,underscore -c bootstrap -e url -r
|
6
|
+
Description:
|
7
|
+
-t: specify HTML title
|
8
|
+
-j: specify javascript libraries
|
9
|
+
-c: specify css
|
10
|
+
-e: specify url to extract body
|
11
|
+
-r: reload wedata config and exit
|
12
|
+
Available JavaScript Libraries:
|
13
|
+
face_detector http://lab.gkbr.me/facedetect/facedetector.min.js
|
14
|
+
tiny_segmenter http://chasen.org/~taku/software/TinySegmenter/tiny_segmenter-0.1.js
|
15
|
+
backbone http://documentcloud.github.com/backbone/backbone.js
|
16
|
+
underscore http://documentcloud.github.com/underscore/underscore.js
|
17
|
+
jquery http://code.jquery.com/jquery-1.7.js
|
18
|
+
Available StyleSheets:
|
19
|
+
bootstrap https://raw.github.com/twitter/bootstrap/master/bootstrap.css
|
20
|
+
|
21
|
+
Just hit the command:
|
22
|
+
|
23
|
+
$ jhc -t "Test App" -j jquery,underscore -c bootstrap testapp
|
24
|
+
# welcome to jhc v0.0.4
|
25
|
+
add: testapp/js/jquery.js # http://code.jquery.com/jquery-1.7.js
|
26
|
+
add: testapp/js/underscore.js # http://documentcloud.github.com/underscore/underscore.js
|
27
|
+
add: testapp/css/bootstrap.css # https://raw.github.com/twitter/bootstrap/master/bootstrap.css
|
28
|
+
add: testapp/index.html
|
29
|
+
|
30
|
+
And you get:
|
31
|
+
|
32
|
+
$ tree testapp
|
33
|
+
testapp
|
34
|
+
├── css
|
35
|
+
│ └── bootstrap.css
|
36
|
+
├── index.html
|
37
|
+
└── js
|
38
|
+
├── jquery.js
|
39
|
+
└── underscore.js
|
16
40
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
<script language="javascript" type="text/javascript" src="./javascripts/jquery.js"></script>
|
24
|
-
<link rel="stylesheet" type="text/css" href="./stylesheets/bootstrap.css" />
|
25
|
-
</head>
|
26
|
-
<body>
|
27
|
-
</body>
|
28
|
-
</html>
|
41
|
+
2 directories, 4 files
|
42
|
+
|
43
|
+
## MORE USAGE
|
44
|
+
|
45
|
+
* with "-e URL" (e.g. "-e http://www.google.com/"), you can extract URL's html body and add it to your index.html
|
46
|
+
* config is loaded from [Wedata](http://wedata.net/databases/JHC/items). you can reload it with "-r" option.
|
29
47
|
|
30
48
|
## INSTALL
|
31
49
|
gem install jhc
|
data/TODO
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/bin/jhc
CHANGED
@@ -1,77 +1,59 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# inspired by http://d.hatena.ne.jp/hitode909/20110614/1308032945
|
3
3
|
require 'yaml'
|
4
|
-
require 'erb'
|
5
4
|
require 'optparse'
|
6
5
|
require 'open-uri'
|
7
6
|
require 'fileutils'
|
7
|
+
require 'kconv'
|
8
8
|
require 'rubygems'
|
9
9
|
require 'nokogiri'
|
10
|
+
require 'haml'
|
11
|
+
require 'json'
|
12
|
+
require 'term/ansicolor'
|
13
|
+
include Term::ANSIColor
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
jquery: http://code.jquery.com/jquery-1.7.js
|
15
|
-
underscore: http://documentcloud.github.com/underscore/underscore.js
|
16
|
-
backbone: http://documentcloud.github.com/backbone/backbone.js
|
17
|
-
stylesheets:
|
18
|
-
bootstrap: https://raw.github.com/twitter/bootstrap/master/bootstrap.css
|
19
|
-
EOC
|
15
|
+
VERSION = File.read(File.dirname(__FILE__) + '/../VERSION')
|
16
|
+
WEDATA_URL = 'http://wedata.net/databases/JHC/items.json'
|
17
|
+
CONFIG_PATH = ENV['HOME'] + '/.jhc'
|
20
18
|
|
21
19
|
def main(args)
|
22
|
-
|
20
|
+
puts white("# welcome to jhc v#{VERSION}")
|
23
21
|
opt = parse_args(args)
|
24
|
-
dir = args[0]
|
25
|
-
hlp = "Usage: jhc -t HTML_TITLE -j #{cfg['javascripts'].keys.join(',')} -s #{cfg['stylesheets'].keys.join(',')}"
|
26
22
|
|
27
|
-
|
23
|
+
if !File.exists?(CONFIG_PATH) || opt['reload']
|
24
|
+
puts white("# downloading: config data from wedata.net")
|
25
|
+
load_config
|
26
|
+
exit 0 if opt['reload']
|
27
|
+
end
|
28
|
+
cfg = YAML.load(File.read(CONFIG_PATH))
|
29
|
+
|
30
|
+
dir = args[0]
|
31
|
+
raise help(cfg) unless dir
|
28
32
|
|
29
33
|
FileUtils.mkdir_p(dir)
|
30
34
|
|
31
|
-
%w(
|
35
|
+
%w(js css).each do |key|
|
32
36
|
next unless opt[key]
|
33
37
|
FileUtils.mkdir_p(File.join(dir, key))
|
34
38
|
opt[key].split(',').each do |lib|
|
35
|
-
if
|
36
|
-
content = open(url).read
|
37
|
-
|
38
|
-
|
39
|
+
if item = cfg.find {|c| c['data']['key'] == lib && c['data']['type'] == key }
|
40
|
+
content = open(item['data']['url']).read
|
41
|
+
File.open(File.join(dir, key, "#{lib}.#{key}"), 'w').write(content)
|
42
|
+
puts blue("add: " + File.join(dir, key, "#{lib}.#{key}")) + white(" # #{item['data']['url']}")
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
47
|
body = nil
|
44
48
|
if opt['extract']
|
49
|
+
puts white("# extracting body of #{opt['extract']}")
|
45
50
|
doc = Nokogiri::HTML.parse(open(opt['extract']).read)
|
46
|
-
body = doc.search('/html/body').to_s
|
51
|
+
body = doc.search('/html/body').to_s.toutf8
|
47
52
|
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
<head>
|
53
|
-
<meta charset="utf-8">
|
54
|
-
<title><%= opt['title'] %></title>
|
55
|
-
<% if opt['javascripts'] -%>
|
56
|
-
<% opt['javascripts'].split(',').each do |key| -%>
|
57
|
-
<script language="javascript" type="text/javascript" src="./javascripts/<%= key %>.js"></script>
|
58
|
-
<% end -%>
|
59
|
-
<% end -%>
|
60
|
-
<% if opt['stylesheets'] -%>
|
61
|
-
<% opt['stylesheets'].split(',').each do |key| -%>
|
62
|
-
<link rel="stylesheet" type="text/css" href="./stylesheets/<%= key %>.css" />
|
63
|
-
<% end -%>
|
64
|
-
<% end -%>
|
65
|
-
</head>
|
66
|
-
<% if body -%>
|
67
|
-
<%= body %>
|
68
|
-
<% else -%>
|
69
|
-
<body>
|
70
|
-
</body>
|
71
|
-
<% end -%>
|
72
|
-
</html>
|
73
|
-
HTML
|
74
|
-
html = ERB.new(erb, nil, '-').result(binding)
|
54
|
+
haml = File.read(File.dirname(__FILE__) + '/../lib/index.haml')
|
55
|
+
html = Haml::Engine.new(haml, :format => :html5).render(binding)
|
56
|
+
puts blue("add: #{File.join(dir, 'index.html')}")
|
75
57
|
File.open(File.join(dir, 'index.html'), 'w').write(html)
|
76
58
|
rescue StandardError => e
|
77
59
|
puts e
|
@@ -81,13 +63,41 @@ end
|
|
81
63
|
def parse_args(args)
|
82
64
|
opt = {}
|
83
65
|
OptionParser.new do |o|
|
84
|
-
%w(title
|
66
|
+
%w(title js css extract).each do |key|
|
85
67
|
o.on("-#{key.chars.first} #{key.upcase}") {|v| opt[key] = v }
|
86
68
|
end
|
69
|
+
o.on("-r") {|v| opt['reload'] = v }
|
87
70
|
o.parse!(args)
|
88
71
|
end
|
89
72
|
opt
|
90
73
|
end
|
91
74
|
|
75
|
+
def load_config
|
76
|
+
json = JSON.parse(open(WEDATA_URL).read)
|
77
|
+
file = File.open(CONFIG_PATH, 'w')
|
78
|
+
file.write(json.to_yaml)
|
79
|
+
file.close
|
80
|
+
end
|
81
|
+
|
82
|
+
def help(config)
|
83
|
+
buf = ''
|
84
|
+
buf += "Usage: jhc -t HTML_TITLE -j jquery,underscore -c bootstrap -e url -r\n"
|
85
|
+
buf += "Description:\n"
|
86
|
+
buf += "\t-t: specify HTML title\n"
|
87
|
+
buf += "\t-j: specify javascript libraries\n"
|
88
|
+
buf += "\t-c: specify css\n"
|
89
|
+
buf += "\t-e: specify url to extract body\n"
|
90
|
+
buf += "\t-r: reload wedata config and exit\n"
|
91
|
+
buf += "Available JavaScript Libraries:\n"
|
92
|
+
config.select{|c| c['data']['type'] == 'js'}.each do |c|
|
93
|
+
buf += "\t#{c['data']['key']}\t#{c['data']['url']}\n"
|
94
|
+
end
|
95
|
+
buf += "Available StyleSheets:\n"
|
96
|
+
config.select{|c| c['data']['type'] == 'css'}.each do |c|
|
97
|
+
buf += "\t#{c['data']['key']}\t#{c['data']['url']}\n"
|
98
|
+
end
|
99
|
+
red(buf)
|
100
|
+
end
|
101
|
+
|
92
102
|
main(ARGV.dup)
|
93
103
|
|
data/lib/index.haml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{:charset=>'utf-8'}
|
5
|
+
%title= opt['title']
|
6
|
+
- if opt['js']
|
7
|
+
- opt['js'].split(',').each do |key|
|
8
|
+
%script{:language=>'javascript',:type=>'text/javascript',:src=>"./javascripts/#{key}.js"}
|
9
|
+
- if opt['css']
|
10
|
+
- opt['css'].split(',').each do |key|
|
11
|
+
%link{:rel=>'stylesheet',:type=>'text/css',:href=>"./stylesheets/#{key}.css"}
|
12
|
+
- if body
|
13
|
+
= body
|
14
|
+
- else
|
15
|
+
%body
|
metadata
CHANGED
@@ -1,107 +1,115 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jhc
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- tily
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
-
none: false
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 3
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
version: "0"
|
12
|
+
date: 2011-11-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
30
15
|
name: shoulda
|
31
|
-
|
16
|
+
requirement: &70218982526420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70218982526420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &70218982524480 !ruby/object:Gem::Requirement
|
36
28
|
none: false
|
37
|
-
requirements:
|
29
|
+
requirements:
|
38
30
|
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
hash: 23
|
41
|
-
segments:
|
42
|
-
- 1
|
43
|
-
- 0
|
44
|
-
- 0
|
31
|
+
- !ruby/object:Gem::Version
|
45
32
|
version: 1.0.0
|
46
|
-
name: bundler
|
47
|
-
prerelease: false
|
48
33
|
type: :development
|
49
|
-
|
50
|
-
|
51
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70218982524480
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &70218982518100 !ruby/object:Gem::Requirement
|
52
39
|
none: false
|
53
|
-
requirements:
|
40
|
+
requirements:
|
54
41
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
hash: 7
|
57
|
-
segments:
|
58
|
-
- 1
|
59
|
-
- 6
|
60
|
-
- 4
|
42
|
+
- !ruby/object:Gem::Version
|
61
43
|
version: 1.6.4
|
62
|
-
|
44
|
+
type: :development
|
63
45
|
prerelease: false
|
46
|
+
version_requirements: *70218982518100
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rcov
|
49
|
+
requirement: &70218982509960 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
64
55
|
type: :development
|
65
|
-
|
66
|
-
|
67
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70218982509960
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: nokogiri
|
60
|
+
requirement: &70218982504700 !ruby/object:Gem::Requirement
|
68
61
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
|
74
|
-
- 0
|
75
|
-
version: "0"
|
76
|
-
name: rcov
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
77
67
|
prerelease: false
|
68
|
+
version_requirements: *70218982504700
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: haml
|
71
|
+
requirement: &70218982500860 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
78
77
|
type: :development
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70218982500860
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: json
|
82
|
+
requirement: &70218982486660 !ruby/object:Gem::Requirement
|
82
83
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
|
88
|
-
- 0
|
89
|
-
version: "0"
|
90
|
-
name: nokogiri
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
91
89
|
prerelease: false
|
90
|
+
version_requirements: *70218982486660
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: term-ansicolor
|
93
|
+
requirement: &70218982472520 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
92
99
|
type: :development
|
93
|
-
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70218982472520
|
94
102
|
description: generate modern html scaffold
|
95
103
|
email: tily05@gmail.com
|
96
|
-
executables:
|
104
|
+
executables:
|
97
105
|
- jhc
|
98
106
|
extensions: []
|
99
|
-
|
100
|
-
extra_rdoc_files:
|
107
|
+
extra_rdoc_files:
|
101
108
|
- LICENSE.txt
|
102
109
|
- README.md
|
103
110
|
- README.rdoc
|
104
|
-
|
111
|
+
- TODO
|
112
|
+
files:
|
105
113
|
- .document
|
106
114
|
- Gemfile
|
107
115
|
- LICENSE.txt
|
@@ -110,41 +118,37 @@ files:
|
|
110
118
|
- Rakefile
|
111
119
|
- VERSION
|
112
120
|
- bin/jhc
|
121
|
+
- lib/index.haml
|
113
122
|
- lib/jhc.rb
|
114
123
|
- test/helper.rb
|
115
124
|
- test/test_jhc.rb
|
125
|
+
- TODO
|
116
126
|
homepage: http://github.com/tily/jhc
|
117
|
-
licenses:
|
127
|
+
licenses:
|
118
128
|
- MIT
|
119
129
|
post_install_message:
|
120
130
|
rdoc_options: []
|
121
|
-
|
122
|
-
require_paths:
|
131
|
+
require_paths:
|
123
132
|
- lib
|
124
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
134
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
segments:
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
segments:
|
131
140
|
- 0
|
132
|
-
|
133
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
hash: -2332572723009259839
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
143
|
none: false
|
135
|
-
requirements:
|
136
|
-
- -
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
|
139
|
-
segments:
|
140
|
-
- 0
|
141
|
-
version: "0"
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
142
148
|
requirements: []
|
143
|
-
|
144
149
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.8.
|
150
|
+
rubygems_version: 1.8.10
|
146
151
|
signing_key:
|
147
152
|
specification_version: 3
|
148
153
|
summary: generate modern html scaffold
|
149
154
|
test_files: []
|
150
|
-
|