lookbook 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +257 -0
  4. data/app/assets/lookbook/css/app.css +37 -0
  5. data/app/assets/lookbook/css/code_theme.css +214 -0
  6. data/app/assets/lookbook/css/tooltip_theme.css +16 -0
  7. data/app/assets/lookbook/js/app.js +47 -0
  8. data/app/assets/lookbook/js/preview.js +76 -0
  9. data/app/assets/lookbook/js/reloader.js +28 -0
  10. data/app/assets/lookbook/js/size_observer.js +16 -0
  11. data/app/assets/lookbook/js/split.js +26 -0
  12. data/app/channels/lookbook/connection.rb +11 -0
  13. data/app/channels/lookbook/reload_channel.rb +7 -0
  14. data/app/controllers/lookbook/browser_controller.rb +141 -0
  15. data/app/helpers/lookbook/application_helper.rb +24 -0
  16. data/app/views/lookbook/browser/error.html.erb +1 -0
  17. data/app/views/lookbook/browser/index.html.erb +8 -0
  18. data/app/views/lookbook/browser/not_found.html.erb +25 -0
  19. data/app/views/lookbook/browser/show.html.erb +33 -0
  20. data/app/views/lookbook/layouts/app.html.erb +49 -0
  21. data/app/views/lookbook/partials/_icon_sprite.html.erb +1 -0
  22. data/app/views/lookbook/partials/_preview.html.erb +18 -0
  23. data/app/views/lookbook/partials/_sidebar.html.erb +21 -0
  24. data/app/views/lookbook/partials/inspector/_code.html.erb +1 -0
  25. data/app/views/lookbook/partials/inspector/_inspector.html.erb +43 -0
  26. data/app/views/lookbook/partials/inspector/_plain.html.erb +3 -0
  27. data/app/views/lookbook/partials/inspector/_prose.html.erb +3 -0
  28. data/app/views/lookbook/partials/nav/_collection.html.erb +17 -0
  29. data/app/views/lookbook/partials/nav/_label.html.erb +13 -0
  30. data/app/views/lookbook/partials/nav/_nav.html.erb +27 -0
  31. data/app/views/lookbook/partials/nav/_preview.html.erb +48 -0
  32. data/config/lookbook_cable.yml +8 -0
  33. data/config/routes.rb +8 -0
  34. data/lib/lookbook.rb +14 -0
  35. data/lib/lookbook/collection.rb +51 -0
  36. data/lib/lookbook/engine.rb +96 -0
  37. data/lib/lookbook/lang.rb +42 -0
  38. data/lib/lookbook/navigation.rb +68 -0
  39. data/lib/lookbook/parser.rb +33 -0
  40. data/lib/lookbook/preview.rb +86 -0
  41. data/lib/lookbook/preview_controller.rb +17 -0
  42. data/lib/lookbook/preview_example.rb +68 -0
  43. data/lib/lookbook/taggable.rb +23 -0
  44. data/lib/lookbook/version.rb +3 -0
  45. data/lib/tasks/lookbook_tasks.rake +15 -0
  46. data/public/lookbook-assets/app.css +2361 -0
  47. data/public/lookbook-assets/app.js +7692 -0
  48. metadata +242 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 30e9c49fca5a575af92323c59fd35018ddcd92798939a87286915060f2f93401
