robin_cms 0.1.1 → 0.1.3
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 +4 -4
- data/README.md +65 -54
- data/lib/robin_cms/cms.rb +32 -30
- data/lib/robin_cms/collection_library.rb +70 -0
- data/lib/robin_cms/configuration-schema.json +2 -0
- data/lib/robin_cms/configuration.rb +2 -16
- data/lib/robin_cms/data_library.rb +58 -0
- data/lib/robin_cms/editable.rb +34 -0
- data/lib/robin_cms/item.rb +89 -19
- data/lib/robin_cms/library.rb +83 -0
- data/lib/robin_cms/queryable.rb +9 -7
- data/lib/robin_cms/version.rb +1 -1
- data/lib/robin_cms/views/filter_form.erb +1 -1
- data/lib/robin_cms/views/hidden_field.erb +1 -1
- data/lib/robin_cms/views/input_field.erb +1 -1
- data/lib/robin_cms/views/layout.erb +6 -3
- data/lib/robin_cms/views/library.erb +2 -2
- data/lib/robin_cms/views/library_actions.erb +3 -0
- data/lib/robin_cms/views/library_item.erb +9 -14
- data/lib/robin_cms/views/richtext_field.erb +1 -1
- data/lib/robin_cms/views/select_field.erb +2 -2
- data/lib/robin_cms/views/stylesheet.css.erb +443 -0
- data/lib/robin_cms.rb +6 -5
- metadata +9 -9
- data/lib/robin_cms/collection_item.rb +0 -82
- data/lib/robin_cms/data_item.rb +0 -88
- data/lib/robin_cms/itemable.rb +0 -124
- data/lib/robin_cms/static_item.rb +0 -92
- data/lib/robin_cms/views/style.erb +0 -441
- /data/lib/robin_cms/views/{logo.erb → logo.svg.erb} +0 -0
- /data/lib/robin_cms/views/{new_tab.erb → new_tab.svg.erb} +0 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RobinCMS
|
4
|
+
class Library
|
5
|
+
include Editable
|
6
|
+
include Sluggable
|
7
|
+
include Queryable
|
8
|
+
|
9
|
+
attr_reader :schema
|
10
|
+
|
11
|
+
def initialize(schema)
|
12
|
+
@schema = schema.freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
def blank
|
16
|
+
Item.new(nil, **@schema)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(attributes)
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_one(id)
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def all
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
|
31
|
+
# Writes the specified item to disk.
|
32
|
+
#
|
33
|
+
# Returns the path where the item was written.
|
34
|
+
def write(item)
|
35
|
+
raise NotImplementedError
|
36
|
+
end
|
37
|
+
|
38
|
+
# Delete the item specified by +id+.
|
39
|
+
def delete(id)
|
40
|
+
raise NotImplementedError
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_static(filename, tempfile)
|
44
|
+
path = File.join(@schema[:static_location], File.basename(make_slug(filename)))
|
45
|
+
|
46
|
+
if File.exist?(path)
|
47
|
+
raise ItemExistsError, "An item with the same name already exists"
|
48
|
+
end
|
49
|
+
|
50
|
+
image_field = @schema[:fields].find { |f| f[:type] == "image" }
|
51
|
+
dimensions = image_field&.dig(:dimensions)
|
52
|
+
filetype = image_field&.dig(:filetype)
|
53
|
+
|
54
|
+
resize_image(tempfile, dimensions) if dimensions
|
55
|
+
format_image(tempfile, filetype) if filetype
|
56
|
+
|
57
|
+
FileUtils.mkdir_p(File.dirname(path))
|
58
|
+
FileUtils.cp(tempfile, path)
|
59
|
+
|
60
|
+
path
|
61
|
+
end
|
62
|
+
|
63
|
+
def delete_static(filename)
|
64
|
+
path = File.join(@schema[:static_location], File.basename(filename))
|
65
|
+
|
66
|
+
return unless File.exist?(path)
|
67
|
+
|
68
|
+
File.delete(path)
|
69
|
+
end
|
70
|
+
|
71
|
+
def drafts_enabled?
|
72
|
+
@schema[:type].nil? || @schema[:type] == "collection"
|
73
|
+
end
|
74
|
+
|
75
|
+
def sorted_fields
|
76
|
+
@schema[:fields].sort_by { |field| field[:order] || Float::INFINITY }
|
77
|
+
end
|
78
|
+
|
79
|
+
def [](key)
|
80
|
+
@schema[key]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/robin_cms/queryable.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RobinCMS
|
4
|
+
# This module provides methods for querying items.
|
5
|
+
#
|
6
|
+
# In order to use this as a mixin, you only need to implement an +all+
|
7
|
+
# method in the base class. This method should take no parameters, and
|
8
|
+
# return all items.
|
4
9
|
module Queryable
|
5
|
-
def
|
10
|
+
def query(**kwargs)
|
6
11
|
by_published = lambda do |i|
|
7
12
|
case kwargs[:published]
|
8
13
|
when nil, ""
|
@@ -34,14 +39,11 @@ module RobinCMS
|
|
34
39
|
end * sort_direction
|
35
40
|
end
|
36
41
|
|
37
|
-
all(
|
38
|
-
.filter(&by_search)
|
39
|
-
.filter(&by_published)
|
40
|
-
.sort(&by_field)
|
42
|
+
all.filter(&by_search).filter(&by_published).sort(&by_field)
|
41
43
|
end
|
42
44
|
|
43
|
-
def count
|
44
|
-
all
|
45
|
+
def count
|
46
|
+
all.size
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
data/lib/robin_cms/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
id="<%= safe_id(field[:id], 'field') %>"
|
4
4
|
type="<%= field[:type] %>"
|
5
5
|
name="<%= field[:id] %>"
|
6
|
-
value="<%= @item.
|
6
|
+
value="<%= @item.field_value_or_default(field) %>"
|
7
7
|
<% if field[:required] %>required<% end %>
|
8
8
|
<% if field[:readonly] %>readonly<% end %>
|
9
9
|
/>
|
@@ -3,8 +3,11 @@
|
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8" />
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
6
|
+
<meta name="robots" content="noindex,nofollow" />
|
6
7
|
<title><%= @config[:title] %> | admin</title>
|
7
|
-
|
8
|
+
<style>
|
9
|
+
<%= erb :"stylesheet.css" %>
|
10
|
+
</style>
|
8
11
|
</head>
|
9
12
|
<body <% if flash[:success_dialog] %>onload="successdialog.showModal()"<% end %>>
|
10
13
|
<% if session[:auth_user] %>
|
@@ -14,7 +17,7 @@
|
|
14
17
|
</span>
|
15
18
|
<span class="controls --gap-md">
|
16
19
|
<a href="<%= @config[:url] %>" target="_blank">
|
17
|
-
<%= @config[:url] %><%= erb :new_tab %>
|
20
|
+
<%= @config[:url] %><%= erb :"new_tab.svg" %>
|
18
21
|
</a>
|
19
22
|
<% if @config[:build_command] %>
|
20
23
|
<form id="publish-form" action="/admin/publish" method="post">
|
@@ -29,7 +32,7 @@
|
|
29
32
|
<main id="site-content">
|
30
33
|
<%= yield %>
|
31
34
|
<footer id="site-footer" class="card --clear">
|
32
|
-
<%= erb :logo %>
|
35
|
+
<%= erb :"logo.svg" %>
|
33
36
|
<p>
|
34
37
|
Made with 🧡
|
35
38
|
<br />
|
@@ -29,7 +29,7 @@
|
|
29
29
|
<thead>
|
30
30
|
<tr>
|
31
31
|
<th class="grow-column">Name</th>
|
32
|
-
<% if @
|
32
|
+
<% if @library.drafts_enabled? %>
|
33
33
|
<th>Status</th>
|
34
34
|
<% end %>
|
35
35
|
<th>Created</th>
|
@@ -44,7 +44,7 @@
|
|
44
44
|
<%= item.display_name %>
|
45
45
|
</a>
|
46
46
|
</td>
|
47
|
-
<% if @
|
47
|
+
<% if @library.drafts_enabled? %>
|
48
48
|
<td>
|
49
49
|
<a href='<%= url("/libraries/#{@library[:id]}/item?id=#{item.id}") %>'>
|
50
50
|
<span class="badge --<%= item.published? ? 'published' : 'draft' %>">
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<h2>
|
3
3
|
<% if @item.id %>Edit<% else %>New<% end %> <%= @library[:label_singular].downcase %>
|
4
4
|
</h2>
|
5
|
-
<%= erb :library_actions %>
|
5
|
+
<%= erb :library_actions, locals: { has_delete: @library[:can_delete] && @item.id } %>
|
6
6
|
</header>
|
7
7
|
<form
|
8
8
|
class="card"
|
@@ -14,31 +14,26 @@
|
|
14
14
|
method="post"
|
15
15
|
enctype="multipart/form-data"
|
16
16
|
>
|
17
|
-
<%
|
17
|
+
<% @library.sorted_fields.each do |field| %>
|
18
18
|
<div class="field">
|
19
19
|
<% case field[:type]
|
20
20
|
when "text", "date", "number", "color", "email", "url" %>
|
21
|
-
<%= erb :input_field, locals: { :
|
21
|
+
<%= erb :input_field, locals: { field: field } %>
|
22
22
|
<% when "hidden" %>
|
23
|
-
<%= erb :hidden_field, locals: { :
|
23
|
+
<%= erb :hidden_field, locals: { field: field } %>
|
24
24
|
<% when "select" %>
|
25
|
-
<%= erb :select_field, locals: { :
|
25
|
+
<%= erb :select_field, locals: { field: field } %>
|
26
26
|
<% when "image" %>
|
27
|
-
<%= erb :image_field, locals: { :
|
27
|
+
<%= erb :image_field, locals: { field: field } %>
|
28
28
|
<% when "richtext" %>
|
29
|
-
<%= erb :richtext_field, locals: { :
|
29
|
+
<%= erb :richtext_field, locals: { field: field } %>
|
30
30
|
<% else %>
|
31
31
|
<div></div>
|
32
32
|
<% end %>
|
33
33
|
</div>
|
34
34
|
<% end %>
|
35
35
|
<%= erb :flash %>
|
36
|
-
<footer class="controls --align-
|
37
|
-
|
38
|
-
<%= erb :delete_dialog %>
|
39
|
-
<% else %>
|
40
|
-
<span></span>
|
41
|
-
<% end %>
|
42
|
-
<%= erb :library_actions %>
|
36
|
+
<footer class="controls --align-right">
|
37
|
+
<%= erb :library_actions, locals: { has_delete: false } %>
|
43
38
|
</footer>
|
44
39
|
</form>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<select
|
3
3
|
id="<%= safe_id(field[:id], 'field') %>"
|
4
4
|
name="<%= field[:id] %>"
|
5
|
-
value="<%= @item.
|
5
|
+
value="<%= @item.field_value_or_default(field) %>"
|
6
6
|
>
|
7
7
|
<% for option in field[:options] %>
|
8
8
|
<option
|
@@ -12,7 +12,7 @@
|
|
12
12
|
selected
|
13
13
|
<% end %>
|
14
14
|
<% else %>
|
15
|
-
<% if option[:value].to_s ==
|
15
|
+
<% if option[:value].to_s == @item.field_value_or_default(field) %>
|
16
16
|
selected
|
17
17
|
<% end %>
|
18
18
|
<% end %>
|