scrapbook 0.2.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/LICENSE.txt +202 -0
- data/README.md +142 -0
- data/Rakefile +7 -0
- data/app/assets/builds/scrapbook/tailwind.css +1 -0
- data/app/assets/config/scrapbook_manifest.js +1 -0
- data/app/assets/stylesheets/scrapbook/application.css +15 -0
- data/app/assets/stylesheets/scrapbook/application.tailwind.css +32 -0
- data/app/controllers/scrapbook/application_controller.rb +10 -0
- data/app/controllers/scrapbook/empty_controller.rb +9 -0
- data/app/controllers/scrapbook/pages_controller.rb +75 -0
- data/app/helpers/scrapbook/application_helper.rb +14 -0
- data/app/helpers/scrapbook/folder_listing_view_model.rb +53 -0
- data/app/helpers/scrapbook/helper_for_view.rb +27 -0
- data/app/mailers/scrapbook/application_mailer.rb +8 -0
- data/app/models/scrapbook/scrapbook.rb +51 -0
- data/app/views/layouts/scrapbook/_folder_listing.html.erb +9 -0
- data/app/views/layouts/scrapbook/application.html.erb +15 -0
- data/app/views/layouts/scrapbook/host_application.html.erb +11 -0
- data/app/views/pages.html.erb +1 -0
- data/app/views/scrapbook/pages/index.html.erb +1 -0
- data/app/views/scrapbook/pages/show.html.erb +1 -0
- data/config/routes.rb +16 -0
- data/lib/generators/scrapbook/install_generator.rb +16 -0
- data/lib/generators/scrapbook/new_generator.rb +23 -0
- data/lib/generators/scrapbook/routes_generator.rb +21 -0
- data/lib/scrapbook/engine.rb +26 -0
- data/lib/scrapbook/version.rb +5 -0
- data/lib/scrapbook.rb +10 -0
- data/lib/tasks/scrapbook_tasks.rake +5 -0
- metadata +97 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ca937f0e8c26f5b3ea2676b64135cf711e53ce2e17ac407c67abc7f934bfc482
|
|
4
|
+
data.tar.gz: 90069e6ac7f4e344b8a6f245dc8e8c2fc02c5b052df51fec6fea7cac7658c9e2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d53088db3d75baeca477c9358ffe7c52483e9f13a370d5c1c4a021ec5017f5d0d108bea466d9194547bd6258852ca2e2b47b2dc468ef66126f784302d88be911
|
|
7
|
+
data.tar.gz: d337a10422bed9966cb1cba24fa8362b63a8f5afed5e16572dc13248679a0d993c122fd06972ff8fd89eed2257892698ec33052c4d8d6945cabfc9788507d361
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
Copyright 2022 Brad Lindsay
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
193
|
+
use this file except in compliance with the License. You may obtain a copy
|
|
194
|
+
of the License at:
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
200
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
201
|
+
License for the specific language governing permissions and limitations
|
|
202
|
+
under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Scrapbook
|
|
2
|
+
|
|
3
|
+
Scrapbook allows you to create a heirarchal set of view templates that can run code from
|
|
4
|
+
your Rails application without the need to create a route or controller for each template.
|
|
5
|
+
All you need to do is install and configure Scrapbook, and then you can add folders and
|
|
6
|
+
template files to your heart's content.
|
|
7
|
+
|
|
8
|
+
Scrapbook started life wanting to be able to test out Rails helper methods and showcase
|
|
9
|
+
their behavior. These helper methods called more complex Ruby classes to create a set of
|
|
10
|
+
rich components, and we needed a way to showcase these components and their capabilites.
|
|
11
|
+
I decided to create a more general application that could allow us to generate and organize
|
|
12
|
+
any view templates that our Rails application knew how to process. Scrapbook is the result.
|
|
13
|
+
Along the way, we discovered that not only was it a great place to document our components,
|
|
14
|
+
but it was also great for doing the initial development as well.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add `scrapbook` to the `:development` group of your application's Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
group :development do
|
|
23
|
+
gem 'scrapbook'
|
|
24
|
+
end
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
And then execute:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$> bundle install
|
|
31
|
+
$> bundle exec rails generate scrapbook:install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This will install the gem and setup the default Scrapbook route and create the default
|
|
35
|
+
scrapbook directory structure at the root of your Rails application.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
A scrapbook folder needs to contain a "pages" sub-folder. Any files and folders created in
|
|
40
|
+
that "pages" folder will be exposed as part of the scrapbook unless their name begins with a
|
|
41
|
+
period. These files and folders will show up as navigatable in Scrapbook's file browser, and
|
|
42
|
+
if the file is a template file whose engine your main Rails application has installed, it
|
|
43
|
+
will be properly processed to generate the HTML for you to view. These templates have access
|
|
44
|
+
to all the helper methods defined in your main Rails application.
|
|
45
|
+
|
|
46
|
+
When a folder is selected in Scrapbook's file browser, by default a small message appears in
|
|
47
|
+
the main display area describing how to customize what is displayed when a folder is
|
|
48
|
+
selected. In short, you need to create a template file with the same base name as the folder
|
|
49
|
+
in the same directory as the folder. So if you had a folder at "scrapbook/pages/scratch",
|
|
50
|
+
then you would need to create a file named something like "scrapbook/pages/scratch.html.erb"
|
|
51
|
+
with the custom display you want to see when you click on the "scratch" folder in the file
|
|
52
|
+
browser. This also works for the main screen you see at the base scrapbook URL. You can
|
|
53
|
+
customize that screen by creating a "pages.html" template file in the root scrapbook folder.
|
|
54
|
+
(The default installation creates a "pages.html.erb" template file for the basic welcome
|
|
55
|
+
message.)
|
|
56
|
+
|
|
57
|
+
To view a scrapbook, navigate to its base URL. The default scarpbook can always be accessed
|
|
58
|
+
at the mountpoint setup in the routes file (this is "/scrapbook" by default). The base URL
|
|
59
|
+
for other scrapbooks is that path followed by the name of the scrapbook's root folder (the
|
|
60
|
+
folder that contains the "pages" folder). By default, only one scrapbook is configured and
|
|
61
|
+
it's name is "scrapbook" which means that both "/scrapbook" and "/scrapbook/scrapbook" point
|
|
62
|
+
to the same scrapbook root page.
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
You can configure the path that Scrapbook runs on in your "config/routes.rb" file. The
|
|
67
|
+
default configuration is to mount Scrapbook on "/scrapbook", but you can use whatever
|
|
68
|
+
path you want: `mount Scrapbook::Engine => "/scrappy"`.
|
|
69
|
+
|
|
70
|
+
You can configure one or more folders to be separate root scrapbooks via the
|
|
71
|
+
`config.scrapbook.paths` option. This option defaults to an empty array which allows for
|
|
72
|
+
using the shovel operator to add your paths:
|
|
73
|
+
```ruby
|
|
74
|
+
Rails.application.configure do
|
|
75
|
+
config.scrapbook.paths << Rails.root.join("scrapbooks/main")
|
|
76
|
+
config.scrapbook.paths << Rails.root.join("scrapbooks/scratch")
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
If no paths have been added, Scrapbook will use `Rails.root.join('scrapbook')` as the
|
|
80
|
+
location it expects the scrapbook to be at. The first folder path in the array is considered
|
|
81
|
+
the default scrapbook and will be available at the root mount point configured in the routes
|
|
82
|
+
file.
|
|
83
|
+
|
|
84
|
+
We recommend only running Scrapbook in development / non-production Rails environments.
|
|
85
|
+
However, if you find yourself needing to be able to run it in an environment precompiles its
|
|
86
|
+
assets, you will need to configure Scrapbook to be part of the precompilation. You can do
|
|
87
|
+
this by setting `config.scrapbook.precompile_assets` to "true":
|
|
88
|
+
```ruby
|
|
89
|
+
Rails.application.configure do
|
|
90
|
+
config.scrapbook.precompile_assets = true
|
|
91
|
+
end
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## Contributing
|
|
96
|
+
|
|
97
|
+
If you have a question about Scrapbook, feel free to ask in [the repository's Discussions]
|
|
98
|
+
[Discussions]. Before starting any work or creating any issues, please read [the
|
|
99
|
+
contribution guidelines](CONTRIBUTING.md).
|
|
100
|
+
|
|
101
|
+
## Development Setup
|
|
102
|
+
|
|
103
|
+
### Install TailwindCSS CLI
|
|
104
|
+
|
|
105
|
+
If you need to submit updates to the theme or are using new Tailwind classes, you'll need to
|
|
106
|
+
follow [the instructions to install the CLI](https://tailwindcss.com/docs/installation).
|
|
107
|
+
After that you'll need to run the following commands to install the plugins:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
$> npm install -D @tailwindcss/forms
|
|
111
|
+
$> npm install -D @tailwindcss/aspect-ratio
|
|
112
|
+
$> npm install -D @tailwindcss/typography
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Once Tailwind's CLI has been installed, you can run it using the command below to update
|
|
116
|
+
Scrapbook's CSS:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
$> npx tailwindcss -i app/assets/stylesheets/scrapbook/application.tailwind.css -o app/assets/builds/scrapbook/tailwind.css --minify --watch
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
(Note, the "tailwindcss-rails" gem currently doesn't support Rails engines, so we have to
|
|
123
|
+
install and run Tailwind manually.)
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
Copyright 2022 Brad Lindsay
|
|
128
|
+
|
|
129
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
130
|
+
you may not use this file except in compliance with the License.
|
|
131
|
+
You may obtain a copy of the License at
|
|
132
|
+
|
|
133
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
134
|
+
|
|
135
|
+
Unless required by applicable law or agreed to in writing, software
|
|
136
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
137
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
138
|
+
See the License for the specific language governing permissions and
|
|
139
|
+
limitations under the License.
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
[Discussion]: https://github.com/bfad/scrapbook/discussions
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tailwindcss v3.0.23 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input:-ms-input-placeholder,textarea:-ms-input-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}[multiple],[type=date],[type=datetime-local],[type=email],[type=month],[type=number],[type=password],[type=search],[type=tel],[type=text],[type=time],[type=url],[type=week],select,textarea{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:#fff;border-color:#6b7280;border-width:1px;border-radius:0;padding:.5rem .75rem;font-size:1rem;line-height:1.5rem;--tw-shadow:0 0 #0000}[multiple]:focus,[type=date]:focus,[type=datetime-local]:focus,[type=email]:focus,[type=month]:focus,[type=number]:focus,[type=password]:focus,[type=search]:focus,[type=tel]:focus,[type=text]:focus,[type=time]:focus,[type=url]:focus,[type=week]:focus,select:focus,textarea:focus{outline:2px solid #0000;outline-offset:2px;--tw-ring-inset:var(--tw-empty,/*!*/ /*!*/);--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#2563eb;--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow);border-color:#2563eb}input::-moz-placeholder,textarea::-moz-placeholder{color:#6b7280;opacity:1}input:-ms-input-placeholder,textarea:-ms-input-placeholder{color:#6b7280;opacity:1}input::placeholder,textarea::placeholder{color:#6b7280;opacity:1}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-date-and-time-value{min-height:1.5em}::-webkit-datetime-edit,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-meridiem-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-year-field{padding-top:0;padding-bottom:0}select{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");background-position:right .5rem center;background-repeat:no-repeat;background-size:1.5em 1.5em;padding-right:2.5rem;-webkit-print-color-adjust:exact;color-adjust:exact}[multiple]{background-image:none;background-position:0 0;background-repeat:unset;background-size:initial;padding-right:.75rem;-webkit-print-color-adjust:unset;color-adjust:unset}[type=checkbox],[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;-webkit-print-color-adjust:exact;color-adjust:exact;display:inline-block;vertical-align:middle;background-origin:border-box;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;flex-shrink:0;height:1rem;width:1rem;color:#2563eb;background-color:#fff;border-color:#6b7280;border-width:1px;--tw-shadow:0 0 #0000}[type=checkbox]{border-radius:0}[type=radio]{border-radius:100%}[type=checkbox]:focus,[type=radio]:focus{outline:2px solid #0000;outline-offset:2px;--tw-ring-inset:var(--tw-empty,/*!*/ /*!*/);--tw-ring-offset-width:2px;--tw-ring-offset-color:#fff;--tw-ring-color:#2563eb;--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}[type=checkbox]:checked,[type=radio]:checked{border-color:#0000;background-color:currentColor;background-size:100% 100%;background-position:50%;background-repeat:no-repeat}[type=checkbox]:checked{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 16 16' fill='%23fff' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12.207 4.793a1 1 0 0 1 0 1.414l-5 5a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L6.5 9.086l4.293-4.293a1 1 0 0 1 1.414 0z'/%3E%3C/svg%3E")}[type=radio]:checked{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 16 16' fill='%23fff' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='8' cy='8' r='3'/%3E%3C/svg%3E")}[type=checkbox]:checked:focus,[type=checkbox]:checked:hover,[type=checkbox]:indeterminate,[type=radio]:checked:focus,[type=radio]:checked:hover{border-color:#0000;background-color:currentColor}[type=checkbox]:indeterminate{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3E%3Cpath stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3E%3C/svg%3E");background-size:100% 100%;background-position:50%;background-repeat:no-repeat}[type=checkbox]:indeterminate:focus,[type=checkbox]:indeterminate:hover{border-color:#0000;background-color:currentColor}[type=file]{background:unset;border-color:inherit;border-width:0;border-radius:0;padding:0;font-size:unset;line-height:inherit}[type=file]:focus{outline:1px auto -webkit-focus-ring-color}body>nav li{cursor:default}body>nav a,body>nav a:active,body>nav a:hover,body>nav a:visited{color:#0f172a;cursor:default;text-decoration:none;transition:background-color 80ms linear;font-weight:400;font-size:unset;line-height:inherit}body>nav a:hover{background-color:#f0f9ff}body>nav a:active{background-color:#bae6fd}*,:after,:before{--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.block{display:block}.flex{display:flex}.contents{display:contents}.h-screen{height:100vh}.h-full{height:100%}.w-screen{width:100vw}.w-full{width:100%}.min-w-\[20ch\]{min-width:20ch}.max-w-\[50\%\]{max-width:50%}.flex-none{flex:none}.overflow-scroll{overflow:scroll}.border-0{border-width:0}.border-r{border-right-width:1px}.border-solid{border-style:solid}.border-sky-700{--tw-border-opacity:1;border-color:rgb(3 105 161/var(--tw-border-opacity))}.bg-sky-100{--tw-bg-opacity:1;background-color:rgb(224 242 254/var(--tw-bg-opacity))}.\!px-0{padding-left:0!important;padding-right:0!important}.py-2{padding-top:.5rem;padding-bottom:.5rem}.px-4{padding-left:1rem;padding-right:1rem}.text-2xl{font-size:1.5rem;line-height:2rem}.children\:px-4>*{padding-left:1rem;padding-right:1rem}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= link_directory ../stylesheets/scrapbook .css
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
@layer base {
|
|
6
|
+
/* Not sure base is correct here */
|
|
7
|
+
body > nav li {
|
|
8
|
+
cursor: default;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
body > nav a,
|
|
12
|
+
body > nav a:hover,
|
|
13
|
+
body > nav a:active,
|
|
14
|
+
body > nav a:visited
|
|
15
|
+
{
|
|
16
|
+
color: theme('colors.slate.900');
|
|
17
|
+
cursor: default;
|
|
18
|
+
text-decoration: none;
|
|
19
|
+
transition: background-color 80ms linear;
|
|
20
|
+
font-weight: normal;
|
|
21
|
+
font-size: unset;
|
|
22
|
+
line-height:inherit;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
body > nav a:hover {
|
|
26
|
+
background-color: theme('colors.sky.50');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
body > nav a:active {
|
|
30
|
+
background-color: theme('colors.sky.200');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scrapbook
|
|
4
|
+
# @todo Document this controller
|
|
5
|
+
class PagesController < ApplicationController
|
|
6
|
+
self.view_paths = Engine.config.paths['app/views'].to_a
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
return head(:not_found) if (scrapbook = find_scrapbook).nil?
|
|
10
|
+
return head(:not_found) unless (pathname = calculate_pathname(scrapbook, params[:path])).directory?
|
|
11
|
+
|
|
12
|
+
if pathname == scrapbook.pages_pathname
|
|
13
|
+
prepend_view_path(scrapbook.root)
|
|
14
|
+
render template: 'pages', locals: {scrapbook: scrapbook, pathname: pathname}
|
|
15
|
+
else
|
|
16
|
+
render locals: {scrapbook: scrapbook, pathname: pathname}
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def show
|
|
21
|
+
return head(:not_found) if (scrapbook = find_scrapbook).nil?
|
|
22
|
+
|
|
23
|
+
pathname = calculate_pathname(scrapbook, params[:id])
|
|
24
|
+
template = params[:id].delete_suffix('.html')
|
|
25
|
+
|
|
26
|
+
if !scrapbook_template_exists?(scrapbook, template) && pathname.directory?
|
|
27
|
+
render 'scrapbook/pages/index', locals: {scrapbook: scrapbook, pathname: pathname}
|
|
28
|
+
else
|
|
29
|
+
render locals: {scrapbook: scrapbook, pathname: pathname}, formats: [:html]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def raw
|
|
34
|
+
return head(:not_found) if (scrapbook = find_scrapbook).nil?
|
|
35
|
+
|
|
36
|
+
pathname = calculate_pathname(scrapbook, params[:id])
|
|
37
|
+
template = params[:id].delete_suffix('.html')
|
|
38
|
+
|
|
39
|
+
if scrapbook_template_exists?(scrapbook, template)
|
|
40
|
+
prepend_view_path(scrapbook.pages_pathname)
|
|
41
|
+
render template: template,
|
|
42
|
+
locals: {scrapbook: scrapbook, pathname: pathname},
|
|
43
|
+
layout: 'layouts/scrapbook/host_application'
|
|
44
|
+
elsif pathname.exist?
|
|
45
|
+
render file: pathname
|
|
46
|
+
else
|
|
47
|
+
head :not_found
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def find_scrapbook
|
|
54
|
+
scrapbook_path = if params[:book].present?
|
|
55
|
+
::Scrapbook::Engine.config.scrapbook.paths.find { File.basename(_1) == params[:book] }
|
|
56
|
+
else
|
|
57
|
+
::Scrapbook::Engine.config.scrapbook.paths.first
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
scrapbook_path && Scrapbook.new(scrapbook_path)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def calculate_pathname(scrapbook, path)
|
|
64
|
+
if path.present?
|
|
65
|
+
scrapbook.pages_pathname.join(path)
|
|
66
|
+
else
|
|
67
|
+
scrapbook.pages_pathname
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def scrapbook_template_exists?(scrapbook, template)
|
|
72
|
+
EmptyController.new.tap { |c| c.prepend_view_path(scrapbook.pages_pathname) }.template_exists?(template)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scrapbook
|
|
4
|
+
# Engine-wide helpers
|
|
5
|
+
module ApplicationHelper
|
|
6
|
+
# Using `include Rails.application.helpers` didn't work for reloading changes
|
|
7
|
+
# made to the main app's helper methods, but this is adapted from its code.
|
|
8
|
+
# (I think it's getting around the memoized "@helpers" variable.)
|
|
9
|
+
# https://github.com/rails/rails/blob/6bfc637659248df5d6719a86d2981b52662d9b50/railties/lib/rails/engine.rb#L494
|
|
10
|
+
ActionController::Base.modules_for_helpers(
|
|
11
|
+
ActionController::Base.all_helpers_from_path(Rails.application.helpers_paths)
|
|
12
|
+
).each { include _1 }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scrapbook
|
|
4
|
+
# Model to assest list a folder's contents
|
|
5
|
+
class FolderListingViewModel
|
|
6
|
+
attr_reader :view, :scrapbook, :pathname, :files, :folders
|
|
7
|
+
|
|
8
|
+
def initialize(view, scrapbook, pathname)
|
|
9
|
+
self.view = view
|
|
10
|
+
self.scrapbook = scrapbook
|
|
11
|
+
self.pathname = pathname.directory? ? pathname : pathname.dirname
|
|
12
|
+
self.folders, self.files = split_files_and_folders
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def root?
|
|
16
|
+
pathname == scrapbook.pages_pathname
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def parent_display_name
|
|
20
|
+
return nil if root?
|
|
21
|
+
return scrapbook.name if pathname.parent == scrapbook.pages_pathname
|
|
22
|
+
|
|
23
|
+
pathname.parent.basename.to_s
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def header_name
|
|
27
|
+
root? ? "/#{scrapbook.name}" : "/#{pathname.basename}/"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
attr_writer :view, :scrapbook, :pathname, :files, :folders
|
|
33
|
+
|
|
34
|
+
def split_files_and_folders
|
|
35
|
+
helper = HelperForView.new(view)
|
|
36
|
+
|
|
37
|
+
folders, files = pathname.children.each_with_object([[], []]) do |pname, acc|
|
|
38
|
+
next if pname.basename.to_s.start_with?('.')
|
|
39
|
+
|
|
40
|
+
if pname.directory?
|
|
41
|
+
acc[0] << pname
|
|
42
|
+
else
|
|
43
|
+
acc[1] << helper.remove_handler_exts_from(pname)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
folders.sort! { |a, b| a.to_s.downcase <=> b.to_s.downcase }
|
|
48
|
+
files.sort! { |a, b| a.to_s.downcase <=> b.to_s.downcase }
|
|
49
|
+
|
|
50
|
+
[folders, files]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scrapbook
|
|
4
|
+
# View helpers for the Scrapbook gem. Doesn't use standard Rail's helper
|
|
5
|
+
# modules to avoid any conflicts with host app
|
|
6
|
+
class HelperForView
|
|
7
|
+
def initialize(view)
|
|
8
|
+
self.view = view
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def short_path_to(pathname, scrapbook = nil)
|
|
12
|
+
scrapbook ||= Scrapbook.find_scrapbook_for(pathname)
|
|
13
|
+
|
|
14
|
+
view.short_page_path(scrapbook.relative_page_path_for(pathname)).gsub(/%2F/i, '/')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def remove_handler_exts_from(pathname)
|
|
18
|
+
pathname.dirname.join(
|
|
19
|
+
pathname.basename.sub(/(?:.#{view.lookup_context.handlers.join('|.')})+\z/, '')
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
attr_accessor :view
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scrapbook
|
|
4
|
+
# Modeling the scrap book
|
|
5
|
+
class Scrapbook
|
|
6
|
+
NotFoundError = Class.new(StandardError)
|
|
7
|
+
|
|
8
|
+
attr_accessor :root
|
|
9
|
+
|
|
10
|
+
def self.find_scrapbook_for(pathname)
|
|
11
|
+
scrapbooks = ::Scrapbook::Engine.config.scrapbook.paths
|
|
12
|
+
candidates = scrapbooks.each_with_index.filter_map do |pname, index|
|
|
13
|
+
relative_path = pathname.relative_path_from(pname)
|
|
14
|
+
next if relative_path.to_s.start_with?('..')
|
|
15
|
+
|
|
16
|
+
[index, relative_path.each_filename.count]
|
|
17
|
+
end
|
|
18
|
+
raise NotFoundError if candidates.empty?
|
|
19
|
+
|
|
20
|
+
new(scrapbooks[candidates.min_by { _1[1] }.first])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def initialize(root)
|
|
24
|
+
self.root = Pathname.new(root)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def name
|
|
28
|
+
root.basename
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def pages_pathname
|
|
32
|
+
root.join('pages')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def relative_page_path_for(pathname)
|
|
36
|
+
return '' if pathname == pages_pathname
|
|
37
|
+
|
|
38
|
+
relative_path = pathname.relative_path_from(pages_pathname).to_s
|
|
39
|
+
if relative_path.start_with?('..')
|
|
40
|
+
raise ArgumentError, "Pathname isn't inside the scrapbook pages: #{relative_path}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
relative_path
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def ==(other)
|
|
47
|
+
other.class == self.class && other.root == root
|
|
48
|
+
end
|
|
49
|
+
alias eql? ==
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%
|
|
2
|
+
helper = Scrapbook::HelperForView.new(self)
|
|
3
|
+
listing = Scrapbook::FolderListingViewModel.new(self, scrapbook, pathname)
|
|
4
|
+
pathname_without_handler_exts = helper.remove_handler_exts_from(pathname)
|
|
5
|
+
%>
|
|
6
|
+
<% unless listing.root? %><%= link_to "‹ #{listing.parent_display_name}", helper.short_path_to(listing.pathname.parent), class: 'back-to-parent block w-100' %><% end %>
|
|
7
|
+
<header aria-label="Which folder's contents" class="text-2xl <%= listing.pathname == pathname ? 'bg-sky-100' : '!px-0 children:px-4' %>"><% if listing.pathname == pathname %><span aria-current="page"><%= listing.header_name %></span><% else %><%= link_to(listing.header_name, helper.short_path_to(listing.pathname), class: 'block w-100') %><% end %></header>
|
|
8
|
+
<ul class="!px-0" aria-label="Sub-folders"><% listing.folders.each do |folder| %><li class="children:px-4"><%= link_to "#{folder.basename}/", helper.short_path_to(folder, scrapbook), class: 'block w-100' %></li><% end %></ul>
|
|
9
|
+
<ul class="!px-0" aria-label="Sub-files"><% listing.files.each do |file| %><% next if listing.folders.include?(file) %><li class="children:px-4"><% if file == pathname_without_handler_exts %><span class="block w-100 bg-sky-100" aria-current="page"><%= file.basename %></span><% else %><%= link_to file.basename, helper.short_path_to(file, scrapbook), class: 'block w-100' %><% end %></li><% end %></ul>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title><%= local_assigns[:scrapbook].name || 'Scrapbook' %>: <%= content_for?(:title) ? yield(:title) : local_assigns[:pathname].basename %></title>
|
|
5
|
+
<%= csrf_meta_tags %>
|
|
6
|
+
<%= csp_meta_tag %>
|
|
7
|
+
|
|
8
|
+
<%= stylesheet_link_tag "scrapbook/tailwind", "data-turbo-track": "reload" %>
|
|
9
|
+
<%= stylesheet_link_tag "scrapbook/application", media: "all" %>
|
|
10
|
+
</head>
|
|
11
|
+
<body class="flex">
|
|
12
|
+
<nav class="flex-none min-w-[20ch] max-w-[50%] h-screen overflow-scroll children:px-4 py-2 border-solid border-sky-700 border-0 border-r"><%= render 'layouts/scrapbook/folder_listing', scrapbook: local_assigns[:scrapbook], pathname: local_assigns[:pathname] %></nav>
|
|
13
|
+
<main class="py-2 px-4 h-screen w-screen overflow-scroll"><%= yield %></main>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This directory has no corresponding template. You can add a template named "pages" to the Scrapbook root directory and its contents will show up here.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This directory has no corresponding template. You can add a template with the same name as the directory as a sibling to the directory and its contents will show up here.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<iframe src="<%= raw_page_path(book: scrapbook.name, id: scrapbook.relative_page_path_for(pathname)) %>" class="w-full h-full"></iframe>
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Scrapbook::Engine.routes.draw do
|
|
4
|
+
book_regex = /#{Scrapbook::Engine.config.scrapbook.paths.map { File.basename(_1) }.join('|')}/
|
|
5
|
+
|
|
6
|
+
resources :pages, id: /.+/
|
|
7
|
+
resources :pages, path: ':book/pages', id: /.+/, constraints: {book: book_regex}
|
|
8
|
+
|
|
9
|
+
get ':book', to: 'pages#index', constraints: {book: book_regex}
|
|
10
|
+
root 'pages#index'
|
|
11
|
+
|
|
12
|
+
get '.raw/:book/pages/*id', to: 'pages#raw', as: :raw_page,
|
|
13
|
+
constraints: {book: book_regex, id: /.*/}, defaults: {raw: true}
|
|
14
|
+
get ':book/*id', to: 'pages#show', constraints: {book: book_regex, id: /.*/}
|
|
15
|
+
get '*id', to: 'pages#show', constraints: {id: /.*/}, as: :short_page
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
|
|
5
|
+
module Scrapbook
|
|
6
|
+
# Initial default setup of Scrapbook
|
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
|
8
|
+
class_option 'url-path', default: '/scrapbook'
|
|
9
|
+
class_option 'path-with-name', default: 'scrapbook'
|
|
10
|
+
|
|
11
|
+
def install
|
|
12
|
+
generate 'scrapbook:routes', options.fetch('url-path')
|
|
13
|
+
generate 'scrapbook:new', options.fetch('path-with-name')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
|
|
5
|
+
module Scrapbook
|
|
6
|
+
# A generator to create a new scrapbook at either the default (scrapbook) or specified
|
|
7
|
+
# path from the Rails application root.
|
|
8
|
+
class NewGenerator < Rails::Generators::Base
|
|
9
|
+
argument :name, optional: true, default: 'scrapbook'
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
create_file("#{name}/pages/.keep")
|
|
13
|
+
|
|
14
|
+
# TODO: Investigate using hooks to default to ERB, but allow templates to overwrite
|
|
15
|
+
create_file("#{name}/pages.html.erb",
|
|
16
|
+
<<~HTML
|
|
17
|
+
<h1>Welcome to Scrapbook</h1>
|
|
18
|
+
<p>Feel free to customize this page and add more folders and pages to your Scrapbook</p>
|
|
19
|
+
HTML
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
|
|
5
|
+
module Scrapbook
|
|
6
|
+
# A generator to create a new scrapbook at either the default (scrapbook) or specified
|
|
7
|
+
# path from the Rails application root.
|
|
8
|
+
class RoutesGenerator < Rails::Generators::Base
|
|
9
|
+
argument :path, optional: true, default: '/scrapbook'
|
|
10
|
+
|
|
11
|
+
def routes
|
|
12
|
+
# TODO: Investigate using a Rubocop rule to determine using single or double auotes.
|
|
13
|
+
url_path = path.start_with?('/') ? path : "/#{path}"
|
|
14
|
+
route <<~ROUTES
|
|
15
|
+
if Rails.env.development?
|
|
16
|
+
mount Scrapbook::Engine => '#{url_path}'
|
|
17
|
+
end
|
|
18
|
+
ROUTES
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scrapbook
|
|
4
|
+
# :nodoc:
|
|
5
|
+
class Engine < ::Rails::Engine
|
|
6
|
+
isolate_namespace Scrapbook
|
|
7
|
+
|
|
8
|
+
config.scrapbook = ActiveSupport::OrderedOptions.new
|
|
9
|
+
config.scrapbook.paths ||= []
|
|
10
|
+
config.scrapbook.precompile_assets = config.scrapbook.precompile_assets || false
|
|
11
|
+
|
|
12
|
+
initializer 'scrapbook.configuration' do |app|
|
|
13
|
+
settings = app.config.scrapbook
|
|
14
|
+
|
|
15
|
+
settings.paths << Rails.root.join('scrapbook') if settings.paths.empty?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
initializer 'scrapbook.assets' do |app|
|
|
19
|
+
if app.config.scrapbook.precompile_assets && app.config.respond_to?(:assets)
|
|
20
|
+
app.config.assets.precompile.concat %w[
|
|
21
|
+
scrapbook/tailwind.css
|
|
22
|
+
]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/scrapbook.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: scrapbook
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brad Lindsay
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-07-18 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: '7.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '7.1'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '7.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '7.1'
|
|
33
|
+
description: Scrapbook allows you to collect and document complex view helpers or
|
|
34
|
+
partials.
|
|
35
|
+
email:
|
|
36
|
+
- sluggy.fan@gmail.com
|
|
37
|
+
executables: []
|
|
38
|
+
extensions: []
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
files:
|
|
41
|
+
- LICENSE.txt
|
|
42
|
+
- README.md
|
|
43
|
+
- Rakefile
|
|
44
|
+
- app/assets/builds/scrapbook/tailwind.css
|
|
45
|
+
- app/assets/config/scrapbook_manifest.js
|
|
46
|
+
- app/assets/stylesheets/scrapbook/application.css
|
|
47
|
+
- app/assets/stylesheets/scrapbook/application.tailwind.css
|
|
48
|
+
- app/controllers/scrapbook/application_controller.rb
|
|
49
|
+
- app/controllers/scrapbook/empty_controller.rb
|
|
50
|
+
- app/controllers/scrapbook/pages_controller.rb
|
|
51
|
+
- app/helpers/scrapbook/application_helper.rb
|
|
52
|
+
- app/helpers/scrapbook/folder_listing_view_model.rb
|
|
53
|
+
- app/helpers/scrapbook/helper_for_view.rb
|
|
54
|
+
- app/mailers/scrapbook/application_mailer.rb
|
|
55
|
+
- app/models/scrapbook/scrapbook.rb
|
|
56
|
+
- app/views/layouts/scrapbook/_folder_listing.html.erb
|
|
57
|
+
- app/views/layouts/scrapbook/application.html.erb
|
|
58
|
+
- app/views/layouts/scrapbook/host_application.html.erb
|
|
59
|
+
- app/views/pages.html.erb
|
|
60
|
+
- app/views/scrapbook/pages/index.html.erb
|
|
61
|
+
- app/views/scrapbook/pages/show.html.erb
|
|
62
|
+
- config/routes.rb
|
|
63
|
+
- lib/generators/scrapbook/install_generator.rb
|
|
64
|
+
- lib/generators/scrapbook/new_generator.rb
|
|
65
|
+
- lib/generators/scrapbook/routes_generator.rb
|
|
66
|
+
- lib/scrapbook.rb
|
|
67
|
+
- lib/scrapbook/engine.rb
|
|
68
|
+
- lib/scrapbook/version.rb
|
|
69
|
+
- lib/tasks/scrapbook_tasks.rake
|
|
70
|
+
homepage: https://bfad.github.io/scrapbook
|
|
71
|
+
licenses:
|
|
72
|
+
- Apache-2.0
|
|
73
|
+
metadata:
|
|
74
|
+
homepage_uri: https://bfad.github.io/scrapbook
|
|
75
|
+
source_code_uri: https://github.com/bfad/scrapbook
|
|
76
|
+
changelog_uri: https://github.com/bfad/scrapbook/blob/main/CHANGELOG.md
|
|
77
|
+
rubygems_mfa_required: 'true'
|
|
78
|
+
post_install_message:
|
|
79
|
+
rdoc_options: []
|
|
80
|
+
require_paths:
|
|
81
|
+
- lib
|
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: 2.7.0
|
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - ">="
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '0'
|
|
92
|
+
requirements: []
|
|
93
|
+
rubygems_version: 3.3.4
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: A place to document and test view helpers for Ruby on Rails
|
|
97
|
+
test_files: []
|