praxis 0.18.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -1
  3. data/Gemfile +2 -1
  4. data/README.md +21 -27
  5. data/lib/api_browser/app/index.html +3 -3
  6. data/lib/api_browser/app/js/app.js +23 -3
  7. data/lib/api_browser/app/js/controllers/action.js +33 -21
  8. data/lib/api_browser/app/js/controllers/controller.js +3 -25
  9. data/lib/api_browser/app/js/controllers/menu.js +61 -51
  10. data/lib/api_browser/app/js/controllers/trait.js +10 -0
  11. data/lib/api_browser/app/js/controllers/type.js +8 -5
  12. data/lib/api_browser/app/js/directives/fixed_if_fits.js +9 -2
  13. data/lib/api_browser/app/js/directives/menu_item.js +59 -0
  14. data/lib/api_browser/app/js/directives/readable_list.js +87 -0
  15. data/lib/api_browser/app/js/directives/url.js +16 -0
  16. data/lib/api_browser/app/js/factories/Configuration.js +1 -2
  17. data/lib/api_browser/app/js/factories/Documentation.js +49 -7
  18. data/lib/api_browser/app/js/factories/PageInfo.js +9 -0
  19. data/lib/api_browser/app/js/factories/normalize_attributes.js +1 -2
  20. data/lib/api_browser/app/js/factories/template_for.js +9 -4
  21. data/lib/api_browser/app/sass/modules/_sidebar.scss +54 -15
  22. data/lib/api_browser/app/sass/praxis.scss +4 -0
  23. data/lib/api_browser/app/views/action.html +72 -41
  24. data/lib/api_browser/app/views/builtin/field-selector.html +24 -0
  25. data/lib/api_browser/app/views/controller.html +9 -10
  26. data/lib/api_browser/app/views/directives/menu_item.html +8 -0
  27. data/lib/api_browser/app/views/directives/url.html +3 -0
  28. data/lib/api_browser/app/views/layout.html +2 -2
  29. data/lib/api_browser/app/views/menu.html +8 -14
  30. data/lib/api_browser/app/views/navbar.html +1 -1
  31. data/lib/api_browser/app/views/trait.html +13 -0
  32. data/lib/api_browser/app/views/type/details.html +1 -1
  33. data/lib/api_browser/app/views/type.html +1 -1
  34. data/lib/api_browser/app/views/types/embedded/field-selector.html +13 -0
  35. data/lib/api_browser/app/views/types/label/primitive.html +1 -1
  36. data/lib/api_browser/app/views/types/standalone/array.html +3 -0
  37. data/lib/praxis/action_definition.rb +15 -2
  38. data/lib/praxis/collection.rb +17 -5
  39. data/lib/praxis/controller.rb +12 -3
  40. data/lib/praxis/docs/generator.rb +11 -7
  41. data/lib/praxis/extensions/field_expansion.rb +59 -0
  42. data/lib/praxis/extensions/field_selection/field_selector.rb +125 -0
  43. data/lib/praxis/extensions/field_selection.rb +10 -0
  44. data/lib/praxis/extensions/mapper_selectors.rb +16 -0
  45. data/lib/praxis/extensions/rendering.rb +43 -0
  46. data/lib/praxis/links.rb +1 -0
  47. data/lib/praxis/media_type.rb +87 -3
  48. data/lib/praxis/media_type_collection.rb +1 -1
  49. data/lib/praxis/media_type_identifier.rb +6 -1
  50. data/lib/praxis/plugins/praxis_mapper_plugin.rb +29 -10
  51. data/lib/praxis/restful_doc_generator.rb +11 -8
  52. data/lib/praxis/tasks/api_docs.rb +6 -5
  53. data/lib/praxis/types/multipart_array.rb +1 -1
  54. data/lib/praxis/version.rb +1 -1
  55. data/lib/praxis.rb +5 -0
  56. data/praxis.gemspec +4 -3
  57. data/spec/api_browser/factories/configuration_spec.js +32 -0
  58. data/spec/api_browser/factories/documentation_spec.js +75 -25
  59. data/spec/api_browser/factories/normalize_attributes_spec.js +0 -5
  60. data/spec/praxis/{types/collection_spec.rb → collection_spec.rb} +36 -23
  61. data/spec/praxis/extensions/field_expansion_spec.rb +96 -0
  62. data/spec/praxis/extensions/field_selection/field_selector_spec.rb +92 -0
  63. data/spec/praxis/extensions/rendering_spec.rb +63 -0
  64. data/spec/praxis/links_spec.rb +6 -0
  65. data/spec/praxis/media_type_collection_spec.rb +0 -1
  66. data/spec/praxis/media_type_identifier_spec.rb +15 -1
  67. data/spec/praxis/media_type_spec.rb +101 -3
  68. data/spec/praxis/plugins/praxis_mapper_plugin_spec.rb +33 -24
  69. data/spec/praxis/request_stages/request_stage_spec.rb +1 -1
  70. data/spec/praxis/types/multipart_array_spec.rb +14 -4
  71. data/spec/spec_app/app/controllers/instances.rb +6 -1
  72. data/spec/spec_app/config/environment.rb +2 -1
  73. data/spec/spec_app/design/resources/instances.rb +1 -0
  74. data/spec/spec_helper.rb +3 -1
  75. data/spec/support/spec_media_types.rb +224 -1
  76. metadata +50 -16
