staticz 1.0.10 → 1.0.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f4c779f303f2e6bfa06e6135323e61e4c089067361d4239d6c53903c239ae02
4
- data.tar.gz: 8958a5a56ed411ef10584076a57994a67786cda23bf6d3f0d012d77cf7954ae3
3
+ metadata.gz: a80ecb49f81917fbaaf10fabec468748de38f060525fe63826c9b24f6f40fe7e
4
+ data.tar.gz: d0d42fa919ad0e332a6b310a855ec72af64786401e32825f52ace50303ba08f7
5
5
  SHA512:
6
- metadata.gz: 2e49f8abff572d050666d143a4a6bbf555e2d97dfbb9d0614950dd3f93ce1d8121e34c4dac74f730fc5b8e7c6d199a675c493074881ff1f74c3a3d6aefd4ecb6
7
- data.tar.gz: 510b452f0dbd668b955ecd56f34e8ef468c42cec49e061968784d0eb9b1917572b1f78d6e5afa56c41635aa035a55c734583c544138eda6486ee30b3d5271e58
6
+ metadata.gz: 6b9956372490bdd8bb44ff5533c05e107f9d5997ccf8b42186037dc4dc4e475b55972712c613cc88de3e208999d5ee985f152d215f774d3b43d907c4e43b6738
7
+ data.tar.gz: 104e0a387444c5e8e962936fce024bf416389bc8b4e1a118473827bc6765f1d164511cd9d5ebe313405ac7150e8c09a8e420776e7f2b47162c7d5647a86c9f25
@@ -8,11 +8,7 @@ module Staticz
8
8
 
9
9
  attr_reader :name
10
10
 
11
- def source_file_ending = "coffee"
12
-
13
- def build_file_ending = "js"
14
-
15
- def tile_type_name = "Coff"
11
+ compile "coffee", "js", "Coff"
16
12
 
17
13
  def initialize(name)
18
14
  @name = name
@@ -20,11 +16,13 @@ module Staticz
20
16
 
21
17
  def build
22
18
  if exists?
23
- js = CoffeeScript.compile File.read(source_path)
24
-
25
- File.write build_path, js
19
+ File.write build_path, render
26
20
  end
27
21
  end
22
+
23
+ def render
24
+ CoffeeScript.compile File.read(source_path)
25
+ end
28
26
  end
29
27
  end
30
28
  end
@@ -8,11 +8,7 @@ module Staticz
8
8
 
9
9
  attr_reader :name
10
10
 
11
- def source_file_ending = "haml"
12
-
13
- def build_file_ending = "html"
14
-
15
- def tile_type_name = "Haml"
11
+ compile "haml", "html", "Haml"
16
12
 
17
13
  def initialize(name)
18
14
  @name = name
@@ -7,11 +7,7 @@ module Staticz
7
7
 
8
8
  attr_reader :name
9
9
 
10
- def source_file_ending = "js"
11
-
12
- def build_file_ending = "js"
13
-
14
- def tile_type_name = "Js"
10
+ compile "js", "js", "Js"
15
11
 
16
12
  def initialize(name)
17
13
  @name = name
@@ -19,9 +15,13 @@ module Staticz
19
15
 
20
16
  def build
21
17
  if exists?
22
- File.write build_path, File.read(source_path)
18
+ File.write build_path, render
23
19
  end
24
20
  end
21
+
22
+ def render
23
+ File.read(source_path)
24
+ end
25
25
  end
26
26
  end
27
27
  end
@@ -8,11 +8,7 @@ module Staticz
8
8
 
9
9
  attr_reader :name
10
10
 
11
- def source_file_ending = "js"
12
-
13
- def build_file_ending = "js"
14
-
15
- def tile_type_name = "React"
11
+ compile "js", "js", "React"
16
12
 
17
13
  def initialize(name)
18
14
  @name = name
@@ -20,11 +16,13 @@ module Staticz
20
16
 
21
17
  def build
22
18
  if exists?
