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.
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Spader
2
4
  class Manifest < Document
3
5
  def self.generate()
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Spader
2
4
  class Messages < Document
3
5
  def self.generate(project_title)
@@ -1,32 +1,72 @@
1
- module Spader
2
- class Project < Document
3
- attr_accessor :title, :url, :author, :html, :js, :scss, :path
4
-
5
- def self.generate(base_dir, opts = {})
6
- project = Project.new()
7
- project.path = File.absolute_path(base_dir, Dir.pwd) + File::SEPARATOR
8
- project.title = opts.delete(:title) || "Example Title"
9
- project.url = opts.delete(:url) || "https://cosmicshovel.com/"
10
- project.author = opts.delete(:author) || "Cosmic Shovel, Inc."
11
- project.html = []
12
- project.js = []
13
- project.scss = []
14
-
15
- return project
16
- end
17
-
18
- def save_json(path)
19
- @document = {
20
- "path" => @path,
21
- "title" => @title,
22
- "url" => @url,
23
- "author" => @author,
24
- "html" => @html,
25
- "js" => @js,
26
- "scss" => @scss,
27
- }
28
-
29
- super
30
- end
31
- end
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
- def write_file(filename, data, append = false)
2
- if data.is_a?(String)
3
- data = data.force_encoding(Encoding::UTF_8)
4
- end
5
-
6
- begin
7
- File.open(filename, append ? "a" : "w") { |f|
8
- f.write(data)
9
- }
10
- rescue Exception => e
11
- dmsg(e)
12
- end
13
- end
14
-
15
- def read_file(filename)
16
- begin
17
- File.open(filename, "r") do |f|
18
- return f.readlines().join("")
19
- end
20
- rescue Exception => e
21
- dmsg(e)
22
- end
23
-
24
- return nil
25
- end
26
-
27
- # eventually this should use a special Spader binding
28
- # and allow users to expose their own variables
29
- def render(template)
30
- browser = $spader_cmd.browser
31
- build_info = $spader_cmd.build_info
32
- camel_domain = "dissident.be"
33
- api_endpoint = "dissident.be"
34
- charts_domain = "charts-dev.camelcamelcamel.com"
35
- analytics_endpoint = "hello.camelcamelcamel.com/camelizer"
36
- browser_requires_polyfill = is_browser_chromal?()
37
- 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]
38
- b = binding
39
- template = File.absolute_path(template, $spader_cmd.path)
40
-
41
- return ERB.new(read_file(template)).result(b)
42
- end
43
-
44
- def pad10(str_num)
45
- return "%02d" % [str_num.to_i()]
46
- end
47
-
48
- def dmsg(msg, cache = false)
49
- t = DateTime.now()
50
- msg = msg.is_a?(String) ? msg : msg.inspect()
51
-
52
- puts "[#{pad10(t.hour())}:#{pad10(t.min())}:#{pad10(t.sec())}] " + msg
53
- end
54
-
55
- def pretty_float(f)
56
- return ("%0.2f" % f)
57
- end
58
-
59
- def is_camelizer_three_oh_oh?(ver)
60
- return Gem::Version.new(ver) == Gem::Version.new("3.0.0")
61
- end
62
-
63
- def anchor_target()
64
- if !is_browser_chromal?()
65
- return ""
66
- end
67
-
68
- return "target=\"_blank\""
69
- end
70
-
71
- def is_browser_chromal?()
72
- return %w[chrome edge opera brave].include?($spader_cmd.browser.downcase())
73
- end
74
-
75
- def browsers()
76
- return Spader::BROWSERS
77
- end
78
-
79
- def entries(path)
80
- list = Dir.entries(path).delete_if {|f| f == "." || f == ".."}
81
- out = []
82
-
83
- list.each do |entry|
84
- full_path = path.dup()
85
-
86
- if path[-1, 1] != "/"
87
- full_path << "/"
88
- end
89
-
90
- full_path << entry
91
- out << full_path
92
- end
93
-
94
- return out
95
- end
96
-
97
- def dirs_in_dir(path)
98
- list = entries(path).delete_if {|f| !File.directory?(f)}
99
- out = []
100
-
101
- list.each do |entry|
102
- if entry[-1, 1] != "/"
103
- entry << "/"
104
- end
105
-
106
- out << entry
107
- end
108
-
109
- return out
110
- end
111
-
112
- def files_in_dir(path)
113
- list = entries(path).delete_if {|f| File.directory?(f)}
114
-
115
- return list
116
- end
117
-
118
- def primary_files_in_dir(path)
119
- return files_in_dir(path).delete_if {|f| File.basename(f)[0, 1] == "_"}
120
- end
121
-
122
- def partial_files_in_dir(path)
123
- return files_in_dir(path).delete_if {|f| File.basename(f)[0, 1] != "_"}
124
- end
125
-
126
- def primary_scss_files()
127
-
128
- end
129
-
130
- def primary_js_files()
131
-
132
- end
133
-
134
- def primary_html_files()
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