@@ -1,9 +1,13 @@
1
1
  class Person < Praxis::MediaType
2
+ identifier "application/vnd.acme.person"
3
+
2
4
  attributes do
3
5
  attribute :id, Integer
4
6
  attribute :name, String, example: /[:name:]/
5
7
  attribute :href, String, example: proc { |person| "/people/#{person.id}" }
6
- attribute :links, silence_warnings { Praxis::Collection.of(String) }
8
+ attribute :links, Attributor::Collection.of(String),
9
+ description: 'Here to ensure an explicit links attribute works'
10
+
7
11
  end
8
12
 
9
13
  view :default do
@@ -29,6 +33,10 @@ class Person < Praxis::MediaType
29
33
  attribute :size
30
34
  end
31
35
 
36
+ view :default do
37
+ attribute :href
38
+ end
39
+
32
40
  end
33
41
  end
34
42
 
@@ -65,4 +73,219 @@ class Address < Praxis::MediaType
65
73
 
66
74
  attribute :links
67
75
  end
76
+
77
+ view :link do
78
+ attribute :id
79
+ attribute :name
80
+ end
81
+
82
+ end
83
+
84
+
85
+
86
+
87
+ class Blog < Praxis::MediaType
88
+ identifier 'application/vnd.bloggy.blog'
89
+ description "A Bloggy Blog"
90
+
91
+ attributes do
92
+ attribute :id, Integer,
93
+ description: 'Unique identifier'
94
+ attribute :name, String,
95
+ description: 'Short name'
96
+ attribute :href, String,
97
+ example: proc {|o,ctx| "/api/v1.0/blogs/#{o.id}"},
98
+ description: 'Href for use with this API'
99
+ attribute :description, String,
100
+ description: 'Longer description'
101
+ attribute :url, String,
102
+ example: proc {|o,ctx| "example.com/blogs/#{o.id}"},
103
+ description: 'URL for a web browser'
104
+
105
+ attribute :timestamps do
106
+ attribute :created_at, DateTime
107
+ attribute :updated_at, DateTime
108
+ end
109
+
110
+ attribute :tags, Attributor::Collection.of(String),
111
+ description: 'Array of tags'
112
+
113
+ attribute :recent_posts, Praxis::Collection.of(Post),
114
+ description: 'Array of recent related Post resources'
115
+ attribute :owner, User,
116
+ description: 'Related User resource'
117
+
118
+ attribute :posts_summary, Post::CollectionSummary,
119
+ example: proc { |blog,ctx| Post::CollectionSummary.example(ctx, href: "#{blog.href}/posts") },
120
+ description: "Summary of information from related Post resources"
121
+
122
+ links do
123
+ link :posts, using: :posts_summary
124
+ link :owner
125
+ end
126
+ end
127
+
128
+ view :default do
129
+ attribute :id
130
+ attribute :href
131
+ attribute :name
132
+ attribute :description
133
+ attribute :url
134
+ attribute :timestamps
135
+
136
+ attribute :owner
137
+ attribute :links
138
+ end
139
+
140
+ view :overview do
141
+ attribute :id
142
+ attribute :name
143
+ attribute :description
144
+ end
145
+
146
+ view :link do
147
+ attribute :href
148
+ end
149
+
150
+ end
151
+
152
+
153
+ class Post < Praxis::MediaType
154
+ identifier 'application/vnd.bloggy.post'
155
+
156
+ description 'A Post in Bloggy'
157
+
158
+ attributes do
159
+ attribute :id, Integer,
160
+ description: 'Unique identifier'
161
+ attribute :href, String,
162
+ example: proc {|o,ctx| "/api/v1.0/posts/#{o.id}"},
163
+ description: 'Href for use with this API'
164
+
165
+ attribute :title, String,
166
+ example: /\w+/
167
+ attribute :content, String,
168
+ example: /[:sentence:]{4,5}/
169
+ attribute :url, String,
170
+ description: 'URL for a web browser',
171
+ example: proc {|o,ctx| "example.com/posts/#{o.id}"}
172
+
173
+ attribute :author, User,
174
+ description: 'Related User resource'
175
+ attribute :blog, Blog,
176
+ description: 'Related Blog resource'
177
+
178
+ attribute :followup_posts, Attributor::Collection.of(Post)
179
+
180
+ attribute :timestamps do
181
+ attribute :created_at, DateTime
182
+ attribute :updated_at, DateTime
183
+ end
184
+
185
+ links do
186
+ link :author
187
+ link :blog
188
+ end
189
+ end
190
+
191
+ view :default do
192
+ attribute :id
193
+ attribute :href
194
+
195
+ attribute :title
196
+ attribute :content
197
+ attribute :url
198
+ attribute :author
199
+
200
+ attribute :timestamps
201
+ attribute :links
202
+ end
203
+
204
+ view :link do
205
+ attribute :href
206
+ end
207
+
208
+
209
+ class CollectionSummary < Praxis::MediaType
210
+ attributes do
211
+ attribute :href, String
212
+ attribute :count, Integer
213
+ end
214
+
215
+ view :link do
216
+ attribute :href
217
+ end
218
+ end
219
+ end
220
+
221
+
222
+ class User < Praxis::MediaType
223
+ identifier 'application/vnd.bloggy.user'
224
+
225
+ attributes do
226
+ attribute :id, Integer
227
+ attribute :href, String,
228
+ example: proc {|o,ctx| "/api/v1.0/users/#{o.id}"}
229
+
230
+ attribute :first, String, example: /[:first_name:]/
231
+ attribute :last, String, example: /[:last_name:]/
232
+ attribute :posts, Attributor::Collection.of(Post)
233
+
234
+ attribute :post_matrix, Attributor::Collection.of(Attributor::Collection.of(Post)),
235
+ description: 'matrix of posts with some row and some column axes that make sense'
236
+ attribute :daily_posts, Attributor::Collection.of(Attributor::Struct) do
237
+ attribute :day, String
238
+ attribute :posts, Attributor::Collection.of(Post)
239
+ end
240
+
241
+ attribute :primary_blog, Blog
242
+
243
+ attribute :timestamps do
244
+ attribute :created_at, DateTime
245
+ attribute :updated_at, DateTime
246
+ end
247
+
248
+ attribute :posts_summary, Post::CollectionSummary,
249
+ example: proc { |user,ctx| Post::CollectionSummary.example(ctx, href: "#{user.href}/posts") }
250
+
251
+ links do
252
+ link :posts, using: :posts_summary
253
+ link :primary_blog
254
+ end
255
+
256
+ end
257
+
258
+ view :default do
259
+ attribute :id
260
+ attribute :href
261
+
262
+ attribute :first
263
+ attribute :last
264
+
265
+ attribute :links
266
+ end
267
+
268
+ view :extended do
269
+ attribute :id
270
+ attribute :href
271
+
272
+ attribute :first
273
+ attribute :last
274
+ attribute :primary_blog, view: :overview
275
+
276
+ attribute :links
277
+ end
278
+
279
+ view :with_post_links do
280
+ attribute :id
281
+ attribute :posts, view: :link
282
+ end
283
+
284
+ view :link do
285
+ attribute :href
286
+ end
287
+
288
+ view :summary do
289
+ attribute :links
290
+ end
68
291
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praxis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.1
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-21 00:00:00.000000000 Z
12
+ date: 2015-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -71,44 +71,44 @@ dependencies:
71
71
  name: praxis-mapper
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '4.1'
76
+ version: '4.2'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '4.1'
83
+ version: '4.2'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: praxis-blueprints
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ">="
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '2.2'
90
+ version: '3.1'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ">="
95
+ - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '2.2'
97
+ version: '3.1'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: attributor
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: 4.0.1
104
+ version: '5.0'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: 4.0.1
111
+ version: '5.0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: thor
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -389,6 +389,20 @@ dependencies:
389
389
  - - "~>"