23
- engine = Babel::Transpiler.transform File.read(source_path)
24
-
25
- File.write build_path, engine["code"]
19
+ File.write build_path, render
26
20
  end
27
21
  end
22
+
23
+ def render
24
+ Babel::Transpiler.transform(File.read(source_path))["code"]
25
+ end
28
26
  end
29
27
  end
30
28
  end
@@ -8,11 +8,7 @@ module Staticz
8
8
 
9
9
  attr_reader :name
10
10
 
11
- def source_file_ending = "sass"
12
-
13
- def build_file_ending = "css"
14
-
15
- def tile_type_name = "Sass"
11
+ compile "sass", "css", "Sass"
16
12
 
17
13
  def initialize(name)
18
14
  @name = name
@@ -20,12 +16,14 @@ module Staticz
20
16
 
21
17
  def build
22
18
  if valid?
23
- engine = ::SassC::Engine.new(File.read(source_path), syntax: :sass, style: :compressed)
24
-
25
- File.write build_path, engine.render
19
+ File.write build_path, render
26
20
  end
27
21
  end
28
22
 
23
+ def render
24
+ ::SassC::Engine.new(File.read(source_path), syntax: :sass, style: :compressed).render
25
+ end
26
+
29
27
  def errors
30
28
  errors = super
31
29
 
@@ -8,11 +8,7 @@ module Staticz
8
8
 
9
9
  attr_reader :name
10
10
 
11
- def source_file_ending = "scss"
12
-
13
- def build_file_ending = "css"
14
-
15
- def tile_type_name = "Scss"
11
+ compile "scss", "css", "Scss"
16
12
 
17
13
  def initialize(name)
18
14
  @name = name
@@ -20,12 +16,14 @@ module Staticz
20
16
 
21
17
  def build
22
18
  if valid?
23
- engine = ::SassC::Engine.new(File.read(source_path), syntax: :scss, style: :compressed)
24
-
25
- File.write build_path, engine.render
19
+ File.write build_path, render
26
20
  end
27
21
  end
28
22
 
23
+ def render
24
+ ::SassC::Engine.new(File.read(source_path), syntax: :scss, style: :compressed).render
25
+ end
26
+
29
27
  def errors
30
28
  errors = super
31
29
 
@@ -5,6 +5,8 @@ module Staticz
5
5
  class SimpleFile
6
6
  include Compilable
7
7
 
8
+ compile "", "", "File"
9
+
8
10
  attr_reader :name
9
11
 
10
12
  def source_path
@@ -20,8 +22,6 @@ module Staticz
20
22
  Object.send(:define_method, path_method_name) { link_path }
21
23
  end
22
24
 
23
- def tile_type_name = "File"
24
-
25
25
  def initialize(name)
26
26
  @name = name
27
27
  end
@@ -2,6 +2,25 @@ require "io/console"
2
2
 
3
3
  module Staticz
4
4
  module Compilable
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+ module ClassMethods
9
+ def compile(source_file_ending, build_file_ending, file_type_name)
10
+ define_method :source_file_ending do
11
+ source_file_ending
12
+ end
13
+
14
+ define_method :build_file_ending do
15
+ build_file_ending
16
+ end
17
+
18
+ define_method :file_type_name do
19
+ file_type_name
20
+ end
21
+ end
22
+ end
23
+
5
24
  def path
6
25
  name.to_s
7
26
  end
@@ -46,14 +65,17 @@ module Staticz
46
65
  end
47
66
  end
48
67
 
49
- def print(indentation)
68
+ def print(indentation, *args)
50
69
  valid_symbol = if valid?
51
70
  Colors.in_green("✔")
52
71
  else
53
72
  Colors.in_red("✘")
54
73
  end
55
74
 
56
- puts "#{" " * (indentation * 3)}└─ #{tile_type_name}: #{path} #{valid_symbol} -> #{path_method_name}"
75
+ compilable_string = "#{" " * (indentation * 3)}└─ #{file_type_name}: #{path} #{valid_symbol}"
76
+ compilable_string << " -> #{path_method_name}" if !args.include? :no_path
77
+
78
+ puts compilable_string
57
79
 
