karasi 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: 6573a2ffd830613a25643f19ffc709f75b2d8813a2baa337f8c1e74bbbafa1a5
4
- data.tar.gz: 6fd6dbb49313e049d27acae9fd074e882eb0665d84654bd91cd06bc514e53efb
3
+ metadata.gz: adbacd92b9c3a47dfb47a380183163af868c3e58c0dc3360042c64c2aa54723a
4
+ data.tar.gz: 6fb6f98074b5dad9e7d6cfdb16c2b99586ac40d4a55ec790e621c9721633a1a0
5
5
  SHA512:
6
- metadata.gz: 412b3630dec01b322607987018f5db1f7d88549b2072c15829993de7974c3818a3c191ecbde2b0fc67be17309e5f52806de002f829d1f4aa9ce7b9637e6f015f
7
- data.tar.gz: 6365ef83e5c072d007f423acee1f47965f78b0848e640f0f012a84f52fdc4a45541c8f93e3332053382ee34b6fda852f07057aefbd1ac479930b29a85b4f684d
6
+ metadata.gz: 72db440a90721ef71a14ee7817e6b13a8e2811e373d67bfbf53d433747ed085b225964c866d7e81cd50ab5eea5b392fe7dc2158ce695cbc9296bc5f3b253ec9e
7
+ data.tar.gz: ff7936c1b6484d726009597ceae83eb5a251ce8e1e082b61566267be7189c67aaadb1b1ffec6f07d8ea9d419b0dbb496c32a5c72e39b1653d6af9867162ae8d6
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
1
  # Karasi
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/karasi`. 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
+ **Karasi** previewable your `rails` application views without controllers implementation.
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'karasi'
10
+ gem 'karasi', group: :development
13
11
  ```
14
12
 
15
13
  And then execute:
@@ -22,7 +20,45 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ### config/routes.rb
24
+
25
+ #### Subdomain access with Rails engine
26
+ ```
27
+ constraints subdomain: 'preview' do
28
+ mount Karasi::Engine, at: '/'
29
+ end
30
+ ```
31
+
32
+ #### Path access
33
+
34
+ ```
35
+ get 'preview/*path', to: 'karasi/karasi#show'
36
+ ```
37
+
38
+ ### config/karasi.yml
39
+
40
+ ```
41
+ hello/index:
42
+ title: Hello world!
43
+ "@message": This is example application.
44
+ ```
45
+
46
+ ### app/views/hello/index.erb
47
+
48
+ ```
49
+ <h1><%= title %></h1>
50
+ <p><%= @message %></p>
51
+ ```
52
+
53
+ And access to `/hello/index` show to the hello messages.
54
+
55
+ ### Use layout
56
+
57
+ Add `config/karasi.yml` to
58
+
59
+ ```
60
+ layout: application
61
+ ```
26
62
 
27
63
  ## Development
28
64
 
@@ -33,3 +69,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
33
69
  ## Contributing
34
70
 
35
71
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/karasi.
72
+
73
+ ## TODO
74
+
75
+ * helpers
@@ -0,0 +1,41 @@
1
+ class Karasi::KarasiController < ActionController::Base
2
+ def show
3
+ render '/' + path, layout: layout, locals: locals
4
+ end
5
+
6
+ private
7
+
8
+ def path; params[:path]; end
9
+
10
+ def root_template_params
11
+ YAML.load_file('config/karasi.yml').symbolize_keys
12
+ end
13
+
14
+ def template_params
15
+ YAML.load_file('config/karasi.yml')[path].symbolize_keys
16
+ end
17
+
18
+ def locals
19
+ template_params.map do |key,value|
20
+ { key => deep_structize(value) }
21
+ end.inject(:merge)
22
+ end
23
+
24
+ def deep_structize(params)
25
+ if params.is_a? Array
26
+ params.map(&method(:deep_structize))
27
+ elsif params.is_a? Hash
28
+ params.symbolize_keys!
29
+ children = params.symbolize_keys.map do |key,value|
30
+ { key => deep_structize(value) }
31
+ end.inject(:merge)
32
+ OpenStruct.new(children)
33
+ else
34
+ params
35
+ end
36
+ end
37
+
38
+ def layout
39
+ template_params[:layout] || root_template_params[:layout]
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ Karasi::Engine.routes.draw do
2
+ get '/*path', to: 'karasi#show'
3
+ end
@@ -1,4 +1,5 @@
1
1
  require "karasi/version"
2
+ require "karasi/engine"
2
3
 
3
4
  module Karasi
4
5
  # Your code goes here...
@@ -0,0 +1,5 @@
1
+ module Karasi
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Karasi
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Karasi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karasi
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
  - Akira SUENAMI
@@ -63,13 +63,15 @@ files:
63
63
  - ".rspec"
64
64
  - ".travis.yml"
65
65
  - Gemfile
66
- - Gemfile.lock
67
66
  - README.md
68
67
  - Rakefile
68
+ - app/controllers/karasi/karasi_controller.rb
69
69
  - bin/console
70
70
  - bin/setup
71
+ - config/routes.rb
71
72
  - karasi.gemspec
72
73
  - lib/karasi.rb
74
+ - lib/karasi/engine.rb
73
75
  - lib/karasi/version.rb
74
76
  homepage: ''
75
77
  licenses: []
@@ -1,35 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- karasi (0.0.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- diff-lcs (1.3)
10
- rake (10.5.0)
11
- rspec (3.8.0)
12
- rspec-core (~> 3.8.0)
13
- rspec-expectations (~> 3.8.0)
14
- rspec-mocks (~> 3.8.0)
15
- rspec-core (3.8.0)
16
- rspec-support (~> 3.8.0)
17
- rspec-expectations (3.8.2)
18
- diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.8.0)
20
- rspec-mocks (3.8.0)
21
- diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.8.0)
23
- rspec-support (3.8.0)
24
-
25
- PLATFORMS
26
- ruby
27
-
28
- DEPENDENCIES
29
- bundler (~> 1.16)
30
- karasi!
31
- rake (~> 10.0)
32
- rspec (~> 3.0)
33
-
34
- BUNDLED WITH
35
- 1.16.2