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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e96823093a09cbe81fe57e93acb586d480258fb6
4
- data.tar.gz: 1c1698195f5afb071265a644f0b5f725d04fc1a3
3
+ metadata.gz: 2228ad770fdb5fc5a5343e3c27644c350c623e86
4
+ data.tar.gz: 0cc3d1e02e37a9a080e639f83c0ada12a23d87e2
5
5
  SHA512:
6
- metadata.gz: 16f926123ff653a696b6b1fea7477de86fa51fe2776708202886518c214cce4284f6e47a043df4d285804793c12dc2a262793ccb3f8f71be1157a6c98af464b0
7
- data.tar.gz: a5190655a95e355561b5f15f55fe96bd7d654134aad86bf46678a115cccd52e537ee9fd205ec34565a0111f5077e76d28f76fe95baf561cb0c9a3ff9173dd014
6
+ metadata.gz: c3d37d812e06e8c8f34c6b728d145a1895722809981252a7e8f2f1f0f77b37aad4dda12176a5581d6506ac06ff538b8dbeff1b3c753f65e341e4c9800aec0804
7
+ data.tar.gz: cdda6647a91b84a2617df44ed5c85f1ca9d785e9402e15da7c95eb4e8477fba3d56350ab9e65e4f5b6339ee7c30097c532f714def55b53f5c6a8466f66547058
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Menilite
2
2
 
3
- 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/menilite`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- ## Usage
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
- TODO: Write usage instructions here
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
- ## Development
61
+ on the client side
62
+
63
+ ```ruby
64
+ user = User.new(name: 'youchan')
65
+ user.auth('topsecret')
66
+ ```
28
67
 
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.
68
+ ## Controller
30
69
 
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+ Controllers can have actions too.
32
71
 
33
- ## Contributing
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/menilite.
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
+ ```
@@ -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.class.namespace}/#{name}" : "api/#{name}"
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
@@ -1,3 +1,3 @@
1
1
  module Menilite
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-13 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler