symprise-wise 0.1.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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +5 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/lib/wise/processor/form.rb +80 -0
- data/lib/wise/processor/table.rb +42 -0
- data/lib/wise/processor.rb +19 -0
- data/lib/wise/template_handler.rb +14 -0
- data/lib/wise/version.rb +5 -0
- data/lib/wise.rb +10 -0
- data/sig/wise.rbs +4 -0
- metadata +55 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2d03eaf5d06199abb78d40be9a89c3463a402d1b142273ed15e49f3693598299
|
|
4
|
+
data.tar.gz: 4c0fc168aea1ebd2378822dd136b0965621b90db453f699300abfe9a932aa7b7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '08a7ff77a158a2e939281949c860d3a5d4563b599cf96d90db8594c417cd590ce18621eb94ce2a29053f7d0d035417454a59b3882061188fc8976dc6a2429ea7'
|
|
7
|
+
data.tar.gz: 8d826592666a21d8e2b090ff1b1df06350ea5d6e5458c9c9516c12076140cc93e2f2d409bd657fd7264a5c237ee42def4b154cc30dc1ae0ed97e6dc74bfde8dd
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Wise
|
|
2
|
+
|
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
|
4
|
+
|
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wise`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
10
|
+
|
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wise.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module Wise
|
|
2
|
+
module Processor
|
|
3
|
+
class Form
|
|
4
|
+
class << self
|
|
5
|
+
def generate(prefix, data)
|
|
6
|
+
"<%= form_with(model: input) do |form| %>\n" +
|
|
7
|
+
message(data['model'], data['name'], ' ') +
|
|
8
|
+
fieldset(' ', data['name'], data['fields']) +
|
|
9
|
+
submit(' ') +
|
|
10
|
+
"<% end %>\n"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def add(prefix, text)
|
|
16
|
+
text.split("\n").map { |line| prefix + line }.join("\n") + "\n"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def message(model, name, prefix)
|
|
20
|
+
add(prefix,
|
|
21
|
+
<<~HTML
|
|
22
|
+
<% if #{model}.errors.any? %>
|
|
23
|
+
<div style="color: red">
|
|
24
|
+
<h2><%= pluralize(input.errors.count, "error") %> prohibited this #{name} from being saved:</h2>
|
|
25
|
+
<ul>
|
|
26
|
+
<% #{model}.errors.each do |error| %>
|
|
27
|
+
<li><%= error.full_message %></li>
|
|
28
|
+
<% end %>
|
|
29
|
+
</ul>
|
|
30
|
+
</div>
|
|
31
|
+
<% end %>
|
|
32
|
+
HTML
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def fieldset(prefix, name, fields)
|
|
37
|
+
add(prefix,
|
|
38
|
+
"<fieldset>\n" +
|
|
39
|
+
" <legend>#{name} Details</legend>\n" +
|
|
40
|
+
fields.map do |key, value|
|
|
41
|
+
case value['type']
|
|
42
|
+
when 'string'; string_field(' ', key, value)
|
|
43
|
+
when 'text'; text_field(' ', key, value)
|
|
44
|
+
end
|
|
45
|
+
end.join +
|
|
46
|
+
"</fieldset>\n"
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def text_field(prefix, model, details)
|
|
51
|
+
add(prefix,
|
|
52
|
+
"<div>\n" +
|
|
53
|
+
" <%= form.label '#{details['label']}' %>\n" +
|
|
54
|
+
" <%= form.textarea :#{model}, rows: #{details['rows']} %>\n" +
|
|
55
|
+
"</div>\n"
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def string_field(prefix, model, details)
|
|
60
|
+
add(prefix,
|
|
61
|
+
"<div>\n" +
|
|
62
|
+
" <%= form.label '#{details['label']}' %>\n" +
|
|
63
|
+
" <%= form.text_field :#{model} %>\n" +
|
|
64
|
+
"</div>\n"
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def submit(prefix)
|
|
69
|
+
add(prefix,
|
|
70
|
+
<<~HTML
|
|
71
|
+
<div>
|
|
72
|
+
<%= form.submit %>
|
|
73
|
+
</div>
|
|
74
|
+
HTML
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Wise
|
|
2
|
+
module Processor
|
|
3
|
+
class Table
|
|
4
|
+
class << self
|
|
5
|
+
def generate(prefix, data)
|
|
6
|
+
"#{prefix}<table>\n" +
|
|
7
|
+
thead(' ', data['columns'].values) +
|
|
8
|
+
tbody(' ', data['source'], data['columns'].keys) +
|
|
9
|
+
"#{prefix}</table>\n"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def thead(prefix, headings)
|
|
15
|
+
"#{prefix}<thead>\n" +
|
|
16
|
+
" #{prefix}<tr>\n" +
|
|
17
|
+
headings.map do |h|
|
|
18
|
+
" #{prefix}<th>#{h}</th>\n"
|
|
19
|
+
end.join +
|
|
20
|
+
" #{prefix}</tr>\n" +
|
|
21
|
+
"#{prefix}</thead>\n"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def tbody(prefix, source, values)
|
|
25
|
+
"#{prefix}<tbody>\n" +
|
|
26
|
+
" #{prefix}<% #{source}.each do |item| %>\n" +
|
|
27
|
+
" #{prefix}<tr>\n" +
|
|
28
|
+
values.map do |v|
|
|
29
|
+
if v == 'actions'
|
|
30
|
+
" #{prefix}<td><%= render partial: 'blocks/actions', locals: { instance: item } %></td>\n"
|
|
31
|
+
else
|
|
32
|
+
" #{prefix}<td><%= item.#{v} %></td>\n"
|
|
33
|
+
end
|
|
34
|
+
end.join +
|
|
35
|
+
" #{prefix}</tr>\n" +
|
|
36
|
+
" #{prefix}<% end %>\n" +
|
|
37
|
+
"#{prefix}</tbody>\n"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require_relative 'processor/form'
|
|
3
|
+
require_relative 'processor/table'
|
|
4
|
+
|
|
5
|
+
module Wise
|
|
6
|
+
module Processor
|
|
7
|
+
class << self
|
|
8
|
+
def translate(yaml)
|
|
9
|
+
data = YAML.load(yaml)
|
|
10
|
+
case
|
|
11
|
+
when data['table']
|
|
12
|
+
Wise::Processor::Table.generate('', data['table'])
|
|
13
|
+
when data['form']
|
|
14
|
+
Wise::Processor::Form.generate('', data['form'])
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Wise
|
|
2
|
+
class TemplateHandler
|
|
3
|
+
attr_reader :erb_handler
|
|
4
|
+
|
|
5
|
+
def initialize(erb_handler)
|
|
6
|
+
@erb_handler = erb_handler
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(template, source)
|
|
10
|
+
# Return the processed source for ERB to handle
|
|
11
|
+
erb_handler.call(template, Wise::Processor::translate(source))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/wise/version.rb
ADDED
data/lib/wise.rb
ADDED
data/sig/wise.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: symprise-wise
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rafael Azevedo
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: 'WISE: Web Information Systems Engine.'
|
|
13
|
+
email:
|
|
14
|
+
- rafael.peixoto.de.azevedo@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- ".rspec"
|
|
20
|
+
- ".rubocop.yml"
|
|
21
|
+
- CHANGELOG.md
|
|
22
|
+
- README.md
|
|
23
|
+
- Rakefile
|
|
24
|
+
- lib/wise.rb
|
|
25
|
+
- lib/wise/processor.rb
|
|
26
|
+
- lib/wise/processor/form.rb
|
|
27
|
+
- lib/wise/processor/table.rb
|
|
28
|
+
- lib/wise/template_handler.rb
|
|
29
|
+
- lib/wise/version.rb
|
|
30
|
+
- sig/wise.rbs
|
|
31
|
+
homepage: https://github.com/RPAzevedo/Wise
|
|
32
|
+
licenses: []
|
|
33
|
+
metadata:
|
|
34
|
+
allowed_push_host: https://rubygems.org
|
|
35
|
+
homepage_uri: https://github.com/RPAzevedo/Wise
|
|
36
|
+
source_code_uri: https://github.com/RPAzevedo/Wise
|
|
37
|
+
changelog_uri: https://github.com/RPAzevedo/Wise/blob/main/CHANGELOG.md
|
|
38
|
+
rdoc_options: []
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 3.1.0
|
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '0'
|
|
51
|
+
requirements: []
|
|
52
|
+
rubygems_version: 3.6.7
|
|
53
|
+
specification_version: 4
|
|
54
|
+
summary: 'Symprise WISE: Web Information Systems Engine.'
|
|
55
|
+
test_files: []
|