class Object
Constants
- HtmlBlock
Public Instance Methods
A(**tags, &block)
click to toggle source
# File lib/tags.rb, line 35 def A(**tags, &block) create_element('a', tags, tag_helper(block)) end
B(**tags, &block)
click to toggle source
# File lib/tags.rb, line 39 def B(**tags, &block) create_element('b', tags, tag_helper(block)) end
I(**tags, &block)
click to toggle source
# File lib/tags.rb, line 95 def I(**tags, &block) create_element('i', tags, tag_helper(block)) end
P(**tags, &block)
click to toggle source
# File lib/tags.rb, line 27 def P(**tags, &block) create_element('p', tags, tag_helper(block)) end
Q(**tags, &block)
click to toggle source
# File lib/tags.rb, line 31 def Q(**tags, &block) create_element('q', tags, tag_helper(block)) end
arrow(code)
click to toggle source
# File lib/reactrb.rb, line 41 def arrow(code) "()=>(#{code})" end
body(**tags, &block)
click to toggle source
# File lib/tags.rb, line 43 def body(**tags, &block) create_element('body', tags, tag_helper(block)) end
br()
click to toggle source
# File lib/tags.rb, line 47 def br create_element('br') end
canvas(**tags, &block)
click to toggle source
# File lib/tags.rb, line 51 def canvas(**tags, &block) create_element('canvas', tags, tag_helper(block)) end
caption(**tags, &block)
click to toggle source
# File lib/tags.rb, line 55 def caption(**tags, &block) create_element('caption', tags, tag_helper(block)) end
cite(**tags, &block)
click to toggle source
# File lib/tags.rb, line 59 def cite(**tags, &block) create_element('cite', tags, tag_helper(block)) end
code(**tags, &block)
click to toggle source
# File lib/tags.rb, line 63 def code(**tags, &block) create_element('code', tags, tag_helper(block)) end
col(**tags, &block)
click to toggle source
# File lib/tags.rb, line 67 def col(**tags, &block) create_element('col', tags, tag_helper(block)) end
create_direct(name, tags = {}, body = [])
click to toggle source
# File lib/reactrb.rb, line 17 def create_direct(name, tags = {}, body = []) HtmlBlock.new(name, tags, body) end
create_element(name, tags = {}, body = [])
click to toggle source
# File lib/reactrb.rb, line 13 def create_element(name, tags = {}, body = []) HtmlBlock.new(name.inspect, tags, body) end
create_function(name, body, head: '')
click to toggle source
# File lib/reactrb.rb, line 53 def create_function(name, body, head: '') "function #{name}(props){#{head};return #{body}}" end
css(file)
click to toggle source
# File lib/reactrb.rb, line 49 def css(file) "<link rel=\"stylesheet\" href=\"#{file}\">" end
del(**tags, &block)
click to toggle source
# File lib/tags.rb, line 71 def del(**tags, &block) create_element('del', tags, tag_helper(block)) end
div(**tags, &block)
click to toggle source
# File lib/tags.rb, line 75 def div(**tags, &block) create_element('div', tags, tag_helper(block)) end
embed(**tags, &block)
click to toggle source
# File lib/tags.rb, line 79 def embed(**tags, &block) create_element('embed', tags, tag_helper(block)) end
form(**tags, &block)
click to toggle source
# File lib/tags.rb, line 87 def form(**tags, &block) create_element('form', tags, tag_helper(block)) end
func(code)
click to toggle source
# File lib/reactrb.rb, line 45 def func(code) "function (){#{code}}" end
h1(**tags, &block)
click to toggle source
# File lib/tags.rb, line 3 def h1(**tags, &block) create_element('h1', tags, tag_helper(block)) end
h2(**tags, &block)
click to toggle source
# File lib/tags.rb, line 7 def h2(**tags, &block) create_element('h2', tags, tag_helper(block)) end
h3(**tags, &block)
click to toggle source
# File lib/tags.rb, line 11 def h3(**tags, &block) create_element('h3', tags, tag_helper(block)) end
h4(**tags, &block)
click to toggle source
# File lib/tags.rb, line 15 def h4(**tags, &block) create_element('h4', tags, tag_helper(block)) end
h5(**tags, &block)
click to toggle source
# File lib/tags.rb, line 19 def h5(**tags, &block) create_element('h5', tags, tag_helper(block)) end
h6(**tags, &block)
click to toggle source
# File lib/tags.rb, line 23 def h6(**tags, &block) create_element('h6', tags, tag_helper(block)) end
header(**tags, &block)
click to toggle source
# File lib/tags.rb, line 91 def header(**tags, &block) create_element('header', tags, tag_helper(block)) end
img(**tags, &block)
click to toggle source
# File lib/tags.rb, line 99 def img(**tags, &block) create_element('img', tags, tag_helper(block)) end
input(**tags, &block)
click to toggle source
# File lib/tags.rb, line 103 def input(**tags, &block) create_element('input', tags, tag_helper(block)) end
link(**tags, &block)
click to toggle source
# File lib/tags.rb, line 107 def link(**tags, &block) create_element('link', tags, tag_helper(block)) end
meta(**tags, &block)
click to toggle source
# File lib/tags.rb, line 111 def meta(**tags, &block) create_element('meta', tags, tag_helper(block)) end
render_react(bodies, entry: 'main', head: '', css: [])
click to toggle source
# File lib/reactrb.rb, line 57 def render_react(bodies, entry: 'main', head: '', css: []) css = [css] unless css.is_a?(Array) %(<!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> 'use strict';const e=React.createElement;const {useState}=React;#{bodies.join(';')};ReactDOM.render(React.createElement(#{entry}, null, null), document.getElementById('root'));</script></body></html>) end
ruby(code)
click to toggle source
# File lib/reactrb.rb, line 29 def ruby(code) Ruby2JS.convert(code).to_s end
str(string)
click to toggle source
# File lib/reactrb.rb, line 33 def str(string) "\"#{string}\"" end
tag_helper(block)
click to toggle source
# File lib/reactrb.rb, line 21 def tag_helper(block) texts = block.call texts = [texts] unless texts.is_a?(Array) texts end
tempstr(string)
click to toggle source
# File lib/reactrb.rb, line 37 def tempstr(string) "`#{string}`" end