scrapbook 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -22
- data/app/controllers/scrapbook/pages_controller.rb +25 -31
- data/app/helpers/scrapbook/helper_for_view.rb +1 -6
- data/app/models/scrapbook/scrapbook.rb +3 -3
- data/app/views/layouts/scrapbook/application.html.erb +1 -1
- data/app/views/pages.html.erb +2 -1
- data/app/views/scrapbook/pages/show.html.erb +1 -1
- data/config/routes.rb +6 -9
- data/lib/generators/scrapbook/install_generator.rb +3 -2
- data/lib/generators/scrapbook/routes_generator.rb +11 -9
- data/lib/scrapbook/engine.rb +1 -7
- data/lib/scrapbook/routing.rb +14 -0
- data/lib/scrapbook/version.rb +1 -1
- data/lib/scrapbook.rb +1 -0
- metadata +5 -5
- data/app/views/scrapbook/pages/index.html.erb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 215d5d39bc38386f6e2c7c08e2126e26718305961ae675a3b6d433b13ff5a4d9
|
4
|
+
data.tar.gz: 07662ed1539e36da1323a74fcb2f4314ea23546586d86036f90d60635b62c913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f2c0d4853af4a8fa82f5a9175874c082932ee36eb9825eccfe1f733afa8bb01025feaa70811321d1f118392ef7803a3da9c0b7addf240967262d6a23171fd6c
|
7
|
+
data.tar.gz: e6e4215895e268d0bb554c1b7fa88ffb1f60e3e18ae2a8ed29fdd62762585ea6998ef582528a637bb2e55f8f3a048e6599732807bfc10ae8c1a899cbd2ea2120
|
data/README.md
CHANGED
@@ -31,8 +31,9 @@ $> bundle install
|
|
31
31
|
$> bundle exec rails generate scrapbook:install
|
32
32
|
```
|
33
33
|
|
34
|
-
This will install the gem and setup
|
35
|
-
scrapbook
|
34
|
+
This will install the gem and then setup a scrapbook directory structure with a folder named
|
35
|
+
"scrapbook" at the root of your Rails application as well as modify your routes to make the
|
36
|
+
scrapbook available.
|
36
37
|
|
37
38
|
## Usage
|
38
39
|
|
@@ -48,38 +49,32 @@ the main display area describing how to customize what is displayed when a folde
|
|
48
49
|
selected. In short, you need to create a template file with the same base name as the folder
|
49
50
|
in the same directory as the folder. So if you had a folder at "scrapbook/pages/scratch",
|
50
51
|
then you would need to create a file named something like "scrapbook/pages/scratch.html.erb"
|
51
|
-
with the custom
|
52
|
+
with the custom view you want to see when you click on the "scratch" folder in the file
|
52
53
|
browser. This also works for the main screen you see at the base scrapbook URL. You can
|
53
54
|
customize that screen by creating a "pages.html" template file in the root scrapbook folder.
|
54
55
|
(The default installation creates a "pages.html.erb" template file for the basic welcome
|
55
56
|
message.)
|
56
57
|
|
57
|
-
To view a scrapbook, navigate to its base URL
|
58
|
-
|
59
|
-
|
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.
|
58
|
+
To view a scrapbook, navigate to its base URL setup by the route file configuration. (See
|
59
|
+
the documentation for the `scrapbook` route helper for more information on how to conigure
|
60
|
+
this route.)
|
63
61
|
|
64
62
|
## Configuration
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
The installation task adds `extend Scrapbook::Routing` to the routes configuration block
|
65
|
+
which gives it access to the `scrapbook` route helper. It also addds a scrapbook named
|
66
|
+
"scrapbook" using that helper (`scrapbook('scrapbook')`). You can modify that configuration,
|
67
|
+
specifying the location of the folder root or the URL path to mount the scrapbook at. You
|
68
|
+
can also add additional scrapbooks using this helper. For example:
|
69
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
70
|
```ruby
|
74
|
-
Rails.application.
|
75
|
-
|
76
|
-
|
71
|
+
Rails.application.routes.draw do
|
72
|
+
extend Scrapbook::Routing
|
73
|
+
|
74
|
+
scrapbook('main', at: '/scrapbook', folder_root: 'scrapbooks/main')
|
75
|
+
scrapbook('scratch', folder_root: 'scrapbooks/scratch')
|
77
76
|
end
|
78
77
|
```
|
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
78
|
|
84
79
|
We recommend only running Scrapbook in development / non-production Rails environments.
|
85
80
|
However, if you find yourself needing to be able to run it in an environment precompiles its
|
@@ -5,42 +5,30 @@ module Scrapbook
|
|
5
5
|
class PagesController < ApplicationController
|
6
6
|
self.view_paths = Engine.config.paths['app/views'].to_a
|
7
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
8
|
def show
|
21
9
|
return head(:not_found) if (scrapbook = find_scrapbook).nil?
|
22
10
|
|
23
11
|
pathname = calculate_pathname(scrapbook, params[:id])
|
24
|
-
template =
|
12
|
+
template = calculate_template
|
25
13
|
|
26
|
-
|
27
|
-
render 'scrapbook/pages/index', locals: {scrapbook: scrapbook, pathname: pathname}
|
28
|
-
else
|
29
|
-
render locals: {scrapbook: scrapbook, pathname: pathname}, formats: [:html]
|
30
|
-
end
|
14
|
+
render locals: {scrapbook: scrapbook, pathname: pathname}, formats: [:html]
|
31
15
|
end
|
32
16
|
|
33
17
|
def raw
|
34
18
|
return head(:not_found) if (scrapbook = find_scrapbook).nil?
|
35
19
|
|
36
20
|
pathname = calculate_pathname(scrapbook, params[:id])
|
37
|
-
template =
|
21
|
+
template = calculate_template
|
38
22
|
|
39
23
|
if scrapbook_template_exists?(scrapbook, template)
|
40
|
-
prepend_view_path(scrapbook.
|
24
|
+
prepend_view_path(scrapbook.root)
|
41
25
|
render template: template,
|
42
26
|
locals: {scrapbook: scrapbook, pathname: pathname},
|
43
27
|
layout: 'layouts/scrapbook/host_application'
|
28
|
+
elsif pathname.directory?
|
29
|
+
render '/pages',
|
30
|
+
locals: {scrapbook: scrapbook, pathname: pathname},
|
31
|
+
layout: 'layouts/scrapbook/host_application'
|
44
32
|
elsif pathname.exist?
|
45
33
|
render file: pathname
|
46
34
|
else
|
@@ -51,25 +39,31 @@ module Scrapbook
|
|
51
39
|
private
|
52
40
|
|
53
41
|
def find_scrapbook
|
54
|
-
|
55
|
-
::Scrapbook::Engine.config.scrapbook.paths.find { File.basename(_1) == params[:book] }
|
56
|
-
else
|
57
|
-
::Scrapbook::Engine.config.scrapbook.paths.first
|
58
|
-
end
|
42
|
+
return nil if book_name.blank?
|
59
43
|
|
44
|
+
scrapbook_path = Engine.config.scrapbook.paths[book_name]
|
60
45
|
scrapbook_path && Scrapbook.new(scrapbook_path)
|
61
46
|
end
|
62
47
|
|
63
48
|
def calculate_pathname(scrapbook, path)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
49
|
+
scrapbook.pages_pathname.join(path || '')
|
50
|
+
end
|
51
|
+
|
52
|
+
def calculate_template
|
53
|
+
return 'pages' if params[:id].blank?
|
54
|
+
|
55
|
+
"pages/#{params[:id].delete_suffix('.html')}"
|
69
56
|
end
|
70
57
|
|
71
58
|
def scrapbook_template_exists?(scrapbook, template)
|
72
|
-
|
59
|
+
# It's deprecated, but Rails 6 allows for templates to be specified with extensions.
|
60
|
+
return false if Rails.version.to_i == 6 && template.include?('.')
|
61
|
+
|
62
|
+
EmptyController.new.tap { |c| c.prepend_view_path(scrapbook.root) }.template_exists?(template)
|
63
|
+
end
|
64
|
+
|
65
|
+
def book_name
|
66
|
+
params[:'.book']
|
73
67
|
end
|
74
68
|
end
|
75
69
|
end
|
@@ -10,12 +10,7 @@ module Scrapbook
|
|
10
10
|
|
11
11
|
def short_path_to(pathname, scrapbook = nil)
|
12
12
|
scrapbook ||= Scrapbook.find_scrapbook_for(pathname)
|
13
|
-
|
14
|
-
if scrapbook.root == ::Scrapbook::Engine.config.scrapbook.paths.first
|
15
|
-
view.short_page_path(scrapbook.relative_page_path_for(pathname))
|
16
|
-
else
|
17
|
-
view.book_page_path(scrapbook.relative_page_path_for(pathname), book: scrapbook.name)
|
18
|
-
end
|
13
|
+
view.short_page_path(scrapbook.relative_page_path_for(pathname))
|
19
14
|
end
|
20
15
|
|
21
16
|
def remove_handler_exts_from(pathname)
|
@@ -9,11 +9,11 @@ module Scrapbook
|
|
9
9
|
|
10
10
|
def self.find_scrapbook_for(pathname)
|
11
11
|
scrapbooks = ::Scrapbook::Engine.config.scrapbook.paths
|
12
|
-
candidates = scrapbooks.
|
12
|
+
candidates = scrapbooks.filter_map do |book, pname|
|
13
13
|
relative_path = pathname.relative_path_from(pname)
|
14
14
|
next if relative_path.to_s.start_with?('..')
|
15
15
|
|
16
|
-
[
|
16
|
+
[book, relative_path.each_filename.count]
|
17
17
|
end
|
18
18
|
raise NotFoundError if candidates.empty?
|
19
19
|
|
@@ -25,7 +25,7 @@ module Scrapbook
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def name
|
28
|
-
root.basename
|
28
|
+
root.basename.to_s
|
29
29
|
end
|
30
30
|
|
31
31
|
def pages_pathname
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title><%= local_assigns[:scrapbook]
|
4
|
+
<title><%= local_assigns[:scrapbook]&.name || 'Scrapbook' %>: <%= content_for?(:title) ? yield(:title) : local_assigns[:pathname]&.basename %></title>
|
5
5
|
<%= csrf_meta_tags %>
|
6
6
|
<%= csp_meta_tag %>
|
7
7
|
|
data/app/views/pages.html.erb
CHANGED
@@ -1 +1,2 @@
|
|
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.
|
1
|
+
<% if pathname == scrapbook.pages_pathname %>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.
|
2
|
+
<% else %>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.<% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<iframe src="<%= raw_page_path(
|
1
|
+
<iframe src="<%= raw_page_path(scrapbook.relative_page_path_for(pathname)) %>" class="w-full h-full"></iframe>
|
data/config/routes.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Scrapbook::Engine.routes.draw do
|
4
|
-
|
4
|
+
# TODO: Future plans
|
5
|
+
# scope path: '/.editor' do
|
6
|
+
# resources :pages, id: /.+/, only: %i[new create edit update]
|
7
|
+
# end
|
5
8
|
|
6
|
-
|
7
|
-
resources :pages, path: ':book/pages', id: /.+/, constraints: {book: book_regex}
|
9
|
+
root 'pages#show'
|
8
10
|
|
9
|
-
get '
|
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: /.*/}, as: :book_page
|
11
|
+
get '.raw/pages(/*id)', to: 'pages#raw', constraints: {id: /.*/}, as: :raw_page
|
15
12
|
get '*id', to: 'pages#show', constraints: {id: /.*/}, as: :short_page
|
16
13
|
end
|
@@ -5,11 +5,12 @@ require 'rails/generators'
|
|
5
5
|
module Scrapbook
|
6
6
|
# Initial default setup of Scrapbook
|
7
7
|
class InstallGenerator < Rails::Generators::Base
|
8
|
-
class_option 'url-path', default: '/scrapbook'
|
9
8
|
class_option 'path-with-name', default: 'scrapbook'
|
10
9
|
|
11
10
|
def install
|
12
|
-
|
11
|
+
name = Pathname.new(options.fetch('path-with-name')).basename.to_s
|
12
|
+
|
13
|
+
generate 'scrapbook:routes', name
|
13
14
|
generate 'scrapbook:new', options.fetch('path-with-name')
|
14
15
|
sprockets_support
|
15
16
|
end
|
@@ -3,19 +3,21 @@
|
|
3
3
|
require 'rails/generators'
|
4
4
|
|
5
5
|
module Scrapbook
|
6
|
-
# A generator to create a new scrapbook
|
7
|
-
#
|
6
|
+
# A generator to create a new scrapbook with either the default (scrapbook) or specified
|
7
|
+
# name. (Using the default options for the URL path and folder root.)
|
8
8
|
class RoutesGenerator < Rails::Generators::Base
|
9
|
-
argument :
|
9
|
+
argument :name, optional: true, default: 'scrapbook'
|
10
10
|
|
11
11
|
def routes
|
12
12
|
# TODO: Investigate using a Rubocop rule to determine using single or double auotes.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
|
14
|
+
inject_into_file('config/routes.rb', after: "Rails.application.routes.draw do\n") do
|
15
|
+
" extend Scrapbook::Routing\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
inject_into_file('config/routes.rb', after: "extend Scrapbook::Routing\n") do
|
19
|
+
"\n scrapbook('#{name}') if Rails.env.development?\n"
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/scrapbook/engine.rb
CHANGED
@@ -6,15 +6,9 @@ module Scrapbook
|
|
6
6
|
isolate_namespace Scrapbook
|
7
7
|
|
8
8
|
config.scrapbook = ActiveSupport::OrderedOptions.new
|
9
|
-
config.scrapbook.paths ||=
|
9
|
+
config.scrapbook.paths ||= {}
|
10
10
|
config.scrapbook.precompile_assets = config.scrapbook.precompile_assets || false
|
11
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
12
|
initializer 'scrapbook.assets' do |app|
|
19
13
|
if app.config.scrapbook.precompile_assets && app.config.respond_to?(:assets)
|
20
14
|
app.config.assets.precompile.concat %w[
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Scrapbook
|
4
|
+
# This is a helper method for making it easier to add scrapbooks to routes.
|
5
|
+
module Routing
|
6
|
+
def scrapbook(name, at: "/#{name}", folder_root: name)
|
7
|
+
folder_root = Pathname.new(folder_root)
|
8
|
+
folder_root = Rails.root.join(folder_root) if folder_root.relative?
|
9
|
+
|
10
|
+
Engine.config.scrapbook.paths[name] = folder_root
|
11
|
+
mount Engine => at, defaults: {'.book': name}, as: "#{name}_scrapbook"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/scrapbook/version.rb
CHANGED
data/lib/scrapbook.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrapbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Lindsay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '7.1'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7.1'
|
@@ -56,7 +56,6 @@ files:
|
|
56
56
|
- app/views/layouts/scrapbook/application.html.erb
|
57
57
|
- app/views/layouts/scrapbook/host_application.html.erb
|
58
58
|
- app/views/pages.html.erb
|
59
|
-
- app/views/scrapbook/pages/index.html.erb
|
60
59
|
- app/views/scrapbook/pages/show.html.erb
|
61
60
|
- config/routes.rb
|
62
61
|
- lib/generators/scrapbook/install_generator.rb
|
@@ -64,6 +63,7 @@ files:
|
|
64
63
|
- lib/generators/scrapbook/routes_generator.rb
|
65
64
|
- lib/scrapbook.rb
|
66
65
|
- lib/scrapbook/engine.rb
|
66
|
+
- lib/scrapbook/routing.rb
|
67
67
|
- lib/scrapbook/version.rb
|
68
68
|
- lib/tasks/scrapbook_tasks.rake
|
69
69
|
homepage: https://bfad.github.io/scrapbook
|
@@ -1 +0,0 @@
|
|
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.
|