390
390
  - !ruby/object:Gem::Version
391
391
  version: '1'
392
+ - !ruby/object:Gem::Dependency
393
+ name: coveralls
394
+ requirement: !ruby/object:Gem::Requirement
395
+ requirements:
396
+ - - ">="
397
+ - !ruby/object:Gem::Version
398
+ version: '0'
399
+ type: :development
400
+ prerelease: false
401
+ version_requirements: !ruby/object:Gem::Requirement
402
+ requirements:
403
+ - - ">="
404
+ - !ruby/object:Gem::Version
405
+ version: '0'
392
406
  description:
393
407
  email:
394
408
  - blanquer@gmail.com
@@ -656,14 +670,19 @@ files:
656
670
  - lib/api_browser/app/js/controllers/action.js
657
671
  - lib/api_browser/app/js/controllers/controller.js
658
672
  - lib/api_browser/app/js/controllers/menu.js
673
+ - lib/api_browser/app/js/controllers/trait.js
659
674
  - lib/api_browser/app/js/controllers/type.js
660
675
  - lib/api_browser/app/js/directives/attribute_description.js
661
676
  - lib/api_browser/app/js/directives/attribute_table.js
662
677
  - lib/api_browser/app/js/directives/fixed_if_fits.js
678
+ - lib/api_browser/app/js/directives/menu_item.js
663
679
  - lib/api_browser/app/js/directives/no_container.js