58
80
  _height, width = IO.console.winsize
59
81
 
@@ -0,0 +1,81 @@
1
+ require_relative "sub"
2
+
3
+ module Staticz
4
+ class CSSBundle
5
+ attr_reader :name, :location, :elements
6
+
7
+ def initialize(name, location)
8
+ @name = name
9
+ @location = location
10
+ @elements = []
11
+ end
12
+
13
+ def sub(name, &block)
14
+ s = Staticz::Sub.new(generate_location_path(name))
15
+ elements.push(s)
16
+ s.instance_eval(&block)
17
+ end
18
+
19
+ def sass(name, &block)
20
+ elements.push(Staticz::Compilable::Sass.new(generate_location_path(name)))
21
+ end
22
+
23
+ def scss(name, &block)
24
+ elements.push(Staticz::Compilable::Scss.new(generate_location_path(name)))
25
+ end
26
+
27
+ def generate_location_path(name)
28
+ if location.empty?
29
+ name
30
+ else
31
+ "#{location}/#{name}"
32
+ end
33
+ end
34
+
35
+ def build
36
+ File.write "build/#{name}_bundle.css", render
37
+ end
38
+
39
+ def render
40
+ render_elements elements
41
+ end
42
+
43
+ def render_elements(elements)
44
+ elements
45
+ .map do |element|
46
+ if element.is_a? Staticz::Sub
47
+ render_elements element.elements
48
+ else
49
+ [
50
+ "/* #{element.name} */",
51
+ element.render
52
+ ].join("\n\n")
53
+ end
54
+ end
55
+ .join("\n\n")
56
+ end
57
+
58
+ def path_method_name
59
+ "#{name.to_s.gsub(/[.\/-]/, "_")}_css_bundle_path"
60
+ end
61
+
62
+ def create_link_function
63
+ link_path = "/#{name}_bundle.css"
64
+
65
+ Object.send(:define_method, path_method_name) do
66
+ link_path
67
+ end
68
+ end
69
+
70
+ def print(indentation)
71
+ puts "#{" " * (indentation * 3)}└─ CSSBundle: #{name} -> #{path_method_name}"
72
+ elements.each do |e|
73
+ e.print(indentation + 1, :no_path)
74
+ end
75
+ end
76
+
77
+ def path
78
+ "src/#{name}"
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,85 @@
1
+ require_relative "sub"
2
+
3
+ module Staticz
4
+ class JSBundle
5
+ attr_reader :name, :location, :elements
6
+
7
+ def initialize(name, location)
8
+ @name = name
9
+ @location = location
10
+ @elements = []
11
+ end
12
+
13
+ def sub(name, &block)
14
+ s = Staticz::Sub.new(generate_location_path(name))
15
+ elements.push(s)
16
+ s.instance_eval(&block)
17
+ end
18
+
19
+ def js(name, &block)
20
+ elements.push(Staticz::Compilable::Js.new(generate_location_path(name)))
21
+ end
22
+
23
+ def coffee(name, &block)
24
+ elements.push(Staticz::Compilable::Cs.new(generate_location_path(name)))
25
+ end
26
+
27
+ def react(name, &block)
28
+ elements.push(Staticz::Compilable::React.new(generate_location_path(name)))
29
+ end
30
+
31
+ def generate_location_path(name)
32
+ if location.empty?
33
+ name
34
+ else
35
+ "#{location}/#{name}"
36
+ end
37
+ end
38
+
39
+ def build
40
+ File.write "build/#{name}_bundle.js", render
41
+ end
42
+
43
+ def render
44
+ render_elements elements
45
+ end
46
+
47
+ def render_elements(elements)
48
+ elements
49
+ .map do |element|
50
+ if element.is_a? Staticz::Sub
51
+ render_elements element.elements
52
+ else
53
+ [
54
+ "// #{element.name}",
55
+ element.render
56
+ ].join("\n\n")
57
+ end
58
+ end
59
+ .join("\n\n")
60
+ end
61
+
62
+ def path_method_name
63
+ "#{name.to_s.gsub(/[.\/-]/, "_")}_js_bundle_path"
64
+ end
65
+
66
+ def create_link_function
67
+ link_path = "/#{name}_bundle.js"
68
+
69
+ Object.send(:define_method, path_method_name) do
70
+ link_path
71
+ end
72
+ end
73
+
74
+ def print(indentation)
75
+ puts "#{" " * (indentation * 3)}└─ JSBundle: #{name} -> #{path_method_name}"
76
+ elements.each do |e|
77
+ e.print(indentation + 1, :no_path)
78
+ end
79
+ end
80
+
81
+ def path
82
+ "src/#{name}"
83
+ end
84
+ end
85
+ end
@@ -7,6 +7,8 @@ require_relative "compilable/react"
7
7
  require_relative "compilable/sass"
