wfc 2.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/CHANGELOG.md +5 -0
- data/README.md +206 -0
- data/Rakefile +4 -0
- data/lib/web_forms.rb +2666 -0
- data/lib/wfc/version.rb +5 -0
- data/lib/wfc.rb +4 -0
- data/sig/wfc.rbs +4 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b9c9494460645247374def67bc05bd7c50f77ef72d7b0def2223a1b242880783
|
|
4
|
+
data.tar.gz: 619c0999e742305914bcc70d1223c5878e5a293cb4381dad9819a9c756a03eec
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 74b895aea1e783332fca9709ea72564253ea40f95891129478c21e2c4bd089b834bf4188d7f51c86f4cd1231cb573a59241dd128b4eb011cd55a29a3b0eb3dec
|
|
7
|
+
data.tar.gz: a149febdc30e90b6d6a6c9dc29a2d481414fc63a82a0d21f04e3d4911d9e4d31c328a68dec1f3f123a3b368851a1f1fab60470b4793759f524b0ecb67444b5f4
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# WebForms Core (WFC)
|
|
2
|
+
|
|
3
|
+
WebForms Core (WFC) is a server-driven web interface technology for Ruby.
|
|
4
|
+
|
|
5
|
+
It provides a `WebForms` class for generating server-side commands that manipulate HTML elements and interact with the WebFormsJS runtime in the browser.
|
|
6
|
+
|
|
7
|
+
WebForms Core is developed by [Elanat](https://elanat.net).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Install the gem:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
gem install wfc
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or add it to your application's Gemfile:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem "wfc"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then run:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bundle install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Require the gem:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
require "wfc"
|
|
35
|
+
|
|
36
|
+
include WebFormsCore
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You can then create a `WebForms` instance and generate server-side commands:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
form = WebForms.new
|
|
43
|
+
|
|
44
|
+
form.set_text("message", "Hello from WebForms Core!")
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The generated commands are intended to be executed by the WebFormsJS runtime in the browser.
|
|
48
|
+
|
|
49
|
+
## How to Work with WebForms Core in Ruby (Sinatra Framework)
|
|
50
|
+
|
|
51
|
+
WebForms Core can be used with the [Sinatra](https://sinatrarb.com/) framework.
|
|
52
|
+
|
|
53
|
+
After installing the `wfc` gem, require it in your Sinatra application:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
require 'sinatra'
|
|
57
|
+
require 'wfc'
|
|
58
|
+
|
|
59
|
+
include WebFormsCore
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The following example demonstrates a form that sends data to the server. The server then uses the `WebForms` class to generate commands that modify the page.
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
require 'sinatra'
|
|
66
|
+
require 'wfc'
|
|
67
|
+
|
|
68
|
+
include WebFormsCore
|
|
69
|
+
|
|
70
|
+
get '/' do
|
|
71
|
+
erb :view
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
post '/' do
|
|
75
|
+
if params['btn_SetBodyValue']
|
|
76
|
+
name = params['txt_Name']
|
|
77
|
+
background_color = params['txt_BackgroundColor']
|
|
78
|
+
font_size = params['txt_FontSize'].to_i
|
|
79
|
+
|
|
80
|
+
form = WebForms.new
|
|
81
|
+
|
|
82
|
+
form.set_font_size(InputPlace.tag('form'), font_size)
|
|
83
|
+
form.set_background_color(InputPlace.tag('form'), background_color)
|
|
84
|
+
form.set_disabled(InputPlace.name('btn_SetBodyValue'), true)
|
|
85
|
+
|
|
86
|
+
form.add_tag(InputPlace.tag('form'), 'h3')
|
|
87
|
+
form.set_text(InputPlace.tag('h3'), "Welcome #{name}!")
|
|
88
|
+
|
|
89
|
+
return form.response
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
__END__
|
|
94
|
+
|
|
95
|
+
@@view
|
|
96
|
+
<!DOCTYPE html>
|
|
97
|
+
<html>
|
|
98
|
+
<head>
|
|
99
|
+
<title>Using WebForms Core</title>
|
|
100
|
+
<script type="text/javascript" src="/script/web-forms.js"></script>
|
|
101
|
+
</head>
|
|
102
|
+
<body>
|
|
103
|
+
<form method="post" action="/" >
|
|
104
|
+
|
|
105
|
+
<label for="txt_Name">Your Name</label>
|
|
106
|
+
<input name="txt_Name" id="txt_Name" type="text" />
|
|
107
|
+
<br>
|
|
108
|
+
<label for="txt_FontSize">Set Font Size</label>
|
|
109
|
+
<input name="txt_FontSize" id="txt_FontSize" type="number" value="16" min="10" max="36" />
|
|
110
|
+
<br>
|
|
111
|
+
<label for="txt_BackgroundColor">Set Background Color</label>
|
|
112
|
+
<input name="txt_BackgroundColor" id="txt_BackgroundColor" type="text" />
|
|
113
|
+
<br>
|
|
114
|
+
<input name="btn_SetBodyValue" type="submit" value="Click to send data" />
|
|
115
|
+
|
|
116
|
+
</form>
|
|
117
|
+
</body>
|
|
118
|
+
</html>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### How the Example Works
|
|
122
|
+
|
|
123
|
+
When the page is requested for the first time, the `GET /` route renders the complete view.
|
|
124
|
+
|
|
125
|
+
When the submit button is clicked, the browser sends the form data to the `POST /` route. The server checks whether `btn_SetBodyValue` was submitted.
|
|
126
|
+
|
|
127
|
+
If the button was submitted, a `WebForms` instance is created and WebForms Core methods are used to generate commands:
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
form = WebForms.new
|
|
131
|
+
|
|
132
|
+
form.set_font_size(InputPlace.tag('form'), font_size)
|
|
133
|
+
form.set_background_color(InputPlace.tag('form'), background_color)
|
|
134
|
+
form.set_disabled(InputPlace.name('btn_SetBodyValue'), true)
|
|
135
|
+
|
|
136
|
+
form.add_tag(InputPlace.tag('form'), 'h3')
|
|
137
|
+
form.set_text(InputPlace.tag('h3'), "Welcome #{name}!")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The generated response is then returned:
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
return form.response
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
In this case, the complete view is not rendered again. The response contains WebForms Core commands that are processed by WebFormsJS in the browser.
|
|
147
|
+
|
|
148
|
+
The initial `GET` request and subsequent `POST` request therefore have different purposes. The initial request renders the page, while the POST request can return WebForms Core commands to update the existing HTML.
|
|
149
|
+
|
|
150
|
+
### WebFormsJS
|
|
151
|
+
|
|
152
|
+
WebFormsJS is the client-side runtime that executes WebForms Core commands in the browser.
|
|
153
|
+
|
|
154
|
+
Add the WebFormsJS script to the `<head>` section of your view:
|
|
155
|
+
|
|
156
|
+
```html
|
|
157
|
+
<script type="text/javascript" src="/script/web-forms.js"></script>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The latest WebFormsJS source is available in the [WebForms repository](https://github.com/elanatframework/Web_forms/blob/elanat_framework/web-forms.js).
|
|
161
|
+
|
|
162
|
+
## WebForms Core Architecture
|
|
163
|
+
|
|
164
|
+
WebForms Core separates server-side command generation from client-side command execution.
|
|
165
|
+
|
|
166
|
+
* **WebForms** runs on the server and generates commands.
|
|
167
|
+
* **WebFormsJS** runs in the browser and executes those commands.
|
|
168
|
+
* HTML remains the primary interface.
|
|
169
|
+
* No virtual DOM is required.
|
|
170
|
+
* No client-side component framework is required.
|
|
171
|
+
|
|
172
|
+
The Ruby implementation provides the server-side WebForms Core API.
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
After checking out the repository, install the dependencies:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
bundle install
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
You can run an interactive Ruby console with:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
bin/console
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
To build the gem:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
gem build wfc.gemspec
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
To install the locally built gem:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
gem install ./wfc-*.gem
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Source Code
|
|
201
|
+
|
|
202
|
+
The WebForms Core source code is available in the [WebForms Core classes repository](https://github.com/webforms-core/Web_forms_classes).
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
WebForms Core is released under the MIT License.
|
data/Rakefile
ADDED