680
+ - lib/api_browser/app/js/directives/readable_list.js
664
681
  - lib/api_browser/app/js/directives/type_placeholder.js
682
+ - lib/api_browser/app/js/directives/url.js
665
683
  - lib/api_browser/app/js/factories/Configuration.js
666
684
  - lib/api_browser/app/js/factories/Documentation.js
685
+ - lib/api_browser/app/js/factories/PageInfo.js
667
686
  - lib/api_browser/app/js/factories/normalize_attributes.js
668
687
  - lib/api_browser/app/js/factories/template_for.js
669
688
  - lib/api_browser/app/js/filters/attribute_name.js
@@ -681,6 +700,7 @@ files:
681
700
  - lib/api_browser/app/sass/praxis.scss
682
701
  - lib/api_browser/app/sass/variables/_bootstrap-variables.scss
683
702
  - lib/api_browser/app/views/action.html
703
+ - lib/api_browser/app/views/builtin/field-selector.html
684
704
  - lib/api_browser/app/views/controller.html
685
705
  - lib/api_browser/app/views/directives/attribute_description.html
686
706
  - lib/api_browser/app/views/directives/attribute_description/default.html
@@ -689,13 +709,17 @@ files:
689
709
  - lib/api_browser/app/views/directives/attribute_description/member_options.html
690
710
  - lib/api_browser/app/views/directives/attribute_description/values.html
691
711
  - lib/api_browser/app/views/directives/attribute_table.html
712
+ - lib/api_browser/app/views/directives/menu_item.html
713
+ - lib/api_browser/app/views/directives/url.html
692
714
  - lib/api_browser/app/views/home.html