8
8
  require_relative "compilable/scss"
9
9
  require_relative "compilable/simple_file"
10
+ require_relative "js_bundle"
11
+ require_relative "css_bundle"
10
12
 
11
13
  module Staticz
12
14
  class Manifest
@@ -53,6 +55,20 @@ module Staticz
53
55
  elements.push(Staticz::Compilable::SimpleFile.new(name))
54
56
  end
55
57
 
58
+ def js_bundle(name, &block)
59
+ s = Staticz::JSBundle.new(name, "")
60
+ elements.push(s)
61
+
62
+ s.instance_eval(&block)
63
+ end
64
+
65
+ def css_bundle(name, &block)
66
+ s = Staticz::CSSBundle.new(name, "")
67
+ elements.push(s)
68
+
69
+ s.instance_eval(&block)
70
+ end
71
+
56
72
  def build
57
73
  load "#{Dir.pwd}/manifest.rb"
58
74
 
data/lib/manifest/sub.rb CHANGED
@@ -41,6 +41,20 @@ module Staticz
41
41
  elements.push(Staticz::Compilable::SimpleFile.new("#{@name}/#{name}"))
42
42
  end
43
43
 
44
+ def js_bundle(name, &block)
45
+ s = Staticz::JSBundle.new("#{@name}/#{name}", @name)
46
+ elements.push(s)
47
+
48
+ s.instance_eval(&block)
49
+ end
50
+
51
+ def css_bundle(name, &block)
52
+ s = Staticz::CSSBundle.new("#{@name}/#{name}", @name)
53
+ elements.push(s)
54
+
55
+ s.instance_eval(&block)
56
+ end
57
+
44
58
  def build
45
59
  Dir.mkdir("build/#{name}") if !Dir.exist?("build/#{name}")
46
60
 
@@ -55,10 +69,10 @@ module Staticz
55
69
  end
56
70
  end
57
71
 
58
- def print(indentation)
72
+ def print(indentation, *args)
59
73
  puts "#{" " * (indentation * 3)}└─ Sub: #{name}"
60
74
  elements.each do |e|
61
- e.print(indentation + 1)
75
+ e.print(indentation + 1, *args)
62
76
  end
63
77
  end
64
78
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staticz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp Schlesinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-14 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -127,6 +127,8 @@ files:
127
127
  - lib/manifest/compilable/sass.rb
128
128
  - lib/manifest/compilable/scss.rb
129
129
  - lib/manifest/compilable/simple_file.rb
130
+ - lib/manifest/css_bundle.rb
131
+ - lib/manifest/js_bundle.rb
130
132
  - lib/manifest/manifest.rb
131
133
  - lib/manifest/sub.rb
132
134
  - lib/modules/lib_loader.rb
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
167
  - !ruby/object:Gem::Version
166
168
  version: '0'
167
169
  requirements: []
168
- rubygems_version: 3.3.3
170
+ rubygems_version: 3.3.7
169
171
  signing_key:
170
172
  specification_version: 4
171
173
  summary: Static website compiler