jasonette-rails 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/MIT-LICENSE +20 -0
- data/README.md +264 -0
- data/Rakefile +24 -0
- data/lib/jasonette-rails.rb +1 -0
- data/lib/jasonette.rb +24 -0
- data/lib/jasonette/core/base.rb +128 -0
- data/lib/jasonette/core/components.rb +13 -0
- data/lib/jasonette/core/items.rb +39 -0
- data/lib/jasonette/core/layout.rb +9 -0
- data/lib/jasonette/core/properties.rb +74 -0
- data/lib/jasonette/core/sections.rb +9 -0
- data/lib/jasonette/core/style.rb +8 -0
- data/lib/jasonette/jason.rb +6 -0
- data/lib/jasonette/jason/body.rb +12 -0
- data/lib/jasonette/jason/body/header.rb +5 -0
- data/lib/jasonette/jason/body/header/search.rb +5 -0
- data/lib/jasonette/jason/head.rb +25 -0
- data/lib/jasonette/jbuilder_extensions.rb +19 -0
- data/lib/jasonette/version.rb +3 -0
- data/lib/tasks/jasonette_tasks.rake +4 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fda9259661d09209ae7d3517078f1679ff5ee80c
|
4
|
+
data.tar.gz: 2bbcea06e94b6f34baa0deb1b6b941c3dd29e6e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5cdf2b5f7c18619c602701100f9731053c8113bcd2b4c6025cd47385f61468e933fb91cf447302f442effba25fa9a7aefa4001c355e2d97a8a59e4d213efdf25
|
7
|
+
data.tar.gz: edadd2a9b6912de4644762159c7d2b9002100ed80dab55ae31a327a12fe78ed975d0c290ff9818fe7eb32e026b243b51366cd4052107bb49651d5d5f3b8bcf84
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Michael Lang
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
# Jasonette Rails
|
2
|
+
A extension of the Jbuilder framework to facilitate building Jasonette flavored JSON in Rails
|
3
|
+
|
4
|
+
## ALPHA code!
|
5
|
+
|
6
|
+
Warning: This project is **alpha** code and still in highly experimental stage and subjected to
|
7
|
+
drastic changes to the DSL. It is also quite full of bugs despite the unit tests you may find herein!
|
8
|
+
|
9
|
+
Note: Almost nothing about this gem is documented, however, you can find ample examples in the project's
|
10
|
+
spec/lib/jasonette/... folders. Generally speaking, the DSL follows the $jason structure closely and supporting
|
11
|
+
classes are organized in sub-folders of the project's lib/jasonette/... accordingly.
|
12
|
+
|
13
|
+
Since it is hooked into Jbuilder, you're able to mix and match Jbuilder directives alongside the extensions provided
|
14
|
+
through this gem. But it's challenging at the moment to "get it right" so everything stays in hierarchical context.
|
15
|
+
|
16
|
+
### Here lies trouble!
|
17
|
+
|
18
|
+
* There is limited support for breaking apart giant jbuilder templates into smaller partials. Right now, there's
|
19
|
+
just two "hooks" into the Jbuilder library and that's "json.jason" and "json.body"
|
20
|
+
|
21
|
+
* asset_paths don't quite work. For example, image_url('some_image.png') only yields a relative path and w/o fingerprint.
|
22
|
+
|
23
|
+
* not all components are represented, yet. layouts, labels, images, but not button, textfield, textarea, etc.
|
24
|
+
|
25
|
+
* Templates, mixins, etc. are not yet built.
|
26
|
+
|
27
|
+
* When you introduce structural errors, the error may be cryptic, basically showing only "failed to load with I/O error reported"
|
28
|
+
|
29
|
+
### TODO
|
30
|
+
|
31
|
+
* implement all the Jasonette components
|
32
|
+
* implement Templates, Mixins, etc.
|
33
|
+
* fix asset Helpers
|
34
|
+
* better error detection and handling
|
35
|
+
* refining implementation in the various classes
|
36
|
+
* document
|
37
|
+
* add Linting?
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
If I haven't done enough to scare you away, then check out the code and play around and provide feedback!
|
42
|
+
Some of the techniques I used are stretching the limits of my understanding of Rails rendering engine and
|
43
|
+
Ruby scoping, esp. with meta-programming, so watch out (and help out)!
|
44
|
+
|
45
|
+
This gem allows to to write the JSON structure expected by a Jasonette application in a much more powerful
|
46
|
+
way than with Jbuilder alone.
|
47
|
+
|
48
|
+
For example:
|
49
|
+
|
50
|
+
Here's how the "hello.json" demo JSON would be rendered with this gem:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
json.jason do
|
54
|
+
head.title "{ ˃̵̑ᴥ˂̵̑}"
|
55
|
+
head.action("$foreground") { reload! }
|
56
|
+
head.action("$pull") { reload! }
|
57
|
+
body do
|
58
|
+
sections do
|
59
|
+
items do
|
60
|
+
image image_url("rails-logo.png") do
|
61
|
+
style do
|
62
|
+
align "center"
|
63
|
+
padding "30"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
layout :vertical do
|
68
|
+
style do
|
69
|
+
padding "30"
|
70
|
+
spacing "20"
|
71
|
+
align "center"
|
72
|
+
end
|
73
|
+
components do
|
74
|
+
label "It's ALIVE!" do
|
75
|
+
style do
|
76
|
+
align "center"
|
77
|
+
font "Courier-Bold"
|
78
|
+
size "18"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
label do
|
83
|
+
text "This is a demo app. You can make your own app by changing the url inside settings.plist"
|
84
|
+
style do
|
85
|
+
align "center"
|
86
|
+
font "Courier"
|
87
|
+
padding "10"
|
88
|
+
size "14"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
label "{ ˃̵̑ᴥ˂̵̑}" do
|
93
|
+
style do
|
94
|
+
align "center"
|
95
|
+
font "HelveticaNeue-Bold"
|
96
|
+
size "50"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
label "Check out Live DEMO" do
|
103
|
+
style do
|
104
|
+
align "right"
|
105
|
+
padding "10"
|
106
|
+
color "#000000"
|
107
|
+
font "HelveticaNeue"
|
108
|
+
size "12"
|
109
|
+
end
|
110
|
+
|
111
|
+
href do
|
112
|
+
url "file://demo.json"
|
113
|
+
fresh "true"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
label "Watch the tutorial video" do
|
118
|
+
style do
|
119
|
+
align "right"
|
120
|
+
padding "10"
|
121
|
+
color "#000000"
|
122
|
+
font "HelveticaNeue"
|
123
|
+
size "12"
|
124
|
+
end
|
125
|
+
href do
|
126
|
+
url "https://www.youtube.com/watch?v=hfevBAAfCMQ"
|
127
|
+
view "web"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
label "View documentation" do
|
132
|
+
style do
|
133
|
+
align "right"
|
134
|
+
padding "10"
|
135
|
+
color "#000000"
|
136
|
+
font "HelveticaNeue"
|
137
|
+
size "12"
|
138
|
+
end
|
139
|
+
href do
|
140
|
+
url "https://jasonette.github.io/documentation"
|
141
|
+
view "web"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
The goal is to make things a lot easier to build than with Jbuilder alone. For example, above, it's much
|
151
|
+
easier to build the sections, items, and components without having to deal with child!, array!, or partials
|
152
|
+
with collections. Which also makes it a lot easier to build arrays of heterogeneous components.
|
153
|
+
|
154
|
+
Building your data is a snap, too. For example:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
json.jason do
|
158
|
+
head do
|
159
|
+
title "Beatles"
|
160
|
+
data.names ["John", "George", "Paul", "Ringo"]
|
161
|
+
data.songs [
|
162
|
+
{album: "My Bonnie", song: "My Bonnie"},
|
163
|
+
{album: "My Bonnie", song: "Skinny Minnie"},
|
164
|
+
{album: "Please Please Me", song: "I Saw Her Standing There"},
|
165
|
+
]
|
166
|
+
end
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
Some things get a lot less verbose
|
171
|
+
|
172
|
+
style blocks using hashes:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
json.jason do
|
176
|
+
head do
|
177
|
+
title "Foobar"
|
178
|
+
style "styled_row", font: "HelveticaNeue", size: 20, color: "#FFFFFF", padding: 10
|
179
|
+
style "col", font: "RobotoBold", color: "#FF0055"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
```
|
183
|
+
Produces:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
{
|
187
|
+
"$jason": {
|
188
|
+
"head": {
|
189
|
+
{
|
190
|
+
"title": "Foobar",
|
191
|
+
"styles": {
|
192
|
+
"styled_row": {
|
193
|
+
"font": "HelveticaNeue",
|
194
|
+
"size": "20",
|
195
|
+
"color": "#FFFFFF",
|
196
|
+
"padding": "10",
|
197
|
+
},
|
198
|
+
"col": {
|
199
|
+
"font": "RobotoBold",
|
200
|
+
"color": "#FF0055",
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}
|
207
|
+
```
|
208
|
+
|
209
|
+
You can even do the bare minimum head block like this:
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
json.jason do
|
213
|
+
head.title "Simple!"
|
214
|
+
body do
|
215
|
+
# Your Brilliant App
|
216
|
+
end
|
217
|
+
end
|
218
|
+
```
|
219
|
+
|
220
|
+
...more to come!...
|
221
|
+
|
222
|
+
## Installation
|
223
|
+
Add this line to your application's Gemfile:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
gem 'jasonette-rails'
|
227
|
+
```
|
228
|
+
|
229
|
+
And then execute:
|
230
|
+
```bash
|
231
|
+
$ bundle
|
232
|
+
```
|
233
|
+
|
234
|
+
Or install it yourself as:
|
235
|
+
```bash
|
236
|
+
$ gem install jasonette
|
237
|
+
```
|
238
|
+
|
239
|
+
Then start using. Basically, start with "json.jason" to get your opening $jason block and
|
240
|
+
## Contributing
|
241
|
+
|
242
|
+
# How to contribute to Jasonette Rails
|
243
|
+
|
244
|
+
## **Do you have a bug report or a feature request?**
|
245
|
+
|
246
|
+
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/mwlang/jasonette-rails/issues).
|
247
|
+
|
248
|
+
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/mwlang/jasonette-rails/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
|
249
|
+
|
250
|
+
## **Did you write a patch that fixes a bug?**
|
251
|
+
|
252
|
+
If you find a bug **anywhere in the code**, or have any improvements anywhere else, please feel free to:
|
253
|
+
|
254
|
+
1. Fork the project
|
255
|
+
2. Create a feature branch (fork the master branch)
|
256
|
+
3. Fix
|
257
|
+
4. Send a pull request
|
258
|
+
|
259
|
+
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
|
260
|
+
|
261
|
+
* Please include specs that cover the issue. PR will not be accepted without the relevant tests to support the change.
|
262
|
+
|
263
|
+
## License
|
264
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
require 'rspec/core'
|
11
|
+
require 'rspec/core/rake_task'
|
12
|
+
|
13
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
14
|
+
rdoc.rdoc_dir = 'rdoc'
|
15
|
+
rdoc.title = 'Jasonette Rails'
|
16
|
+
rdoc.options << '--line-numbers'
|
17
|
+
rdoc.rdoc_files.include('README.md')
|
18
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
22
|
+
RSpec::Core::RakeTask.new(:spec)
|
23
|
+
|
24
|
+
task :default => :spec
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'jasonette'
|
data/lib/jasonette.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
require 'jbuilder/jbuilder_template'
|
3
|
+
|
4
|
+
# Core components for library
|
5
|
+
require_relative 'jasonette/core/properties'
|
6
|
+
require_relative 'jasonette/core/base'
|
7
|
+
require_relative 'jasonette/core/style'
|
8
|
+
require_relative 'jasonette/core/sections'
|
9
|
+
require_relative 'jasonette/core/items'
|
10
|
+
require_relative 'jasonette/core/layout'
|
11
|
+
require_relative 'jasonette/core/components'
|
12
|
+
|
13
|
+
# Structural components
|
14
|
+
require_relative 'jasonette/jason'
|
15
|
+
require_relative 'jasonette/jason/head'
|
16
|
+
require_relative 'jasonette/jason/body'
|
17
|
+
require_relative 'jasonette/jason/body/header'
|
18
|
+
require_relative 'jasonette/jason/body/header/search'
|
19
|
+
|
20
|
+
# Inject Jasonette into Jbuilder
|
21
|
+
require_relative 'jasonette/jbuilder_extensions'
|
22
|
+
|
23
|
+
module Jasonette
|
24
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Jasonette
|
2
|
+
class Base
|
3
|
+
include Properties
|
4
|
+
include ActionView::Helpers
|
5
|
+
|
6
|
+
def implicit_set! name, *args, &block
|
7
|
+
with_attributes do
|
8
|
+
if properties.include? name
|
9
|
+
property_set! name, *args, &block
|
10
|
+
else
|
11
|
+
json.set!(name) { instance_eval(&block) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def attr_value name
|
17
|
+
if properties.include? name
|
18
|
+
instance_variable_get :"@#{name}"
|
19
|
+
else
|
20
|
+
@attributes[name.to_s]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing name, *args, &block
|
25
|
+
if ::Kernel.block_given?
|
26
|
+
implicit_set! name, *args, &block
|
27
|
+
else
|
28
|
+
if properties.include? name
|
29
|
+
return property_get! name
|
30
|
+
else
|
31
|
+
with_attributes { json.set! name, *args }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :context
|
38
|
+
attr_reader :attributes
|
39
|
+
attr_reader :json
|
40
|
+
|
41
|
+
def initialize context
|
42
|
+
@context = context
|
43
|
+
@attributes = {}
|
44
|
+
instance_eval(&::Proc.new) if ::Kernel.block_given?
|
45
|
+
end
|
46
|
+
|
47
|
+
def trigger name, &block
|
48
|
+
with_attributes do
|
49
|
+
json.trigger name
|
50
|
+
instance_eval(&block) if block_given?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def action name="action", &block
|
55
|
+
with_attributes do
|
56
|
+
json.set! name do
|
57
|
+
block_given? ? instance_eval(&block) : success { type "$render" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def render!
|
63
|
+
with_attributes { json.type "$render" }
|
64
|
+
end
|
65
|
+
|
66
|
+
def reload!
|
67
|
+
with_attributes { json.type "$reload" }
|
68
|
+
end
|
69
|
+
|
70
|
+
def success &block
|
71
|
+
with_attributes do
|
72
|
+
if block_given?
|
73
|
+
json.success { instance_eval(&block) }
|
74
|
+
else
|
75
|
+
json.success { json.type "$render" }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def target!
|
81
|
+
attributes!.to_json
|
82
|
+
end
|
83
|
+
|
84
|
+
def encode
|
85
|
+
instance_eval(&::Proc.new)
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
def empty?
|
90
|
+
properties_empty? && @attributes.empty?
|
91
|
+
end
|
92
|
+
|
93
|
+
def klass name
|
94
|
+
json.set! "class", name
|
95
|
+
end
|
96
|
+
alias :css_class :klass
|
97
|
+
|
98
|
+
def with_attributes
|
99
|
+
if json
|
100
|
+
instance_eval(&::Proc.new)
|
101
|
+
return self
|
102
|
+
end
|
103
|
+
template = JbuilderTemplate.new(context) do |json|
|
104
|
+
@json = json
|
105
|
+
instance_eval(&::Proc.new)
|
106
|
+
@json = nil
|
107
|
+
end
|
108
|
+
@attributes.merge! template.attributes!
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def inline json
|
113
|
+
@attributes.merge! JSON.parse(json)
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def inline! name, *args
|
118
|
+
with_attributes do
|
119
|
+
json.partial! name, *args
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def attributes!
|
124
|
+
merge_properties
|
125
|
+
@attributes
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Jasonette
|
2
|
+
class Items < Jasonette::Base
|
3
|
+
|
4
|
+
def label caption=nil
|
5
|
+
item = Jasonette::Base.new(@context) do
|
6
|
+
text caption unless caption.nil?
|
7
|
+
type "label"
|
8
|
+
with_attributes { instance_eval(&::Proc.new) } if block_given?
|
9
|
+
end
|
10
|
+
append item
|
11
|
+
end
|
12
|
+
|
13
|
+
def image uri=nil
|
14
|
+
item = Jasonette::Base.new(@context) do
|
15
|
+
type "image"
|
16
|
+
url uri unless uri.nil?
|
17
|
+
with_attributes { instance_eval(&::Proc.new) } if block_given?
|
18
|
+
end
|
19
|
+
append item
|
20
|
+
end
|
21
|
+
|
22
|
+
def layout orientation="vertical"
|
23
|
+
item = Jasonette::Layout.new(@context) do
|
24
|
+
type orientation
|
25
|
+
with_attributes { instance_eval(&::Proc.new) } if block_given?
|
26
|
+
end
|
27
|
+
append item
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def append builder
|
33
|
+
@attributes["items"] ||= []
|
34
|
+
@attributes["items"] << builder.attributes!
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Jasonette::Properties
|
2
|
+
module ClassMethods
|
3
|
+
def property name
|
4
|
+
properties << name
|
5
|
+
end
|
6
|
+
|
7
|
+
def properties
|
8
|
+
@properties ||= []
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included base
|
13
|
+
base.send :extend, ClassMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
def properties
|
17
|
+
self.class.properties
|
18
|
+
end
|
19
|
+
|
20
|
+
def prop name
|
21
|
+
instance_variable_get("@#{name}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def properties_empty?
|
25
|
+
properties.all? do |ivar_name|
|
26
|
+
ivar = instance_variable_get(:"@#{ivar_name}")
|
27
|
+
ivar.nil? || ivar.empty?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def klass_for_property name
|
32
|
+
name = name.to_s.camelize
|
33
|
+
klass = "#{self.class}::#{name}".constantize rescue nil
|
34
|
+
klass ||= "Jasonette::#{name}".constantize rescue Jasonette::Base
|
35
|
+
klass
|
36
|
+
end
|
37
|
+
|
38
|
+
def property_get! name
|
39
|
+
ivar_name = "@#{name}"
|
40
|
+
if instance_variable_get(ivar_name).nil?
|
41
|
+
klass = klass_for_property name
|
42
|
+
instance_variable_set(ivar_name, klass.new(@context))
|
43
|
+
end
|
44
|
+
instance_variable_get(ivar_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
def property_set! name, *args, &block
|
48
|
+
ivar = property_get! name
|
49
|
+
return ivar unless block_given?
|
50
|
+
ivar.tap { |v| v.encode(&block) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def merge_properties
|
54
|
+
properties.each do |property_name|
|
55
|
+
ivar = instance_variable_get(:"@#{property_name}")
|
56
|
+
next if ivar.nil? || ivar.empty?
|
57
|
+
@attributes[property_name.to_s] ||= {}
|
58
|
+
@attributes[property_name.to_s].merge! ivar.attributes!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def property_sender target, name, *args, &block
|
63
|
+
if block_given?
|
64
|
+
target.send name, *args, &block
|
65
|
+
elsif args.one? && args.first.is_a?(Hash)
|
66
|
+
target.send name do
|
67
|
+
args.first.each{ |key, value| json.set! key, value.to_s }
|
68
|
+
end
|
69
|
+
else
|
70
|
+
raise "unhandled definition!"
|
71
|
+
end
|
72
|
+
self
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Jasonette
|
2
|
+
class Jason::Head < Jasonette::Base
|
3
|
+
|
4
|
+
property :styles
|
5
|
+
property :actions
|
6
|
+
property :data
|
7
|
+
property :templates
|
8
|
+
|
9
|
+
def template name, *args, &block
|
10
|
+
property_sender templates, name, *args, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def datum name, *args, &block
|
14
|
+
property_sender data, name, *args, &block
|
15
|
+
end
|
16
|
+
|
17
|
+
def style name, *args, &block
|
18
|
+
property_sender styles, name, *args, &block
|
19
|
+
end
|
20
|
+
|
21
|
+
def action name, *args, &block
|
22
|
+
property_sender actions, name, *args, &block
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Jasonette
|
2
|
+
module JbuilderExtensions
|
3
|
+
def jason &block
|
4
|
+
builder = Jasonette::Jason.new(@context)
|
5
|
+
builder.with_attributes { instance_eval(&block) }
|
6
|
+
_set_value "$jason", builder.attributes!
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def body &block
|
11
|
+
builder = Jasonette::Jason::Body.new(@context)
|
12
|
+
builder.with_attributes { instance_eval(&block) }
|
13
|
+
_set_value "body", builder.attributes!
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
::Jbuilder.send(:include, JbuilderExtensions)
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jasonette-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mwlang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionview
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jbuilder
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.6.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.5.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.5.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-its
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.2.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.4.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.4.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: json_matchers
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.7.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.7.0
|
153
|
+
description: Jbuilder bolt-on to make Jasonette JSON easier to produce
|
154
|
+
email:
|
155
|
+
- mwlang@cybrains.net
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- MIT-LICENSE
|
161
|
+
- README.md
|
162
|
+
- Rakefile
|
163
|
+
- lib/jasonette-rails.rb
|
164
|
+
- lib/jasonette.rb
|
165
|
+
- lib/jasonette/core/base.rb
|
166
|
+
- lib/jasonette/core/components.rb
|
167
|
+
- lib/jasonette/core/items.rb
|
168
|
+
- lib/jasonette/core/layout.rb
|
169
|
+
- lib/jasonette/core/properties.rb
|
170
|
+
- lib/jasonette/core/sections.rb
|
171
|
+
- lib/jasonette/core/style.rb
|
172
|
+
- lib/jasonette/jason.rb
|
173
|
+
- lib/jasonette/jason/body.rb
|
174
|
+
- lib/jasonette/jason/body/header.rb
|
175
|
+
- lib/jasonette/jason/body/header/search.rb
|
176
|
+
- lib/jasonette/jason/head.rb
|
177
|
+
- lib/jasonette/jbuilder_extensions.rb
|
178
|
+
- lib/jasonette/version.rb
|
179
|
+
- lib/tasks/jasonette_tasks.rake
|
180
|
+
homepage: http://codeconnoisseur.org
|
181
|
+
licenses:
|
182
|
+
- MIT
|
183
|
+
metadata: {}
|
184
|
+
post_install_message:
|
185
|
+
rdoc_options: []
|
186
|
+
require_paths:
|
187
|
+
- lib
|
188
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
requirements: []
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 2.6.10
|
201
|
+
signing_key:
|
202
|
+
specification_version: 4
|
203
|
+
summary: Jbuilder bolt-on to make Jasonette JSON easier to produce
|
204
|
+
test_files: []
|