basemate-ui-core 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +495 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/basemate_ui_core_manifest.js +2 -0
  6. data/app/assets/javascripts/basemate/ui/core/application.js +15 -0
  7. data/app/assets/stylesheets/basemate/ui/core/application.css +15 -0
  8. data/app/concepts/app/cell/app.rb +75 -0
  9. data/app/concepts/app/js/app.js +27 -0
  10. data/app/concepts/app/js/store.js +66 -0
  11. data/app/concepts/app/utils/app_node.rb +53 -0
  12. data/app/concepts/app/view/app.haml +4 -0
  13. data/app/concepts/component/cell/dynamic.rb +110 -0
  14. data/app/concepts/component/cell/static.rb +14 -0
  15. data/app/concepts/component/js/component.js +38 -0
  16. data/app/concepts/component/view/children.haml +2 -0
  17. data/app/concepts/component/view/dynamic.haml +6 -0
  18. data/app/concepts/component/view/static.haml +1 -0
  19. data/app/concepts/core/js/core.js +20 -0
  20. data/app/concepts/div/cell/div.rb +5 -0
  21. data/app/concepts/div/view/div.haml +3 -0
  22. data/app/concepts/header/cell/header.rb +5 -0
  23. data/app/concepts/header/view/header.haml +3 -0
  24. data/app/concepts/heading/cell/heading.rb +5 -0
  25. data/app/concepts/heading/view/heading.haml +50 -0
  26. data/app/concepts/html/cell/html.rb +17 -0
  27. data/app/concepts/html/js/html.js +10 -0
  28. data/app/concepts/html/view/html.haml +3 -0
  29. data/app/concepts/img/cell/img.rb +5 -0
  30. data/app/concepts/img/view/img.haml +1 -0
  31. data/app/concepts/link/cell/link.rb +14 -0
  32. data/app/concepts/link/view/link.haml +6 -0
  33. data/app/concepts/main/cell/main.rb +5 -0
  34. data/app/concepts/main/view/main.haml +3 -0
  35. data/app/concepts/nav/cell/nav.rb +5 -0
  36. data/app/concepts/nav/view/nav.haml +3 -0
  37. data/app/concepts/navigation/cell/button.rb +5 -0
  38. data/app/concepts/navigation/view/button.haml +3 -0
  39. data/app/concepts/page/cell/content.rb +5 -0
  40. data/app/concepts/page/cell/page.rb +110 -0
  41. data/app/concepts/page/utils/page_node.rb +51 -0
  42. data/app/concepts/page/view/content.haml +7 -0
  43. data/app/concepts/page/view/page.haml +3 -0
  44. data/app/concepts/partial/cell/partial.rb +5 -0
  45. data/app/concepts/partial/view/partial.haml +3 -0
  46. data/app/concepts/plain/cell/plain.rb +10 -0
  47. data/app/concepts/section/cell/section.rb +5 -0
  48. data/app/concepts/section/view/section.haml +3 -0
  49. data/app/concepts/shared/utils/to_cell.rb +27 -0
  50. data/app/concepts/span/cell/span.rb +5 -0
  51. data/app/concepts/span/view/span.haml +3 -0
  52. data/app/concepts/transition/cell/transition.rb +18 -0
  53. data/app/concepts/transition/js/transition.js +26 -0
  54. data/app/concepts/transition/view/transition.haml +6 -0
  55. data/app/controllers/basemate/ui/core/application_controller.rb +9 -0
  56. data/app/helpers/basemate/ui/core/application_helper.rb +35 -0
  57. data/config/routes.rb +2 -0
  58. data/lib/basemate/ui/core.rb +14 -0
  59. data/lib/basemate/ui/core/engine.rb +19 -0
  60. data/lib/basemate/ui/core/version.rb +7 -0
  61. data/lib/tasks/basemate/ui/core_tasks.rake +4 -0
  62. metadata +190 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6ad2b4fc6829e694d57e640aa01dd4b6e8d688d5cf93f28f0902554ea1537c0a
