staticz 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 733c9126fb489a9ea9f92238d22cb507b877623ff8be13f1ade75c1d35cbfcdc
4
- data.tar.gz: 072d4bfafe6f8a5053c9c28bfc56fdaef67030bc83d2f9c1a001a2bc5987295f
3
+ metadata.gz: 9df1b15e6569279a80d29e173395fbef21e674f275ff0ab0c50804348d22e272
4
+ data.tar.gz: a16bcca4068889052fdb41d541ac5c2e9922eb33ed06b36a5dabd5ea6beae12d
5
5
  SHA512:
6
- metadata.gz: 24f1a7fd344f06ef37d77f49e459b9cdf75c330b19e4d41cc5929a09c683a024209f278da80c279efc40f5400548f7a750555b59a107800f0a330efddadb5bdd
7
- data.tar.gz: d6c40a9109eec65fddcce3342620ffee0c416298e49a29368ad2f7c1880e884e088e1696ee2e5846458dfeea395391c09bbb10d923ce65ec459b8916c70eacfb
6
+ metadata.gz: 7460d6c6052926514f7a0ab771b0954f566f1655b77194ecbb3841ba8717c38d477b0c125519e1dd25fc28978131cb665fbe8a417c2bc8c625155c2a6a2d2c79
7
+ data.tar.gz: 6b6b5585c23109518bd4130179803c0363cd9ee3ef61930e971c4eebb0075ca5eeb7333d80f8e4e7723270085a021a2eba1ee69d7c184c9bd4d6e351d9bdf75a
data/lib/helpers.rb CHANGED
@@ -24,3 +24,32 @@ end
24
24
  def javascript(path)
25
25
  "<script src=\"#{path}\"></script>"
26
26
  end
27
+
28
+ def react(*component_file_paths)
29
+ lines = [
30
+ "<script crossorigin src=\"https://unpkg.com/react@18/umd/react.development.js\"></script>",
31
+ "<script crossorigin src=\"https://unpkg.com/react-dom@18/umd/react-dom.development.js\"></script>",
32
+ component_file_paths.map do |component_file_path|
33
+ javascript(component_file_path)
34
+ end
35
+ ].flatten.join("\n")
36
+ end
37
+
38
+ def react_mount(*components)
39
+ components.map do |component|
40
+ [
41
+ "<script>",
42
+ "document.querySelectorAll('[data-component=\"#{component}\"]')",
43
+ ".forEach(domContainer => {",
44
+ "console.log('yas')",
45
+ "const root = ReactDOM.createRoot(domContainer);",
46
+ "root.render(React.createElement(#{component}));",
47
+ "});",
48
+ "</script>"
49
+ ]
50
+ end.flatten.join("\n")
51
+ end
52
+
53
+ def react_component(name, css_class = nil)
54
+ "<div data-component=\"#{name}\" class=\"#{css_class}\"></div>"
55
+ end
@@ -6,6 +6,7 @@ require_relative 'sass'
6
6
  require_relative 'scss'
7
7
  require_relative 'js'
8
8
  require_relative 'cs'
9
+ require_relative 'react'
9
10
 
10
11
  module Staticz
11
12
  class Manifest
@@ -44,6 +45,10 @@ module Staticz
44
45
  elements.push(Staticz::Cs.new(name))
45
46
  end
46
47
 
48
+ def react(name)
49
+ elements.push(Staticz::React.new(name))
50
+ end
51
+
47
52
  def build
48
53
  load "#{Dir.pwd}/manifest.rb"
49
54
 
@@ -0,0 +1,27 @@
1
+ require 'babel/transpiler'
2
+
3
+ module Staticz
4
+ class React
5
+ include Compilable
6
+
7
+ attr_reader :name
8
+
9
+ def source_file_ending = "js"
10
+
11
+ def build_file_ending = "js"
12
+
13
+ def tile_type_name = "React"
14
+
15
+ def initialize(name)
16
+ @name = name
17
+ end
18
+
19
+ def build
20
+ if exists?
21
+ engine = Babel::Transpiler.transform File.read(source_path)
22
+
23
+ File.write build_path, engine["code"]
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/manifest/sub.rb CHANGED
@@ -33,6 +33,10 @@ module Staticz
33
33
  elements.push(Staticz::Cs.new("#{@name}/#{name}"))
34
34
  end
35
35
 
36
+ def react(name, &block)
37
+ elements.push(Staticz::React.new("#{@name}/#{name}"))
38
+ end
39
+
36
40
  def build
37
41
  Dir.mkdir("build/#{name}") if !Dir.exist?("build/#{name}")
38
42
 
data/lib/server.rb CHANGED
@@ -8,6 +8,7 @@ module Staticz
8
8
 
9
9
  app = Rack::Builder.new do
10
10
  map "/" do
11
+ use Rack::Static, urls: {"/" => "build/index.html"}
11
12
  run Rack::Directory.new("build")
12
13
  end
13
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staticz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp Schlesinger
@@ -112,6 +112,7 @@ files:
112
112
  - lib/manifest/haml.rb
113
113
  - lib/manifest/js.rb
114
114
  - lib/manifest/manifest.rb
115
+ - lib/manifest/react.rb
115
116
  - lib/manifest/sass.rb
116
117
  - lib/manifest/scss.rb
117
118
  - lib/manifest/sub.rb
@@ -130,6 +131,7 @@ licenses:
130
131
  metadata:
131
132
  documentation_uri: https://github.com/OfficialPhilcomm/staticz
132
133
  source_code_uri: https://github.com/OfficialPhilcomm/staticz
134
+ changelog_uri: https://github.com/OfficialPhilcomm/staticz/blob/master/changelog.md
133
135
  post_install_message:
134
136
  rdoc_options: []
135
137
  require_paths: