ant-design-rails 0.0.1 → 0.1.0

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: 2439845d459b04b101663a12394c4b0478e97c5d5d3d173fbcd9611a73b6b682
4
- data.tar.gz: 01dc6b29ab80d667af27a245e799b599af8f2bb2bd8cf2a02b72046a0e24ffab
3
+ metadata.gz: '0018bf821e5678e2347ffea2c095c2bd3c7d96655c15716d4d3158a815692800'
4
+ data.tar.gz: ade8e43bf58c34370f1eb69f57eafc8385d09e4669eb4c192b0de0d4958ef218
5
5
  SHA512:
6
- metadata.gz: 5f2bc22a19971e08cfaaded469537e6ee0a5deb4f42559634170d3050e32ee370f750e0fa91fd984453acd83c210cde8aa027da33861832b1714a826a3200301
7
- data.tar.gz: f7fd108207d3efbb45df905d6fdffb756f89950e8a3e41a6194a105189eaf6056e40ce45c4039f33a6883f3e49863566862e4a43e8292baddb7dc11c307227fc
6
+ metadata.gz: bf4b454b968d7177816d64b55fc90b6e0aa5af045fd436c97678a10e834293b62b8a8a82035d259cbd3daac460e7448b794a1ad070a67c6a0f9529d9a4253f62
7
+ data.tar.gz: ed2fe2b351c257cb814b457d5f8cd09f6a338bf75ad3c4e64079195c6609e86fe6e81c735679741c44cd31344291e3cc982d529a7d18bfeaea54bb93b8d1c396
data/Gemfile.lock CHANGED
@@ -1,12 +1,66 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ant-design-rails (0.0.1)
4
+ ant-design-rails (0.1.0)
5
+ execjs (~> 2.8, >= 2.8.1)
6
+ railties (~> 7.0.4, >= 7.0.4.2)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
11
+ actionpack (7.0.4.2)
12
+ actionview (= 7.0.4.2)
13
+ activesupport (= 7.0.4.2)
14
+ rack (~> 2.0, >= 2.2.0)
15
+ rack-test (>= 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
+ actionview (7.0.4.2)
19
+ activesupport (= 7.0.4.2)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
+ activesupport (7.0.4.2)
25
+ concurrent-ruby (~> 1.0, >= 1.0.2)
26
+ i18n (>= 1.6, < 2)
27
+ minitest (>= 5.1)
28
+ tzinfo (~> 2.0)
29
+ builder (3.2.4)
30
+ concurrent-ruby (1.2.0)
31
+ crass (1.0.6)
32
+ erubi (1.12.0)
33
+ execjs (2.8.1)
34
+ i18n (1.12.0)
35
+ concurrent-ruby (~> 1.0)
36
+ loofah (2.19.1)
37
+ crass (~> 1.0.2)
38
+ nokogiri (>= 1.5.9)
39
+ method_source (1.0.0)
40
+ minitest (5.17.0)
41
+ nokogiri (1.14.0-arm64-darwin)
42
+ racc (~> 1.4)
43
+ racc (1.6.2)
44
+ rack (2.2.6.2)
45
+ rack-test (2.0.2)
46
+ rack (>= 1.3)
47
+ rails-dom-testing (2.0.3)
48
+ activesupport (>= 4.2.0)
49
+ nokogiri (>= 1.6)
50
+ rails-html-sanitizer (1.5.0)
51
+ loofah (~> 2.19, >= 2.19.1)
52
+ railties (7.0.4.2)
53
+ actionpack (= 7.0.4.2)
54
+ activesupport (= 7.0.4.2)
55
+ method_source
56
+ rake (>= 12.2)
57
+ thor (~> 1.0)
58
+ zeitwerk (~> 2.5)
9
59
  rake (13.0.6)
60
+ thor (1.2.1)
61
+ tzinfo (2.0.5)
62
+ concurrent-ruby (~> 1.0)
63
+ zeitwerk (2.6.6)
10
64
 
11
65
  PLATFORMS
12
66
  arm64-darwin-21
@@ -26,10 +26,6 @@ Gem::Specification.new do |spec|
26
26
  (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
27
27
  end
28
28
  end
29
-
30
- # Uncomment to register a new dependency of your gem
31
- # spec.add_dependency "example-gem", "~> 1.0"
32
-
33
- # For more information and examples about making a new gem, check out our
34
- # guide at: https://bundler.io/guides/creating_gem.html
29
+ spec.add_dependency "railties", '~> 7.0.4', '>= 7.0.4.2'
30
+ spec.add_dependency "execjs", '~> 2.8', '>= 2.8.1'
35
31
  end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'execjs'
5
+
6
+ module Ant
7
+ module Design
8
+ module Rails
9
+ class Routes
10
+ include Enumerable
11
+ extend Forwardable
12
+ def_delegators :@result_array, :each, :<<
13
+
14
+ def initialize(routes_ts_path)
15
+ @body = File.read(routes_ts_path)
16
+ @result_array = ExecJS.eval(@body[start_of_json..end_of_json])
17
+ end
18
+
19
+ def start_of_json
20
+ @body.index('[')
21
+ end
22
+
23
+ def end_of_json
24
+ @body.rindex(']')
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ module ActionDispatch::Routing
32
+ class Mapper
33
+ def antd_pages(routes_ts_path)
34
+ antd_routes_reader = Ant::Design::Rails::Routes.new(routes_ts_path)
35
+ antd_api = {}
36
+ antd_routes_reader.each do |antd_route|
37
+ next if antd_route["path"] == "*"
38
+ antd_route_parse(antd_api, antd_route)
39
+ end
40
+ scope :api do
41
+ antd_api.each_value.map(&:call)
42
+ end
43
+ end
44
+
45
+ def antd_route_parse(antd_api, antd_route)
46
+ if antd_route["path"] == "/" && antd_route["redirect"].present?
47
+ root to: redirect(antd_route["redirect"])
48
+ elsif (antd_route["path"][0..4]) == "/api/" && (antd_route["path"][5..-1]).present?
49
+ antd_route_without_api = antd_route["path"][5..-1]
50
+ antd_api[antd_route_without_api] = antd_lambda(antd_route_without_api, antd_route)
51
+ end
52
+ # Recurse
53
+ antd_route['routes']&.each do |sub_antd_route|
54
+ antd_route_parse(antd_api, sub_antd_route)
55
+ end
56
+ end
57
+
58
+ def antd_lambda(antd_route_without_api, antd_route)
59
+ antd_route_parts = antd_route_without_api.split("/")
60
+ if antd_route["redirect"].present?
61
+ lambda { get antd_route_without_api, to: redirect(antd_route["redirect"]) }
62
+ elsif antd_route_parts.length == 1
63
+ lambda { get antd_route_without_api => "#{antd_route_parts.first.underscore}#index" }
64
+ else
65
+ lambda { get antd_route_without_api => "#{antd_route_parts.first.underscore}##{antd_route_parts[1..-1].join("_").underscore}" }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -3,7 +3,7 @@
3
3
  module Ant
4
4
  module Design
5
5
  module Rails
6
- VERSION = "0.0.1".freeze
6
+ VERSION = "0.1.0".freeze
7
7
  end
8
8
  end
9
9
  end
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rails/version"
4
+ require_relative "rails/routes"
4
5
 
6
+ # Todo
5
7
  module Ant
6
8
  module Design
7
9
  module Rails
8
10
  class Error < StandardError; end
9
11
 
10
12
  def self.hi(language)
11
- puts "Hi #{language}"
13
+ puts "Todo: Hi #{language}"
12
14
  end
13
15
  end
14
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ant-design-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minqi Pan
@@ -9,7 +9,47 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2023-01-27 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.4
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.4.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 7.0.4
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.4.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: execjs
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.8'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.8.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.8'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.8.1
13
53
  description: 'Ant Design on Rails: pairing world''s best backend framework with the
14
54
  best frontend framework, without wrapping everything in API!'
15
55
  email: pmq2001@gmail.com
@@ -20,9 +60,10 @@ files:
20
60
  - Gemfile
21
61
  - Gemfile.lock
22
62
  - Rakefile
63
+ - ant-design-rails.gemspec
23
64
  - exe/antd
24
- - hola.gemspec
25
65
  - lib/ant/design/rails.rb
66
+ - lib/ant/design/rails/routes.rb
26
67
  - lib/ant/design/rails/version.rb
27
68
  homepage: https://github.com/pmq20/ant-design-rails
28
69
  licenses: