Xomponent 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c59fc50da9a7a9168b7cb30fc1b6b7646699c6f0639c19ec4606209167cadd05
4
+ data.tar.gz: 7b2707c7132a5beeb1538565f9e0584930794a71b02cbd1706060e17923ad8cc
5
+ SHA512:
6
+ metadata.gz: e3412da105e271392edb7af6a68b94822c5997d45ffdc7abab0f8c3bcb33f8fad8a90e630a4dd68d5e5d8b0bd828bfbd5eb54c1d73ba70c5bf35b9ade04c4a7c
7
+ data.tar.gz: 4c31de324f5e10fb377fdd024872a1b94ce075ade6b71b99db9b4189712e81b818aa7bed2e3138f368edcb77d1e63ff71b1fff78dec19600b8340a004fdce788
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in Xomponent.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ Xomponent (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ Xomponent!
16
+ bundler (~> 1.16)
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 myun2
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Xomponent
2
+
3
+ **Ruby based React rendering** system.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'Xomponent'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install Xomponent
20
+
21
+ ## Usage
22
+
23
+ Write follow code example name 'app.rb'
24
+
25
+ ```rb
26
+ require 'Xomponent/server'
27
+ require 'Xomponent/React'
28
+
29
+ class Hello
30
+ def render
31
+ <<-EOS
32
+ <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
33
+ <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
34
+ <div id="app"/>
35
+ <script>#{Xomponent::React.render_to_app(Xomponent::React.new('div', '"Hello Xomponent."'))}</script>
36
+ EOS
37
+ end
38
+ end
39
+
40
+ puts 'Run Xomponent server at 2998'
41
+ Xomponent::Server.new(2998, Hello.new)
42
+ ```
43
+
44
+ And execute `ruby app.rb` and access to http://localhost:2998 in your browser.
45
+
46
+ More example code is https://github.com/myun2/Xomponent/blob/master/examples/app.rb
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Xomponent.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/Xomponent.gemspec ADDED
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "Xomponent/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Xomponent"
8
+ spec.version = Xomponent::VERSION
9
+ spec.authors = ["myun2"]
10
+ spec.email = ["myun2@mbr.nifty.com"]
11
+
12
+ spec.summary = %q{Ruby based react rendering system}
13
+ spec.description = %q{Ruby based react rendering system}
14
+ spec.homepage = "https://github.com/myun2/Xomponent"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Xomponent"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/examples/app.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'Xomponent/server'
2
+ require 'Xomponent/Document'
3
+ require 'Xomponent/Style'
4
+ require 'Xomponent/React'
5
+
6
+ class Example
7
+ class Style < Xomponent::Style
8
+ def initialize
9
+ super
10
+ reset!
11
+ add :header, {
12
+ "background-color" => "#1c1b1f",
13
+ "color" => "#fff", "font-size" => "2em"
14
+ }
15
+ add :main, margin: "4px"
16
+ end
17
+ end
18
+
19
+ class Document < Xomponent::Document
20
+ def initialize
21
+ super
22
+ self.title_content = 'Xomponent'
23
+ self.style_content = Example::Style.new.render
24
+ self.head_inner =
25
+ '<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>' +
26
+ '<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>'
27
+ self.script_content = Xomponent::React.render_to_id(app)
28
+ end
29
+
30
+ def app
31
+ content = header.render + ',' + main.render
32
+ Xomponent::React.new(:div, content, className: 'container')
33
+ end
34
+
35
+ def header
36
+ Xomponent::React.new('header', '"Xomponent"')
37
+ end
38
+
39
+ def main
40
+ Xomponent::React.new('main', '"Hello."')
41
+ end
42
+ end
43
+ end
44
+
45
+ puts 'Run Xomponent server at 2998'
46
+ Xomponent::Server.new(2998, Example::Document.new)
data/examples/hello.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'Xomponent/server'
2
+ require 'Xomponent/React'
3
+
4
+ class Hello
5
+ def render
6
+ <<-EOS
7
+ <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
8
+ <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
9
+ <div id="app"/>
10
+ <script>#{Xomponent::React.render_to_app(Xomponent::React.new('div', '"Hello Xomponent."'))}</script>
11
+ EOS
12
+ end
13
+ end
14
+
15
+ puts 'Run Xomponent server at 2998'
16
+ Xomponent::Server.new(2998, Hello.new)
data/exe/Xomponent ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "Xomponent/version"
4
+
5
+ if ARGV[0] == 'serv'
6
+ require 'Xomponent/serv'
7
+ puts 'Run Xomponent server at 2998'
8
+ Xomponent::Serv.new(2998)
9
+ end
data/lib/Xomponent.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "Xomponent/version"
2
+ module Xomponent
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'Xomponent/Element'
2
+
3
+ module Xomponent
4
+ class Document
5
+ attr_writer :title_content, :head_inner, :style_content, :script_content
6
+ DOCTYPE = '<!DOCTYPE html>'
7
+
8
+ def method_missing(name, **args, &block)
9
+ Element.new(name, args, &block)
10
+ end
11
+
12
+ def head_content
13
+ title { @title_content } +
14
+ style { @style_content } + (@head_inner || '')
15
+ end
16
+
17
+ def render
18
+ DOCTYPE + html {
19
+ head { head_content } +
20
+ body {
21
+ div(id: :app) +
22
+ script { @script_content }
23
+ }
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Xomponent
2
+ class Element
3
+ def self.new(name, **args)
4
+ attrs = args.map do |name, value|
5
+ " #{name}=\"#{value}\""
6
+ end.join()
7
+
8
+ "<#{name}#{attrs}>#{yield if block_given?}</#{name}>"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ require 'json'
2
+
3
+ module Xomponent
4
+ class React
5
+ attr_accessor :tag, :body, :params
6
+
7
+ def initialize(tag = :div, body = 'null', **params)
8
+ @tag = tag
9
+ @body = body
10
+ @params = params
11
+ end
12
+
13
+ def render
14
+ "React.createElement('#{tag}',#{JSON.dump(params)},#{body})"
15
+ end
16
+
17
+ def self.render(component, target)
18
+ "ReactDOM.render(#{component.render},#{target});"
19
+ end
20
+
21
+ def self.render_to_id(component, id = 'app')
22
+ "ReactDOM.render(#{component.render},document.getElementById('#{id}'));"
23
+ end
24
+
25
+ def self.render_to_app(component, id = 'app')
26
+ "ReactDOM.render(#{component.render},document.getElementById('#{id}'));"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ module Xomponent
2
+ class Style
3
+ attr_writer :s
4
+ def initialize
5
+ @s = ''
6
+ end
7
+
8
+ def reset!
9
+ @s = "body{margin:0;font-family:sans-serif}"
10
+ end
11
+
12
+ def add(selector, styles)
13
+ styles_str = styles.map do |name, value|
14
+ "#{name}:#{value}"
15
+ end.join(';')
16
+
17
+ @s += "#{selector}{#{styles_str}}"
18
+ end
19
+
20
+ def render
21
+ @s
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'socket'
2
+
3
+ module Xomponent
4
+ class Server
5
+ def initialize(port, content)
6
+ server = TCPServer.new port.to_i
7
+ loop do
8
+ client = server.accept
9
+ headers = []
10
+ while header = client.gets
11
+ break if header.chomp.empty?
12
+ headers << header.chomp
13
+ end
14
+ p headers
15
+
16
+ client.puts "HTTP/1.0 200 OK"
17
+ client.puts "Content-Type: text/html"
18
+ client.puts
19
+ client.puts content.render
20
+ client.close
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Xomponent
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Xomponent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - myun2
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Ruby based react rendering system
42
+ email:
43
+ - myun2@mbr.nifty.com
44
+ executables:
45
+ - Xomponent
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - Xomponent.gemspec
56
+ - bin/console
57
+ - bin/setup
58
+ - examples/app.rb
59
+ - examples/hello.rb
60
+ - exe/Xomponent
61
+ - lib/Xomponent.rb
62
+ - lib/Xomponent/Document.rb
63
+ - lib/Xomponent/Element.rb
64
+ - lib/Xomponent/React.rb
65
+ - lib/Xomponent/Style.rb
66
+ - lib/Xomponent/server.rb
67
+ - lib/Xomponent/version.rb
68
+ homepage: https://github.com/myun2/Xomponent
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.7.6
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Ruby based react rendering system
92
+ test_files: []