4
+ data.tar.gz: feec335328d3d9cebe70fd82adf119e12732ae2bdbe638c8200c5c3a6f834e9c
5
+ SHA512:
6
+ metadata.gz: b356cb9294da5b08026ca74b508501f86ddaa080cc9159c8020ac2ddd0d60d3ba2088041e5c9421e03a46b4bb5d6b3b90208bf63dc52611fa213b706992f9604
7
+ data.tar.gz: b6c20d2c6e68d5143370ef6fa0b7b3240c30f3f25b1d36c430995a4fdf749f92d35d7282da8779add5c6054509eb6665345cecab20c15d658851ba609d2d6852
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Jonas Jabari
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,495 @@
1
+ # Basemate::Ui::Core
2
+
3
+ Create component based, object oriented views. Get dynamic SPA-like behaviour
4
+ through integrated vue.js with zero effort.
5
+
6
+ ## Purpose
7
+
8
+ TODO
9
+
10
+ ## Why basemate?
11
+
12
+ TODO
13
+
14
+ ## Current State
15
+ This repo is currently under heavy development and should not be used until the
16
+ first tested, stable version is released. Please use it only after being
17
+ onboarded by the basemate team. Feel free to reach out if you really can't
18
+ wait to start :)
19
+
20
+ First stable release is scheduled for mid October 2018.
21
+
22
+ ## Table of Contents
23
+ 1. [Setup](#setup)
24
+ 2. [Usage](#usage)
25
+ 3. [Customize](#customize)
26
+ 4. [Bundles](#bundles)
27
+ 5. [Themes](#themes)
28
+ 6. [Contribution](#contribution)
29
+ 7. [License](#license)
30
+
31
+ ## Setup
32
+ This setup part documents the simplest approach to use Basemate::Ui::Core
33
+ without any basemate bundle or theme involved. Assets are compiled and served
34
+ only via sprockets. This makes it very easy to integrate it in a classic Rails
35
+ project without any further dependencies.
36
+ **Do not use this setup if you want to build custom vue.js components.**
37
+ If you want to extend basemate by building your own vue.js components,
38
+ use Webpacker (see: [Setup with Webpacker](#setup-with-webpacker)).
39
+
40
+ ### Gemfile
41
+
42
+ Add 'basemate-ui-core' to your Gemfile
43
+
44
+ ```ruby
45
+ gem 'basemate-ui-core', :git => 'https://github.com/basemate/basemate-ui-core.git'
46
+ ```
47
+
48
+ and run
49
+ ````
50
+ $ bundle install
51
+ ````
52
+
53
+ ### Javascript
54
+
55
+ Require 'basemate-ui-core' in your assets/javascript/application.js
56
+
57
+ ```
58
+ //= require basemate-ui-core
59
+ ```
60
+
61
+ ### Basemate Folder
62
+
63
+ Create a folder called 'basemate' in your app directory. All your basemate apps,
64
+ pages, components (and more to come) will be defined there.
65
+
66
+ ### Include Helper
67
+
68
+ Add the basemate Helper to your controllers. If you want to make the helpers
69
+ available in all controllers, add it to your 'ApplicationController' this way:
70
+
71
+ app/controllers/application_controller.rb
72
+ ```ruby
73
+ class ApplicationController < ActionController::Base
74
+ include Basemate::Ui::Core::ApplicationHelper
75
+ end
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ - [Basemate Page](#basemate-page)
81
+ - [Setup](#basic-page-setup)
82
+ - [Partials](#structure-your-basemate-page-response-with-partials)
83
+ - [Prepare Block](#use-the-prepare-method-to-implement-page-related-business-logic)
84
+ - [Iterators](#use-iterators)
85
+ - [Basemate App](#basemate-app)
86
+ - [Setup](#basic-app-setup)
87
+
88
+ ### Basemate Page
89
+
90
+ #### Basic Page Setup
91
+ Scenario: You want to use a basemate Page instead of a classic Rails view as a
92
+ response for a controller action. This is what your setup looks like:
93
+
94
+ Your routes:
95
+
96
+ config/routes.rb
97
+ ```ruby
98
+ Rails.application.routes.draw do
99
+ get '/home', to:'website#home'
100
+ end
101
+ ```
102
+
103
+ Your Application Layout:
104
+
105
+ app/views/layouts/application.html.erb
106
+ ```erb
107
+ <!DOCTYPE html>
108
+ <html>
109
+ <head>
110
+ <title>My App</title>
111
+ <%= csrf_meta_tags %>
112
+ <%= csp_meta_tag %>
113
+
114
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
115
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
116
+ </head>
117
+
118
+ <body>
119
+ <div id="basemate_ui">
120
+ <%= yield %>
121
+ </div>
122
+ </body>
123
+ </html>
124
+ ```
125
+ Note: Wrap your content with a div and assgin the id "basemate_ui"
126
+
127
+ Your Controller Action:
128
+
129
+ app/controllers/website_controller.rb
130
+ ```ruby
131
+ class WebsiteController < ApplicationController
132
+
133
+ def home
134
+ @foo = "foo"
135
+ @bar = "bar"
136
+ responder_for(Website::Home) #-> Basemate::Ui::Core::ApplicationHelper
137
+ end
138
+
139
+ end
140
+ ```
141
+
142
+ Your basemate Page:
143
+
144
+ app/basemate/website/home.rb
145
+ ```ruby
146
+ module Website
147
+ class Home < Page::Cell::Page
148
+
149
+ def response
150
+
151
+ components {
152
+ row do
153
+ col do
154
+ plain @foo
155
+ end
156
+ col id: "my_special_col" do
157
+ plain @bar
158
+ end
159
+ end
160
+ }
161
+
162
+ end
163
+
164
+ end
165
+ end
166
+ ```
167
+ This gives you following output:
168
+
169
+ ```html
170
+ <div id='website_home'>
171
+ <div class='row' id="row_1">
172
+ <div class='col' id="row_1__col_1">
173
+ foo
174
+ </div>
175
+ <div class='col' id="my_special_col">
176
+ bar
177
+ </div>
178
+ </div>
179
+ </div>
180
+ ```
181
+ As you can see, each component receives an id that is automatically created
182
+ using the components' name. Those ids should help you style specific parts of
183
+ your page later on, and can be overwritten in the page response if you need more freedom.
184
+
185
+ Note:
186
+ - "row", "col", "plain" are predefined core components
187
+ - a documentation of predefined core component can be found here: TODO
188
+ - row/col class setup for bootstrap 4.x and material-design-lite can be found here:
189
+ - bootstrap 4.x: TODO
190
+ - material-design-lite: TODO
191
+ - you can customize the output of the core components
192
+ - see: [Customize](#customize)
193
+ - you can add your own components
194
+ - see: [Customize](#customize)
195
+ - you can use styles from Basemate Themes
196
+ - see: [Themes](#themes)
197
+ - you can use components from Basemate Bundles
198
+ - see: [Bundles](#bundles)
199
+
200
+ #### Structure your basemate Page response with partials
201
+
202
+ If you don't want to define the response of you page in one block, you can use
203
+ partials.
204
+
205
+ Let's take our app/basemate/website/home.rb and refactor it from this:
206
+
207
+ ```ruby
208
+ module Website
209
+ class Home < Page::Cell::Page
210
+
211
+ def response
212
+
213
+ components {
214
+ row do
215
+ col do
216
+ plain @foo
217
+ end
218
+ col do
219
+ plain @bar
220
+ end
221
+ end
222
+ row do
223
+ col do
224
+ plain "hello"
225
+ end
226
+ col do
227
+ plain "world"
228
+ end
229
+ end
230
+ }
231
+
232
+ end
233
+
234
+ end
235
+ end
236
+
237
+ ```
238
+
239
+ to this:
240
+
241
+ ```ruby
242
+ module Website
243
+ class Home < Page::Cell::Page
244
+
245
+ def response
246
+ components {
247
+ partial :row_1
248
+ partial :row_2
249
+ }
250
+ end
251
+
252
+ def row_1
253
+ partial {
254
+ row do
255
+ col do
256
+ plain @foo
257
+ end
258
+ col do
259
+ plain @bar
260
+ end
261
+ end
262
+ }
263
+ end
264
+
265
+ def row_2
266
+ partial {
267
+ row do
268
+ col do
269
+ plain "hello"
270
+ end
271
+ col do
272
+ plain "world"
273
+ end
274
+ end
275
+ }
276
+ end
277
+
278
+
279
+ end
280
+ end
281
+
282
+ ```
283
+
284
+ You could also implement dynamic partials, for example:
285
+
286
+ ```ruby
287
+ module Website
288
+ class Home < Page::Cell::Page
289
+
290
+ def response
291
+ components {
292
+ partial :row, @foo, @bar
293
+ partial :row, "hello", "world"
294
+ }
295
+ end
296
+
297
+ def row first_col, second_col
298
+ partial {
299
+ row do
300
+ col do
301
+ plain first_col
302
+ end
303
+ col do
304
+ plain second_col
305
+ end
306
+ end
307
+ }
308
+ end
309
+
310
+ end
311
+ end
312
+
313
+ ```
314
+ #### Use the Prepare method to implement page-related business logic
315
+
316
+ If you want to move code out of your controller action, you could place your
317
+ page-related business logic in the 'prepare'-method of your Basemate Page.
318
+
319
+
320
+ app/controllers/website_controller.rb
321
+ ```ruby
322
+ class WebsiteController < ApplicationController
323
+
324
+ def home
325
+ #@foo = "foo" #moved to prepare method
326
+ #@bar = "bar" #moved to prepare method
327
+ responder_for(Website::Home)
328
+ end
329
+
330
+ end
331
+
332
+ ```
333
+
334
+ app/basemate/website/home.rb
335
+ ```ruby
336
+ module Website
337
+ class Home < Page::Cell::Page
338
+
339
+ def prepare
340
+ @foo = "foo"
341
+ @bar = "bar"
342
+ end
343
+
344
+ def response
345
+ components {
346
+ row do
347
+ col do
348
+ plain @foo
349
+ end
350
+ col do
351
+ plain @bar
352
+ end
353
+ end
354
+ }
355
+ end
356
+
357
+ end
358
+ end
359
+
360
+ ```
361
+
362
+ #### Use Iterators
363
+
364
+ Often you need to iterate through some datastructure on your UI. Since you're
365
+ writing pure Ruby, it's straight forward. Iterations can use dynamic partials:
366
+
367
+ app/basemate/website/home.rb
368
+ ```ruby
369
+ module Website
370
+ class Home < Page::Cell::Page
371
+
372
+ def prepare
373
+ @team_members = ["Mike", "Laura", "John"]
374
+ end
375
+
376
+ def response
377
+ components {
378
+ @team_members.each do |member|
379
+ partial :member_profile, member
380
+ end
381
+ }
382
+ end
383
+
384
+ def member_profile member
385
+ partial {
386
+ row do
387
+ col do
388
+ plain member
389
+ end
390
+ end
391
+ }
392
+ end
393
+ end
394
+ end
395
+
396
+ ```
397
+
398
+ ### Basemate App
399
+
400
+ ### Basic App Setup
401
+
402
+ TODO
403
+
404
+
405
+ ## Customize
406
+
407
+ ### Customize Core Components
408
+
409
+ Add a ruby file to the correct basemate customize folder, for example:
410
+
411
+ app/basemate/customize/ui/core/row.rb
412
+ ```ruby
413
+
414
+ module Customize::Ui::Core
415
+ class Row
416
+
417
+ def row_classes(classes, options)
418
+ classes << "justify-content-md-center" if options[:center] == true
419
+ end
420
+
421
+ end
422
+ end
423
+ ```
424
+
425
+ and change your Basemate Page to use your new interface:
426
+
427
+ app/basemate/website/home.rb
428
+ ```ruby
429
+ module Website
430
+ class Home < Page::Cell::Page
431
+
432
+ def response
433
+
434
+ components {
435
+ row center: true do
436
+ col do
437
+ plain @foo
438
+ end
439
+ col do
440
+ plain @bar
441
+ end
442
+ end
443
+ }
444
+
445
+ end
446
+
447
+ end
448
+ end
449
+
450
+ ```
451
+ The result is the following, customized output:
452
+
453
+ ```html
454
+ <div class='row justify-content-md-center'>
455
+ <div class='col'>
456
+ foo
457
+ </div>
458
+ <div class='col'>
459
+ bar
460
+ </div>
461
+ </div>
462
+ ```
463
+ ### Create your own Component
464
+
465
+ TODO
466
+
467
+ ### Setup with Webpacker
468
+
469
+ TODO
470
+
471
+ ## Bundles
472
+
473
+ TODO
474
+
475
+ ## Templates
476
+
477
+ TODO
478
+
479
+ ## Contribution
480
+
481
+ ### Core
482
+
483
+ TODO
484
+
485
+ ### Bundles
486
+
487
+ TODO
488
+
489
+ ### Themes
490
+
491
+ TODO
492
+
493
+ ## License
494
+ The gem is available as open source under the terms of the
495
+ [MIT License](https://opensource.org/licenses/MIT).