purereact.rb 0.0.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/reactrb.rb +61 -0
  3. data/lib/tags.rb +117 -0
  4. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: edf615a0c145689ffda0e04d1fc322b55d7a86e79a100cb8f1b18e0cca8f0c3e
4
+ data.tar.gz: 3f5b55755855d92138d5e051d0c035e6883d7f068008b37441299cc84b1fbca8
5
+ SHA512:
6
+ metadata.gz: 0c0bdc0d1643280938e5fe5c4021759a86f1e03aec377c68763a9efdf3ea7fab8f4c256fd9612038e7eea016e84b1dc41b5dc618cb8ea9c92908aa9b6fd405ee
7
+ data.tar.gz: 91b57905aaa767993efc8bbd1b3abbb69f7ba937e65bfea9a96a2a8ffc5fa6f1f444a5cb6f6d4d3edb66010652d7abc5c26b5ea707d169779f8a3c0fa7a4a2a4
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby2js'
4
+
5
+ HtmlBlock = Struct.new(:name, :tags, :texts) do
6
+ def to_s
7
+ l = tags.map { |k, v| "#{k}: #{v}" }.join(',')
8
+ q = texts.map(&:to_s).join(',')
9
+ %(e(#{name},{#{l}},#{q}))
10
+ end
11
+ end
12
+
13
+ def create_element(name, tags = {}, body = [])
14
+ HtmlBlock.new(name.inspect, tags, body)
15
+ end
16
+
17
+ def create_direct(name, tags = {}, body = [])
18
+ HtmlBlock.new(name, tags, body)
19
+ end
20
+
21
+ def tag_helper(block)
22
+ texts = block.call
23
+ texts = [texts] unless texts.is_a?(Array)
24
+ texts
25
+ end
26
+
27
+ require_relative './tags'
28
+
29
+ def ruby(code)
30
+ Ruby2JS.convert(code).to_s
31
+ end
32
+
33
+ def str(string)
34
+ "\"#{string}\""
35
+ end
36
+
37
+ def tempstr(string)
38
+ "`#{string}`"
39
+ end
40
+
41
+ def arrow(code)
42
+ "()=>(#{code})"
43
+ end
44
+
45
+ def func(code)
46
+ "function (){#{code}}"
47
+ end
48
+
49
+ def css(file)
50
+ "<link rel=\"stylesheet\" href=\"#{file}\">"
51
+ end
52
+
53
+ def create_function(name, body, head: '')
54
+ "function #{name}(props){#{head};return #{body}}"
55
+ end
56
+
57
+ def render_react(bodies, entry: 'main', head: '', css: [])
58
+ css = [css] unless css.is_a?(Array)
59
+ %(<!DOCTYPE html><html><head><script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script><script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script><script>#{head}</script>#{css.join}</head><body><div id="root"></div><script>
60
+ 'use strict';const e=React.createElement;const {useState}=React;#{bodies.join(';')};ReactDOM.render(React.createElement(#{entry}, null, null), document.getElementById('root'));</script></body></html>)
61
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ def h1(**tags, &block)
4
+ create_element('h1', tags, tag_helper(block))
5
+ end
6
+
7
+ def h2(**tags, &block)
8
+ create_element('h2', tags, tag_helper(block))
9
+ end
10
+
11
+ def h3(**tags, &block)
12
+ create_element('h3', tags, tag_helper(block))
13
+ end
14
+
15
+ def h4(**tags, &block)
16
+ create_element('h4', tags, tag_helper(block))
17
+ end
18
+
19
+ def h5(**tags, &block)
20
+ create_element('h5', tags, tag_helper(block))
21
+ end
22
+
23
+ def h6(**tags, &block)
24
+ create_element('h6', tags, tag_helper(block))
25
+ end
26
+
27
+ def P(**tags, &block)
28
+ create_element('p', tags, tag_helper(block))
29
+ end
30
+
31
+ def Q(**tags, &block)
32
+ create_element('q', tags, tag_helper(block))
33
+ end
34
+
35
+ def A(**tags, &block)
36
+ create_element('a', tags, tag_helper(block))
37
+ end
38
+
39
+ def B(**tags, &block)
40
+ create_element('b', tags, tag_helper(block))
41
+ end
42
+
43
+ def body(**tags, &block)
44
+ create_element('body', tags, tag_helper(block))
45
+ end
46
+
47
+ def br
48
+ create_element('br')
49
+ end
50
+
51
+ def canvas(**tags, &block)
52
+ create_element('canvas', tags, tag_helper(block))
53
+ end
54
+
55
+ def caption(**tags, &block)
56
+ create_element('caption', tags, tag_helper(block))
57
+ end
58
+
59
+ def cite(**tags, &block)
60
+ create_element('cite', tags, tag_helper(block))
61
+ end
62
+
63
+ def code(**tags, &block)
64
+ create_element('code', tags, tag_helper(block))
65
+ end
66
+
67
+ def col(**tags, &block)
68
+ create_element('col', tags, tag_helper(block))
69
+ end
70
+
71
+ def del(**tags, &block)
72
+ create_element('del', tags, tag_helper(block))
73
+ end
74
+
75
+ def div(**tags, &block)
76
+ create_element('div', tags, tag_helper(block))
77
+ end
78
+
79
+ def embed(**tags, &block)
80
+ create_element('embed', tags, tag_helper(block))
81
+ end
82
+
83
+ def footer(**tags, &block)
84
+ create_element('footer', tags, tag_helper(block))
85
+ end
86
+
87
+ def form(**tags, &block)
88
+ create_element('form', tags, tag_helper(block))
89
+ end
90
+
91
+ def header(**tags, &block)
92
+ create_element('header', tags, tag_helper(block))
93
+ end
94
+
95
+ def I(**tags, &block)
96
+ create_element('i', tags, tag_helper(block))
97
+ end
98
+
99
+ def img(**tags, &block)
100
+ create_element('img', tags, tag_helper(block))
101
+ end
102
+
103
+ def input(**tags, &block)
104
+ create_element('input', tags, tag_helper(block))
105
+ end
106
+
107
+ def link(**tags, &block)
108
+ create_element('link', tags, tag_helper(block))
109
+ end
110
+
111
+ def meta(**tags, &block)
112
+ create_element('meta', tags, tag_helper(block))
113
+ end
114
+
115
+ def button(**tags, &block)
116
+ create_element('button', tags, tag_helper(block))
117
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: purereact.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - SnowballSH
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-12-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple hello world gem
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/reactrb.rb
20
+ - lib/tags.rb
21
+ homepage: https://github.com/SnowballSH/React.rb
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.1.4
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A simple hello world gem
44
+ test_files: []