spader 0.0.1.pre.pre → 0.0.3.pre.pre
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.
- checksums.yaml +4 -4
- data/bin/spader +68 -329
- data/lib/spader.rb +10 -10
- data/lib/spader/command.rb +13 -14
- data/lib/spader/commands/build.rb +156 -120
- data/lib/spader/commands/generate.rb +66 -62
- data/lib/spader/document.rb +24 -22
- data/lib/spader/documents/manifest.rb +2 -0
- data/lib/spader/documents/messages.rb +2 -0
- data/lib/spader/documents/project.rb +71 -31
- data/lib/spader/util.rb +152 -135
- data/lib/spader/zip.rb +57 -0
- metadata +6 -5
@@ -1,32 +1,72 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
project
|
9
|
-
project.
|
10
|
-
project.
|
11
|
-
project.
|
12
|
-
project.
|
13
|
-
project.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Spader
|
4
|
+
class Project < Document
|
5
|
+
attr_accessor :title, :url, :author, :html, :js, :scss, :path, :static, :permissions
|
6
|
+
|
7
|
+
def self.generate(base_dir, opts = {})
|
8
|
+
project = Project.new()
|
9
|
+
project.path = make_path_absolute(base_dir, Dir.pwd, :dir)
|
10
|
+
project.title = opts.delete(:title) || "Example Title"
|
11
|
+
project.url = opts.delete(:url) || "https://cosmicshovel.com/"
|
12
|
+
project.author = opts.delete(:author) || "Cosmic Shovel, Inc."
|
13
|
+
project.html = []
|
14
|
+
project.js = []
|
15
|
+
project.scss = []
|
16
|
+
project.static = []
|
17
|
+
project.permissions = []
|
18
|
+
|
19
|
+
return project
|
20
|
+
end
|
21
|
+
|
22
|
+
def save_json(path)
|
23
|
+
@document = {
|
24
|
+
"path" => @path,
|
25
|
+
"title" => @title,
|
26
|
+
"url" => @url,
|
27
|
+
"author" => @author,
|
28
|
+
"html" => @html,
|
29
|
+
"js" => @js,
|
30
|
+
"scss" => @scss,
|
31
|
+
"static" => @static,
|
32
|
+
"permissions" => @permissions,
|
33
|
+
}
|
34
|
+
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_json(path)
|
39
|
+
super
|
40
|
+
|
41
|
+
@path = @document["path"]
|
42
|
+
@title = @document["title"]
|
43
|
+
@url = @document["url"]
|
44
|
+
@author = @document["author"]
|
45
|
+
@html = absoluteize_paths(@document["html"], "html")
|
46
|
+
@js = absoluteize_paths(@document["js"], "js")
|
47
|
+
@scss = absoluteize_paths(@document["scss"], "scss")
|
48
|
+
@static = absoluteize_paths(@document["static"], "static")
|
49
|
+
@permissions = @document["permissions"]
|
50
|
+
|
51
|
+
return self
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def absoluteize_paths(paths, asset_type)
|
57
|
+
out = []
|
58
|
+
|
59
|
+
base_dir = @path.dup()
|
60
|
+
|
61
|
+
if asset_type != "static"
|
62
|
+
base_dir << asset_type + File::SEPARATOR
|
63
|
+
end
|
64
|
+
|
65
|
+
paths.each do |path|
|
66
|
+
out << make_path_absolute(path, base_dir, :file)
|
67
|
+
end
|
68
|
+
|
69
|
+
return out
|
70
|
+
end
|
71
|
+
end
|
32
72
|
end
|
data/lib/spader/util.rb
CHANGED
@@ -1,136 +1,153 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
return
|
46
|
-
end
|
47
|
-
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
def
|
60
|
-
return
|
61
|
-
end
|
62
|
-
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
return
|
73
|
-
end
|
74
|
-
|
75
|
-
def
|
76
|
-
return
|
77
|
-
end
|
78
|
-
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
return
|
120
|
-
end
|
121
|
-
|
122
|
-
def
|
123
|
-
return files_in_dir(path).delete_if {|f| File.basename(f)[0, 1]
|
124
|
-
end
|
125
|
-
|
126
|
-
def
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
def
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
def
|
135
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative "zip"
|
4
|
+
|
5
|
+
def write_file(filename, data, append = false)
|
6
|
+
if data.is_a?(String)
|
7
|
+
data = data.force_encoding(Encoding::UTF_8)
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
File.open(filename, append ? "a" : "w") { |f|
|
12
|
+
f.write(data)
|
13
|
+
}
|
14
|
+
rescue Exception => e
|
15
|
+
dmsg(e)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_file(filename)
|
20
|
+
begin
|
21
|
+
File.open(filename, "r") do |f|
|
22
|
+
return f.readlines().join("")
|
23
|
+
end
|
24
|
+
rescue Exception => e
|
25
|
+
dmsg(e)
|
26
|
+
end
|
27
|
+
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# eventually this should use a special Spader binding
|
32
|
+
# and allow users to expose their own variables
|
33
|
+
def render(template)
|
34
|
+
browser = $spader_cmd.browser
|
35
|
+
build_info = $spader_cmd.build_info
|
36
|
+
camel_domain = "camelcamelcamel.com"
|
37
|
+
api_endpoint = "izer.camelcamelcamel.com"
|
38
|
+
charts_domain = "charts.camelcamelcamel.com"
|
39
|
+
analytics_endpoint = "hello.camelcamelcamel.com/camelizer"
|
40
|
+
browser_requires_polyfill = is_browser_chromal?()
|
41
|
+
zoom_levels = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0]
|
42
|
+
b = binding
|
43
|
+
template = File.absolute_path(template, $spader_cmd.path)
|
44
|
+
|
45
|
+
return ERB.new(read_file(template)).result(b)
|
46
|
+
end
|
47
|
+
|
48
|
+
def pad10(str_num)
|
49
|
+
return "%02d" % [str_num.to_i()]
|
50
|
+
end
|
51
|
+
|
52
|
+
def dmsg(msg, cache = false)
|
53
|
+
t = DateTime.now()
|
54
|
+
msg = msg.is_a?(String) ? msg : msg.inspect()
|
55
|
+
|
56
|
+
puts "[#{pad10(t.hour())}:#{pad10(t.min())}:#{pad10(t.sec())}] " + msg
|
57
|
+
end
|
58
|
+
|
59
|
+
def pretty_float(f)
|
60
|
+
return ("%0.2f" % f)
|
61
|
+
end
|
62
|
+
|
63
|
+
def is_camelizer_three_oh_oh?(ver)
|
64
|
+
return Gem::Version.new(ver) == Gem::Version.new("3.0.0")
|
65
|
+
end
|
66
|
+
|
67
|
+
def anchor_target()
|
68
|
+
if !is_browser_chromal?()
|
69
|
+
return ""
|
70
|
+
end
|
71
|
+
|
72
|
+
return "target=\"_blank\""
|
73
|
+
end
|
74
|
+
|
75
|
+
def is_browser_chromal?()
|
76
|
+
return %w[chrome edge opera brave].include?($spader_cmd.browser.downcase())
|
77
|
+
end
|
78
|
+
|
79
|
+
def browsers()
|
80
|
+
return Spader::BROWSERS
|
81
|
+
end
|
82
|
+
|
83
|
+
def entries(path)
|
84
|
+
list = Dir.entries(path).delete_if {|f| f == "." || f == ".."}
|
85
|
+
out = []
|
86
|
+
|
87
|
+
list.each do |entry|
|
88
|
+
full_path = path.dup()
|
89
|
+
|
90
|
+
if path[-1, 1] != "/"
|
91
|
+
full_path << "/"
|
92
|
+
end
|
93
|
+
|
94
|
+
full_path << entry
|
95
|
+
out << full_path
|
96
|
+
end
|
97
|
+
|
98
|
+
return out
|
99
|
+
end
|
100
|
+
|
101
|
+
def dirs_in_dir(path)
|
102
|
+
list = entries(path).delete_if {|f| !File.directory?(f)}
|
103
|
+
out = []
|
104
|
+
|
105
|
+
list.each do |entry|
|
106
|
+
if entry[-1, 1] != "/"
|
107
|
+
entry << "/"
|
108
|
+
end
|
109
|
+
|
110
|
+
out << entry
|
111
|
+
end
|
112
|
+
|
113
|
+
return out
|
114
|
+
end
|
115
|
+
|
116
|
+
def files_in_dir(path)
|
117
|
+
list = entries(path).delete_if {|f| File.directory?(f)}
|
118
|
+
|
119
|
+
return list
|
120
|
+
end
|
121
|
+
|
122
|
+
def primary_files_in_dir(path)
|
123
|
+
return files_in_dir(path).delete_if {|f| bn = File.basename(f); bn[0, 1] == "_" || bn[0, 1] == "."}
|
124
|
+
end
|
125
|
+
|
126
|
+
def partial_files_in_dir(path)
|
127
|
+
return files_in_dir(path).delete_if {|f| bn = File.basename(f); bn[0, 1] != "_"}
|
128
|
+
end
|
129
|
+
|
130
|
+
def primary_scss_files()
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
def primary_js_files()
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
def primary_html_files()
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
# path_type = one of [:dir, :file]
|
143
|
+
def make_path_absolute(path, base_dir, path_type)
|
144
|
+
tmp = File.absolute_path(path, base_dir)
|
145
|
+
|
146
|
+
if path_type == :dir
|
147
|
+
if tmp[-1, 1] != File::SEPARATOR
|
148
|
+
tmp << File::SEPARATOR
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
return tmp
|
136
153
|
end
|
data/lib/spader/zip.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'zip'
|
4
|
+
require 'zip/zip'
|
5
|
+
|
6
|
+
# This is a simple example which uses rubyzip to
|
7
|
+
# recursively generate a zip file from the contents of
|
8
|
+
# a specified directory. The directory itself is not
|
9
|
+
# included in the archive, rather just its contents.
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
# directory_to_zip = "/tmp/input"
|
13
|
+
# output_file = "/tmp/out.zip"
|
14
|
+
# zf = ZipFileGenerator.new(directory_to_zip, output_file)
|
15
|
+
# zf.write()
|
16
|
+
class ZipFileGenerator
|
17
|
+
# Initialize with the directory to zip and the location of the output archive.
|
18
|
+
def initialize(input_dir, output_file)
|
19
|
+
@input_dir = input_dir
|
20
|
+
@output_file = output_file
|
21
|
+
end
|
22
|
+
|
23
|
+
# Zip the input directory.
|
24
|
+
def write
|
25
|
+
entries = Dir.entries(@input_dir) - %w[. ..]
|
26
|
+
|
27
|
+
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |zipfile|
|
28
|
+
write_entries entries, '', zipfile
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# A helper method to make the recursion work.
|
35
|
+
def write_entries(entries, path, zipfile)
|
36
|
+
entries.each do |e|
|
37
|
+
zipfile_path = path == '' ? e : File.join(path, e)
|
38
|
+
disk_file_path = File.join(@input_dir, zipfile_path)
|
39
|
+
|
40
|
+
if File.directory? disk_file_path
|
41
|
+
recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
42
|
+
else
|
43
|
+
put_into_archive(disk_file_path, zipfile, zipfile_path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
49
|
+
zipfile.mkdir zipfile_path
|
50
|
+
subdir = Dir.entries(disk_file_path) - %w[. ..]
|
51
|
+
write_entries subdir, zipfile_path, zipfile
|
52
|
+
end
|
53
|
+
|
54
|
+
def put_into_archive(disk_file_path, zipfile, zipfile_path)
|
55
|
+
zipfile.add(zipfile_path, disk_file_path)
|
56
|
+
end
|
57
|
+
end
|