693
715
  - lib/api_browser/app/views/layout.html
694
716
  - lib/api_browser/app/views/menu.html
695
717
  - lib/api_browser/app/views/navbar.html
718
+ - lib/api_browser/app/views/trait.html
696
719
  - lib/api_browser/app/views/type.html
697
720
  - lib/api_browser/app/views/type/details.html
698
721
  - lib/api_browser/app/views/types/embedded/default.html
722
+ - lib/api_browser/app/views/types/embedded/field-selector.html
699
723
  - lib/api_browser/app/views/types/embedded/links.html
700
724
  - lib/api_browser/app/views/types/embedded/struct.html
701
725
  - lib/api_browser/app/views/types/label/link.html
@@ -703,6 +727,7 @@ files:
703
727
  - lib/api_browser/app/views/types/label/primitive_collection.html
704
728
  - lib/api_browser/app/views/types/label/type.html
705
729
  - lib/api_browser/app/views/types/label/type_collection.html
730
+ - lib/api_browser/app/views/types/standalone/array.html
706
731
  - lib/api_browser/app/views/types/standalone/default.html
707
732
  - lib/api_browser/app/views/types/standalone/struct.html
708
733
  - lib/api_browser/bower.json
@@ -739,6 +764,11 @@ files:
739
764
  - lib/praxis/exceptions/invalid_trait.rb
740
765
  - lib/praxis/exceptions/stage_not_found.rb
741
766
  - lib/praxis/exceptions/validation.rb
767
+ - lib/praxis/extensions/field_expansion.rb
768
+ - lib/praxis/extensions/field_selection.rb
769
+ - lib/praxis/extensions/field_selection/field_selector.rb
770
+ - lib/praxis/extensions/mapper_selectors.rb
771
+ - lib/praxis/extensions/rendering.rb
742
772
  - lib/praxis/file_group.rb
743
773
  - lib/praxis/handlers/json.rb
744
774
  - lib/praxis/handlers/plain.rb
@@ -794,6 +824,7 @@ files:
794
824
  - lib/praxis/version.rb
795
825
  - praxis.gemspec
796
826
  - spec/api_browser/directives/type_placeholder_spec.js
827
+ - spec/api_browser/factories/configuration_spec.js
797
828
  - spec/api_browser/factories/documentation_spec.js
798
829
  - spec/api_browser/factories/normalize_attributes_spec.js
799
830
  - spec/api_browser/factories/template_for_spec.js
@@ -806,9 +837,13 @@ files:
806
837
  - spec/praxis/application_spec.rb
807
838
  - spec/praxis/bootloader_spec.rb
808
839
  - spec/praxis/callbacks_spec.rb
840
+ - spec/praxis/collection_spec.rb
809
841
  - spec/praxis/config_spec.rb
810
842
  - spec/praxis/controller_spec.rb
811
843
  - spec/praxis/dispatcher_spec.rb
844
+ - spec/praxis/extensions/field_expansion_spec.rb
845
+ - spec/praxis/extensions/field_selection/field_selector_spec.rb
846
+ - spec/praxis/extensions/rendering_spec.rb
812
847
  - spec/praxis/file_group_spec.rb
813
848
  - spec/praxis/handlers/json_spec.rb
814
849
  - spec/praxis/handlers/xml_spec.rb
@@ -835,7 +870,6 @@ files:
835
870
  - spec/praxis/stage_spec.rb
836
871
  - spec/praxis/stats_spec.rb
837
872
  - spec/praxis/trait_spec.rb
838
- - spec/praxis/types/collection_spec.rb
839
873
  - spec/praxis/types/fuzzy_hash_spec.rb
840
874
  - spec/praxis/types/multipart_array/part_definition_spec.rb
841
875
  - spec/praxis/types/multipart_array_spec.rb
@@ -921,7 +955,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
921
955
  version: '0'
922
956
  requirements: []
923
957
  rubyforge_project:
924
- rubygems_version: 2.4.5.1
958
+ rubygems_version: 2.4.5
925
959
  signing_key:
926
960
  specification_version: 4
927
961
  summary: Building APIs the way you want it.