menilite 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +63 -10
- data/lib/menilite/controller.rb +1 -1
- data/lib/menilite/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2228ad770fdb5fc5a5343e3c27644c350c623e86
|
4
|
+
data.tar.gz: 0cc3d1e02e37a9a080e639f83c0ada12a23d87e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3d37d812e06e8c8f34c6b728d145a1895722809981252a7e8f2f1f0f77b37aad4dda12176a5581d6506ac06ff538b8dbeff1b3c753f65e341e4c9800aec0804
|
7
|
+
data.tar.gz: cdda6647a91b84a2617df44ed5c85f1ca9d785e9402e15da7c95eb4e8477fba3d56350ab9e65e4f5b6339ee7c30097c532f714def55b53f5c6a8466f66547058
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Menilite
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
An isomophic web programming framework in Ruby.
|
4
|
+
Ruby codes also run on the client side by using [Opalrb](http://opalrb.org).
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -20,17 +19,71 @@ Or install it yourself as:
|
|
20
19
|
|
21
20
|
$ gem install menilite
|
22
21
|
|
23
|
-
##
|
22
|
+
## How to use
|
23
|
+
|
24
|
+
You can generate the template project by [Silica](https://github.com/youchan/silica) to get started.
|
25
|
+
|
26
|
+
$ gem install silica
|
27
|
+
$ silica new your-app
|
28
|
+
$ cd your-app
|
29
|
+
$ bundle install
|
30
|
+
$ bundle exec rackup
|
31
|
+
|
32
|
+
## Model definition
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class User < Menilite::Model
|
36
|
+
field :name
|
37
|
+
field :password
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Model definition is shared from the client side (compiled by Opal) and the server side (in MRI).
|
42
|
+
In this tiny example, `User` model has two string fields (`name` and `password`).
|
43
|
+
Field has a type and the type is set `string` as default.
|
44
|
+
You can specify another type by the following way, for example.
|
45
|
+
|
46
|
+
field :active, :boolean
|
47
|
+
|
48
|
+
## Action
|
24
49
|
|
25
|
-
|
50
|
+
```ruby
|
51
|
+
class User < Menilite::Model
|
52
|
+
action :signup, on_create: true do |password|
|
53
|
+
self.password = BCrypt::Password.create(password)
|
54
|
+
self.save
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
Models can have actions. The action is executed on the server side and the client code call the action as a method.
|
26
60
|
|
27
|
-
|
61
|
+
on the client side
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
user = User.new(name: 'youchan')
|
65
|
+
user.auth('topsecret')
|
66
|
+
```
|
28
67
|
|
29
|
-
|
68
|
+
## Controller
|
30
69
|
|
31
|
-
|
70
|
+
Controllers can have actions too.
|
32
71
|
|
33
|
-
|
72
|
+
```ruby
|
73
|
+
class ApplicationController < Menilite::Controller
|
74
|
+
action :login do |username, password|
|
75
|
+
user = User.find(name: username)
|
76
|
+
if user && user.auth(password)
|
77
|
+
session[:user_id] = user.id
|
78
|
+
else
|
79
|
+
raise 'login failed'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
```
|
34
84
|
|
35
|
-
|
85
|
+
The action of Controller is defined as a class method on the client side.
|
36
86
|
|
87
|
+
```ruby
|
88
|
+
ApplicationController.login('youchan', 'topsecret')
|
89
|
+
```
|
data/lib/menilite/controller.rb
CHANGED
@@ -35,7 +35,7 @@ module Menilite
|
|
35
35
|
action_info[name.to_s] = ActionInfo.new(name, block.parameters, options)
|
36
36
|
if RUBY_ENGINE == 'opal'
|
37
37
|
method = Proc.new do |*args, &callback| # todo: should adopt keyword parameters
|
38
|
-
action_url = self.respond_to?(:namespace) ? "api/#{self.
|
38
|
+
action_url = self.respond_to?(:namespace) ? "api/#{self.namespace}/#{name}" : "api/#{name}"
|
39
39
|
post_data = {}
|
40
40
|
post_data[:args] = args
|
41
41
|
Browser::HTTP.post(action_url, post_data.to_json) do
|
data/lib/menilite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menilite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youchan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|