4
+ data.tar.gz: d90162b2ea72fcc7fc5fe38478b3ced236649421fdc08f0554acead3f5a41213
5
+ SHA512:
6
+ metadata.gz: 7dcac40f9c516acbb996dae1ab5e26026fe7a98cd607b066572f22a958101d5cdad4b447a9d50348f694f198b5dba3f10682d8236dfc9eb0ea0ff4c415c177e0
7
+ data.tar.gz: 372f92f28d094d502dafe5acdc7ce243034542432a33ac5fa1075f62cb1aebfeed3f02913cabc08690b467b6bd16b46d380cdfb2c1dfd3c16bd814d03773c18e
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 allmarkedup
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,257 @@
1
+ <div align="center">
2
+ <h2>Lookbook</h2>
3
+
4
+ 👀 A native development UI for [ViewComponent](http://viewcomponent.org/) 👀
5
+
6
+ </div>
7
+
8
+ ---
9
+
10
+ Lookbook gives [ViewComponent](http://viewcomponent.org/)-based projects a _ready-to-go_ development UI for navigating, inspecting and interacting with component previews.
11
+
12
+ It uses (and extends) the native [ViewComponent preview functionality](https://viewcomponent.org/guide/previews.html) and is intended to integrate seamlessly with existing component libraries.
13
+
14
+ Lookbook uses [RDoc/Yard-style comment tags](https://rubydoc.info/gems/yard/file/docs/Tags.md) to extend the capabilities of ViewComponent's previews whilst maintaining compatability with the standard preview class format, so you can add or remove Lookbook at any time without having to rework your code.
15
+
16
+ > ⚠️ **PLEASE NOTE!** Lookbook is very much a **work in progress** at the moment. There may be breaking changes on point-releases before a 1.0 version is ready. ⚠️
17
+
18
+ ![Lookbook UI](.github/assets/lookbook_screenshot.png)
19
+
20
+ ### Features
21
+
22
+ - 👀 Navigate your component previews with ease
23
+ - 🔍 Search/filter previews
24
+ - 🖥 Resizable, responsive preview window
25
+ - 🔦 Highlighted preview source code and HTML output (with one-click copy to clipboard)
26
+ - 📝 Add notes via comments in the preview file (markdown supported)
27
+ - 🚀 Live UI, auto-updates when component or previews files are updated
28
+ - 🙈 Supports 'hidden' previews and examples
29
+
30
+ ## Lookbook demo
31
+
32
+ If you want to have a quick play with Lookbook, the easiest way is to [give the demo app](https://github.com/allmarkedup/lookbook-demo) a spin. It's a basic Rails/ViewComponent app with a few test components included to tinker with.
33
+
34
+ The [demo app repo](https://github.com/allmarkedup/lookbook-demo) contains instructions on how to get it up and running.
35
+
36
+ ## Installing
37
+
38
+ Lookbook is current a work in progress and **has not been published as a Gem** yet.
39
+
40
+ If you wish to play with it in it's current state you can include it directly from Github using the instructions below.
41
+
42
+ ### 1. Add as a dependency
43
+
44
+ In your `Gemfile` add:
45
+
46
+ ```ruby
47
+ gem "lookbook", '>= 0.1', git: "https://github.com/allmarkedup/lookbook", branch: "main"
48
+ ```
49
+
50
+ This line should be placed <strong>below</strong> wherever you have specified the `view_component` gem.
51
+
52
+ ### 2. Mount the Lookbook engine
53
+
54
+ You then need to mount the Lookbook engine (at a path of your choosing) in your `routes.rb` file:
55
+
56
+ ```ruby
57
+ Rails.application.routes.draw do
58
+ # any other routes...
59
+ if Rails.env.development?
60
+ mount Lookbook::Engine, at: "/lookbook"
61
+ end
62
+ end
63
+ ```
64
+
65
+ The `at` property determines the root URL that the Lookbook UI will be served at.
66
+
67
+ > If you would like to expose the Lookbook UI in production as well as in development, just remove the `if Rails.env.development?` wrapper from the mount statement.
68
+
69
+ Then you can start your app as normal and navigate to `http://localhost:3000/lookbook` (or whatever mount path you specified) to view your component previews in the Lookbook UI.
70
+
71
+ ## Usage
72
+
73
+ You don't need to do anything special to create ViewComponent previews for Lookbook.
74
+
75
+ Lookbook will use the [ViewComponent configuration options](https://viewcomponent.org/api.html#configuration) for your project to find and render your components so you don't need to configure anything separately (unless you want to tweak the behaviour or look of Lookbook itself).
76
+
77
+ > If you are new to ViewComponent development, checkout the [ViewComponent docs](https://viewcomponent.org/guide/) on how to get started developing your components and creating previews.
78
+
79
+ Lookbook uses the exact same [preview files](https://viewcomponent.org/guide/previews.html) as 'regular' ViewComponent previews, so using preview templates, custom layouts and even bespoke [preview controllers](https://viewcomponent.org/guide/previews.html#configuring-preview-controller) all works as you would expect.
80
+
81
+ ### Comment tags
82
+
83
+ Lookbook uses [Yard-style tags](https://rubydoc.info/gems/yard/file/docs/Tags.md) in class and method comments to extract additional information about previews and examples.
84
+
85
+ Tags are just strings identified by their `@` prefix - for example `@hidden`. Tags are always placed in a comment above the relevant preview class or example method. The comments can still contain any other text, and multiple tags can be included in any one comment. For example:
86
+
87
+ ```ruby
88
+ # This is a class-level comment.
89
+ # @hidden
90
+ class MyClass
91
+ # This is a method-level comment.
92
+ # @hidden
93
+ def my_method
94
+ end
95
+ end
96
+ ```
97
+
98
+ Some tags can also require additional arguments. Further informatin on the tags Lookbook uses are detailed in the docs below.
99
+
100
+ ### 📝 Adding notes to previews
101
+
102
+ Lookbook lets you add notes to your preview examples which are then displayed in the inspector panel. They look something like this:
103
+
104
+ <img src=".github/assets/preview_example_notes.png" width="400">
105
+
106
+ Notes are generated from comments above example methods in your preview files. Below is an example of two preview examples that both have notes:
107
+
108
+ ```ruby
109
+ class ButtonComponentPreview < ViewComponent::Preview
110
+
111
+ # Add notes as comments above the example methods.
112
+ # Multi-line is just fine and **markdown** is supported too!
113
+ #
114
+ # It's a good place to put usage and implementation instructions
115
+ # for people browsing the component previews in the UI.
116
+ def default
117
+ render ButtonComponent.new(text: "Click me")
118
+ end
119
+
120
+ # Each preview example has it's own notes, extracted from the method comments.
121
+ def danger
122
+ render ButtonComponent.new(text: "Don't do it!", theme: :danger)
123
+ end
124
+ end
125
+ ```
126
+
127
+ ### 👀 Navigation customisation
128
+
129
+ Lookbook generates a nested navigation menu based on the file structure of your component preview directories. This can be customised in a number of ways.
130
+
131
+ #### Preview and example labels
132
+
133
+ By default, the labels shown for previews and examples are stripped and 'titlized' versions of the preview file names and the example method names, respectively.
134
+
135
+ If you wish to override the automatic navigation label generation for a preview or example you can use the `@label` comment tag:
136
+
137
+ ```ruby
138
+ # @label Standard Button
139
+ class BtnPreview < ViewComponent::Preview
140
+
141
+ # @label Icon Button
142
+ def with_icon
143
+ end
144
+ end
145
+ ```
146
+
147
+ In the example above, the preview and example would be displayed like this:
148
+
149
+ <img src=".github/assets/nav_labels.png" width="200">
150
+
151
+ #### Excluding previews and/or examples from the navigation
152
+
153
+ Sometimes you may want a preview or an individual example to be 'hidden' in the Lookbook UI. This means that the preview or example will not show up in the navigation, but will still be accessible via it's URL. You can use the `@hidden` comment tag to manage this.
154
+
155
+ To **hide an entire preview** so that it no longer shows up in the , include the `@hidden` tag in a class comment:
156
+
157
+ ```ruby
158
+ # @hidden
159
+ class MyComponentPreview < ViewComponent::Preview
160
+ # examples here....
161
+ end
162
+ ```
163
+
164
+ To **hide an individual example**, include the `@hidden` tag in the appropriate method comment:
165
+
166
+ ```ruby
167
+ class MyComponentPreview < ViewComponent::Preview
168
+
169
+ # Hidden Example
170
+ # ----------
171
+ # You won't see this in the nav!
172
+ #
173
+ # @hidden
174
+ def hidden_example
175
+ # ...
176
+ end
177
+
178
+ def a_visible_example
179
+ # ...
180
+ end
181
+
182
+ # @hidden
183
+ def another_hidden_example
184
+ # ...
185
+ end
186
+ end
187
+ ```
188
+
189
+ ### 🔦 Viewing source code and rendered HTML output
190
+
191
+ Lookbook displays the source code of the current preview (or the contents of preview template, if one is being used), right underneath the rendered preview itself:
192
+
193
+ <img src=".github/assets/preview_source.png" width="400">
194
+
195
+ You can also inspect the HTML output of the rendered preview (without any of the layout cruft):
196
+
197
+ <img src=".github/assets/preview_output.png" width="400">
198
+
199
+ All code panels have a 'copy-to-clipboard' button at the top right of the panel, just click it to copy the un-highlighted code to your clipboard.
200
+
201
+ <img src=".github/assets/copy_to_clipboard.png" width="400">
202
+
203
+ ## Configuration
204
+
205
+ Lookbook uses ViewComponent's configuration options for anything to do with previews, paths and general setup, so you won't need to duplicate any settings.
206
+
207
+ However the following Lookbook-specific config options are also available:
208
+
209
+ ### UI auto-refresh
210
+
211
+ Disable/enable the auto-updating of the Lookbook UI when files change. Enabled by default.
212
+
213
+ ```ruby
214
+ config.lookbook.auto_refresh = false # default is true
215
+ ```
216
+
217
+ By default Lookbook will listen for changes in any [preview directories](https://viewcomponent.org/api.html#preview_paths) as well as in the [components directory](config.view_component.preview_paths) itself.
218
+
219
+ If you wish to add additional paths to listen for changes in, you can use the `listen_paths` option:
220
+
221
+ ```ruby
222
+ config.lookbook.listen_paths << Rails.root.join('app/other/directory')
223
+ ```
224
+
225
+ ## Contributing
226
+
227
+ Lookbook is very much a small hobby/side project at the moment. I'd love to hear from anyone who is interested in contributing but I'm terrible at replying to emails or messages, so don't be surprised if I take forever to get back to you. It's not personal 😜
228
+
229
+ However, I'm a frontend developer - not a Rails dev - so any thoughts, advice or PRs on how to improve the codebase will be always much appreciated. 🍻
230
+
231
+ ### Developing on a local version of Lookbook
232
+
233
+ The quickest way to get a development version of Lookbook up and running is to use the [lookbook-demo](https://github.com/allmarkedup/lookbook-demo) app and link it to a local version of the Lookbook gem:
234
+
235
+ #### Initial setup:
236
+
237
+ 1. Clone this repository somewhere on your machine - `git clone git@github.com:allmarkedup/lookbook.git`
238
+ 2. Also pull down the [lookbook-demo](https://github.com/allmarkedup/lookbook-demo) repository to your machine
239
+ 3. In the `Gemfile` of the `lookbook-demo` repository, replace `gem "lookbook", '>= 0.1', git: "https://github.com/allmarkedup/lookbook", branch: "main"` with `gem "lookbook", path: "../path/to/lookbook"` (use the path to your local copy of lookbook)
240
+ 4. Install dependencies - from the root of the parent project run `bundle install`
241
+
242
+ #### Starting development
243
+
244
+ 1. From within the `lookbook` root directory run the comand `npm run dev` (this will make sure the CSS/JS is recompiled if/when you make changes to the UI)
245
+ 2. From within the `lookbook-demo` root directory run `npm run start` - this will start a server and build the demo assets
246
+
247
+ Point your browser to http://localhost:3000/lookbook to see the UI. You can then make and test changes to the Lookbook code in your local copy of lookbook repo. PRs are welcome if you add anything useful :-)
248
+
249
+ > Note that changes to files in the Lookbook `lib/` directory will require a server restart in order to have them applied.
250
+
251
+ #### Tests
252
+
253
+ You can run the tests from within the `lookbook` root directory with the `rake test` command.
254
+
255
+ ## License
256
+
257
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
1
+ @import "tailwindcss/base";
2
+ @import "tailwindcss/components";
3
+ @import "tailwindcss/utilities";
4
+ @import "tippy.js/dist/tippy";
5
+ @import "code_theme";
6
+ @import "tooltip_theme";
7
+
8
+ @layer base {
9
+ html {
10
+ scroll-behavior: smooth;
11
+ }
12
+
13
+ @media screen and (prefers-reduced-motion: reduce) {
14
+ html {
15
+ scroll-behavior: auto;
16
+ }
17
+ }
18
+
19
+ [x-cloak] {
20
+ display: none !important;
21
+ }
22
+
23
+ pre[class*="language-"] {
24
+ padding: 0 !important;
25
+ margin: 0 !important;
26
+ }
27
+
28
+ .feather {
29
+ width: 24px;
30
+ height: 24px;
31
+ stroke: currentColor;
32
+ stroke-width: 2;
33
+ stroke-linecap: round;
34
+ stroke-linejoin: round;
35
+ fill: none;
36
+ }
37
+ }
@@ -0,0 +1,214 @@
1
+ /*
2
+ * GitHub style for Pygments
3
+ * Courtesy of GitHub.com
4
+ */
5
+
6
+ .highlight .hll {
7
+ background-color: #f8f8f8;
8
+ border: 1px solid #ccc;
9
+ padding: 6px 10px;
10
+ border-radius: 3px;
11
+ }
12
+ .highlight .c {
13
+ color: #999988;
14
+ font-style: italic;
15
+ }
16
+ .highlight .err {
17
+ color: #a61717;
18
+ background-color: #e3d2d2;
19
+ }
20
+ .highlight .k {
21
+ font-weight: bold;
22
+ }
23
+ .highlight .o {
24
+ font-weight: bold;
25
+ }
26
+ .highlight .cm {
27
+ color: #999988;
28
+ font-style: italic;
29
+ }
30
+ .highlight .cp {
31
+ color: #999999;
32
+ font-weight: bold;
33
+ }
34
+ .highlight .c1 {
35
+ color: #999988;
36
+ font-style: italic;
37
+ }
38
+ .highlight .cs {
39
+ color: #999999;
40
+ font-weight: bold;
41
+ font-style: italic;
42
+ }
43
+ .highlight .gd {
44
+ color: #000000;
45
+ background-color: #ffdddd;
46
+ }
47
+ .highlight .gd .x {
48
+ color: #000000;
49
+ background-color: #ffaaaa;
50
+ }
51
+ .highlight .ge {
52
+ font-style: italic;
53
+ }
54
+ .highlight .gr {
55
+ color: #aa0000;
56
+ }
57
+ .highlight .gh {
58
+ color: #999999;
59
+ }
60
+ .highlight .gi {
61
+ color: #000000;
62
+ background-color: #ddffdd;
63
+ }
64
+ .highlight .gi .x {
65
+ color: #000000;
66
+ background-color: #aaffaa;
67
+ }
68
+ .highlight .go {
69
+ color: #888888;
70
+ }
71
+ .highlight .gp {
72
+ color: #555555;
73
+ }
74
+ .highlight .gs {
75
+ font-weight: bold;
76
+ }
77
+ .highlight .gu {
78
+ color: #800080;
79
+ font-weight: bold;
80
+ }
81
+ .highlight .gt {
82
+ color: #aa0000;
83
+ }
84
+ .highlight .kc {
85
+ font-weight: bold;
86
+ }
87
+ .highlight .kd {
88
+ font-weight: bold;
89
+ }
90
+ .highlight .kn {
91
+ font-weight: bold;
92
+ }
93
+ .highlight .kp {
94
+ font-weight: bold;
95
+ }
96
+ .highlight .kr {
97
+ font-weight: bold;
98
+ }
99
+ .highlight .kt {
100
+ color: #445588;
101
+ font-weight: bold;
102
+ }
103
+ .highlight .m {
104
+ color: #009999;
105
+ }
106
+ .highlight .s {
107
+ color: #dd1144;
108
+ }
109
+ .highlight .n {
110
+ color: #333333;
111
+ }
112
+ .highlight .na {
113
+ color: teal;
114
+ }
115
+ .highlight .nb {
116
+ color: #0086b3;
117
+ }
118
+ .highlight .nc {
119
+ color: #445588;
120
+ font-weight: bold;
121
+ }
122
+ .highlight .no {
123
+ color: teal;
124
+ }
125
+ .highlight .ni {
126
+ color: purple;
127
+ }
128
+ .highlight .ne {
129
+ color: #990000;
130
+ font-weight: bold;
131
+ }
132
+ .highlight .nf {
133
+ color: #990000;
134
+ font-weight: bold;
135
+ }
136
+ .highlight .nn {
137
+ color: #555555;
138
+ }
139
+ .highlight .nt {
140
+ color: navy;
141
+ }
142
+ .highlight .nv {
143
+ color: teal;
144
+ }
145
+ .highlight .ow {
146
+ font-weight: bold;
147
+ }
148
+ .highlight .w {
149
+ color: #bbbbbb;
150
+ }
151
+ .highlight .mf {
152
+ color: #009999;
153
+ }
154
+ .highlight .mh {
155
+ color: #009999;
156
+ }
157
+ .highlight .mi {
158
+ color: #009999;
159
+ }
160
+ .highlight .mo {
161
+ color: #009999;
162
+ }
163
+ .highlight .sb {
164
+ color: #dd1144;
165
+ }
166
+ .highlight .sc {
167
+ color: #dd1144;
168
+ }
169
+ .highlight .sd {
170
+ color: #dd1144;
171
+ }
172
+ .highlight .s2 {
173
+ color: #dd1144;
174
+ }
175
+ .highlight .se {
176
+ color: #dd1144;
177
+ }
178
+ .highlight .sh {
179
+ color: #dd1144;
180
+ }
181
+ .highlight .si {
182
+ color: #dd1144;
183
+ }
184
+ .highlight .sx {
185
+ color: #dd1144;
186
+ }
187
+ .highlight .sr {
188
+ color: #009926;
189
+ }
190
+ .highlight .s1 {
191
+ color: #dd1144;
192
+ }
193
+ .highlight .ss {
194
+ color: #990073;
195
+ }
196
+ .highlight .bp {
197
+ color: #999999;
198
+ }
199
+ .highlight .vc {
200
+ color: teal;
201
+ }
202
+ .highlight .vg {
203
+ color: teal;
204
+ }
205
+ .highlight .vi {
206
+ color: teal;
207
+ }
208
+ .highlight .il {
209
+ color: #009999;
210
+ }
211
+ .highlight .gc {
212
+ color: #999;
213
+ background-color: #eaf2f5;
214
+ }