robin_cms 0.1.3 → 0.1.4
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/lib/robin_cms/cms.rb +38 -43
- data/lib/robin_cms/editable.rb +19 -13
- data/lib/robin_cms/library.rb +16 -5
- data/lib/robin_cms/version.rb +1 -1
- data/lib/robin_cms/views/delete_dialog.erb +1 -1
- data/lib/robin_cms/views/filter_form.erb +1 -1
- data/lib/robin_cms/views/library.erb +7 -7
- data/lib/robin_cms/views/library_actions.erb +1 -1
- data/lib/robin_cms/views/library_item.erb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3a49ee1ef9d638a300e82352bba65071dc6dfffecfb4cb409fbf8cbb8fbdd69
|
|
4
|
+
data.tar.gz: 928887dfc693144ebaaf9f2233a08b161faa7146ab7a037501098052d046fe74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 17bcd5f6cc1d057c6740fb3d7cf393432cd823956fcf4e78421b085cfc1ec3ef382c40b776b5f570cfb295af6cae71fd8a0711e5accc118641509bc519947bd9
|
|
7
|
+
data.tar.gz: e7f2f736f7535dce94edbe15a41c24201959e1231d0827c542ec3b4560215d1285e49f1d94321a57bdca50c1cfd85015f8a11f74cbd952b967081e7f5b3291a3
|
data/lib/robin_cms/cms.rb
CHANGED
|
@@ -53,7 +53,6 @@ module RobinCMS
|
|
|
53
53
|
|
|
54
54
|
post "/login" do
|
|
55
55
|
authenticate!(params[:username], params[:password])
|
|
56
|
-
|
|
57
56
|
session[:auth_user] = params[:username]
|
|
58
57
|
redirect to(home_page)
|
|
59
58
|
rescue AuthenticationError
|
|
@@ -83,11 +82,9 @@ module RobinCMS
|
|
|
83
82
|
end
|
|
84
83
|
|
|
85
84
|
authenticate!(session[:auth_user], params[:old_password])
|
|
86
|
-
|
|
87
85
|
update_credentials(params[:new_password])
|
|
88
86
|
session[:auth_user] = nil
|
|
89
87
|
flash[:success] = "Password updated succesfully. Please log in with your new credentials."
|
|
90
|
-
|
|
91
88
|
redirect to("/login")
|
|
92
89
|
rescue AuthenticationError
|
|
93
90
|
flash[:error] = "Incorrect username or password"
|
|
@@ -100,69 +97,67 @@ module RobinCMS
|
|
|
100
97
|
published: params[:published],
|
|
101
98
|
q: params[:q]
|
|
102
99
|
)
|
|
103
|
-
|
|
104
100
|
erb :library
|
|
105
101
|
end
|
|
106
102
|
|
|
107
103
|
get "/libraries/:kind/item" do
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
else
|
|
112
|
-
@item = @library.blank
|
|
113
|
-
end
|
|
104
|
+
@item = @library.blank
|
|
105
|
+
erb :library_item
|
|
106
|
+
end
|
|
114
107
|
|
|
108
|
+
get "/libraries/:kind/item/:id" do
|
|
109
|
+
@item = @library.find_one(params[:id])
|
|
110
|
+
halt 404 unless @item
|
|
115
111
|
erb :library_item
|
|
116
112
|
end
|
|
117
113
|
|
|
118
114
|
post "/libraries/:kind/item" do
|
|
119
|
-
if params[:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
tempfile = params[:image][:tempfile].to_path
|
|
126
|
-
|
|
127
|
-
@library.delete_static(@item.attributes[:image_src])
|
|
128
|
-
static_path = @library.create_static(filename, tempfile)
|
|
129
|
-
params[:image_src] = "/" + static_path
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
@item.attributes = params
|
|
133
|
-
@library.write(@item)
|
|
134
|
-
else
|
|
135
|
-
if params[:image]
|
|
136
|
-
filename = params[:image][:filename]
|
|
137
|
-
tempfile = params[:image][:tempfile].to_path
|
|
138
|
-
|
|
139
|
-
static_path = @library.create_static(filename, tempfile)
|
|
140
|
-
params[:image_src] = "/" + static_path
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
@library.create(params)
|
|
115
|
+
if params[:image]
|
|
116
|
+
static_path = @library.create_static(
|
|
117
|
+
params[:image][:filename],
|
|
118
|
+
params[:image][:tempfile].to_path
|
|
119
|
+
)
|
|
120
|
+
params[:image_src] = "/" + static_path
|
|
144
121
|
end
|
|
145
122
|
|
|
123
|
+
@library.create(params)
|
|
146
124
|
redirect to("/libraries/#{params[:kind]}")
|
|
147
125
|
rescue ItemExistsError
|
|
148
126
|
flash[:error] = "An item with the same name already exists"
|
|
149
127
|
redirect to("/libraries/#{params[:kind]}/item")
|
|
150
128
|
end
|
|
151
129
|
|
|
152
|
-
post "/libraries/:kind/item
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
halt 404 unless @item
|
|
130
|
+
post "/libraries/:kind/item/:id" do
|
|
131
|
+
@item = @library.find_one(params[:id])
|
|
132
|
+
halt 404 unless @item
|
|
156
133
|
|
|
157
|
-
|
|
134
|
+
if params[:image]
|
|
135
|
+
# If there is an existing image for this item, delete it to prevent
|
|
136
|
+
# accumulation of old files.
|
|
137
|
+
if @item.attributes[:image_src] && !@item.attributes[:image_src].empty?
|
|
158
138
|
@library.delete_static(@item.attributes[:image_src])
|
|
159
139
|
end
|
|
140
|
+
static_path = @library.create_static(
|
|
141
|
+
params[:image][:filename],
|
|
142
|
+
params[:image][:tempfile].to_path
|
|
143
|
+
)
|
|
144
|
+
params[:image_src] = "/" + static_path
|
|
145
|
+
end
|
|
160
146
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
147
|
+
@item.attributes = params
|
|
148
|
+
@library.write(@item)
|
|
149
|
+
redirect to("/libraries/#{params[:kind]}")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
post "/libraries/:kind/item/:id/delete" do
|
|
153
|
+
@item = @library.find_one(params[:id])
|
|
154
|
+
halt 404 unless @item
|
|
155
|
+
|
|
156
|
+
if @item.attributes[:image_src]
|
|
157
|
+
@library.delete_static(@item.attributes[:image_src])
|
|
164
158
|
end
|
|
165
159
|
|
|
160
|
+
@library.delete(@item.id)
|
|
166
161
|
redirect to("/libraries/#{params[:kind]}")
|
|
167
162
|
end
|
|
168
163
|
|
data/lib/robin_cms/editable.rb
CHANGED
|
@@ -4,31 +4,37 @@ module RobinCMS
|
|
|
4
4
|
# This module provides methods for editing image files.
|
|
5
5
|
# No methods are required in the base class in order to use this mixin.
|
|
6
6
|
module Editable
|
|
7
|
-
def resize_image(filepath,
|
|
7
|
+
def resize_image(filepath, to:)
|
|
8
8
|
# The mogrify command edits images in place. For more info, see
|
|
9
9
|
# mogrify(1).
|
|
10
|
-
|
|
11
|
-
system("mogrify -resize #{dimensions} #{filepath}")
|
|
10
|
+
system("mogrify -resize #{to} #{filepath}")
|
|
12
11
|
if $?.exitstatus != 0
|
|
13
12
|
raise ConversionError, "Could not resize image #{filepath}"
|
|
14
13
|
end
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
def
|
|
18
|
-
system("mogrify -format #{
|
|
16
|
+
def convert_image(filepath, to:)
|
|
17
|
+
system("mogrify -format #{to} #{filepath}")
|
|
19
18
|
if $?.exitstatus != 0
|
|
20
19
|
raise ConversionError, "Could not format image #{filepath}"
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
# The
|
|
24
|
-
# with
|
|
25
|
-
converted = filepath.sub(/#{File.extname(filepath)}$/, ".#{
|
|
22
|
+
# The file created by the mogrify command will be the same as the
|
|
23
|
+
# original but with the new file extension.
|
|
24
|
+
converted = filepath.sub(/#{File.extname(filepath)}$/, ".#{to}")
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
if converted == filepath
|
|
27
|
+
# If the converted file has the same filename as the original (i.e. no
|
|
28
|
+
# conversion happened), there is nothing more to do.
|
|
29
|
+
filepath
|
|
30
|
+
else
|
|
31
|
+
# Otherwise, copy the contents of the mogrify output file to a new
|
|
32
|
+
# tempfile and delete the mogrify output.
|
|
33
|
+
tempfile = Tempfile.new(["robin_cms" ".#{to}"])
|
|
34
|
+
IO.copy_stream(converted, tempfile)
|
|
35
|
+
File.delete(converted)
|
|
36
|
+
tempfile
|
|
37
|
+
end
|
|
32
38
|
end
|
|
33
39
|
end
|
|
34
40
|
end
|
data/lib/robin_cms/library.rb
CHANGED
|
@@ -42,6 +42,7 @@ module RobinCMS
|
|
|
42
42
|
|
|
43
43
|
def create_static(filename, tempfile)
|
|
44
44
|
path = File.join(@schema[:static_location], File.basename(make_slug(filename)))
|
|
45
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
45
46
|
|
|
46
47
|
if File.exist?(path)
|
|
47
48
|
raise ItemExistsError, "An item with the same name already exists"
|
|
@@ -51,18 +52,24 @@ module RobinCMS
|
|
|
51
52
|
dimensions = image_field&.dig(:dimensions)
|
|
52
53
|
filetype = image_field&.dig(:filetype)
|
|
53
54
|
|
|
54
|
-
resize_image(tempfile, dimensions) if dimensions
|
|
55
|
-
format_image(tempfile, filetype) if filetype
|
|
55
|
+
resize_image(tempfile, to: dimensions) if dimensions
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
# Only convert if the specified filetype is different to the actual
|
|
58
|
+
# filetype. Unlike resize_image which modifies the image in-pace, this
|
|
59
|
+
# function necessarily creates a new file, so we need to ensure we
|
|
60
|
+
# update the path with the new file extension.
|
|
61
|
+
if filetype && File.extname(tempfile) != ".#{filetype}"
|
|
62
|
+
tempfile = convert_image(tempfile, to: filetype)
|
|
63
|
+
path = File.join(File.dirname(path), "#{File.basename(path, '.*')}.#{filetype}")
|
|
64
|
+
end
|
|
59
65
|
|
|
66
|
+
FileUtils.cp(tempfile, path)
|
|
60
67
|
path
|
|
61
68
|
end
|
|
62
69
|
|
|
63
70
|
def delete_static(filename)
|
|
71
|
+
return if filename.nil? || filename.empty?
|
|
64
72
|
path = File.join(@schema[:static_location], File.basename(filename))
|
|
65
|
-
|
|
66
73
|
return unless File.exist?(path)
|
|
67
74
|
|
|
68
75
|
File.delete(path)
|
|
@@ -79,5 +86,9 @@ module RobinCMS
|
|
|
79
86
|
def [](key)
|
|
80
87
|
@schema[key]
|
|
81
88
|
end
|
|
89
|
+
|
|
90
|
+
def kind
|
|
91
|
+
@schema[:id]
|
|
92
|
+
end
|
|
82
93
|
end
|
|
83
94
|
end
|
data/lib/robin_cms/version.rb
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<button type="submit">Close</button>
|
|
10
10
|
</form>
|
|
11
11
|
<form
|
|
12
|
-
action='<%= url("/libraries/#{@library
|
|
12
|
+
action='<%= url("/libraries/#{@library.kind}/item/#{@item.id}/delete") %>'
|
|
13
13
|
method="post"
|
|
14
14
|
>
|
|
15
15
|
<button type="submit" class="--danger">Delete</button>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<p><%= @library[:description] %></p>
|
|
7
7
|
<% end %>
|
|
8
8
|
<% if @library[:can_create] %>
|
|
9
|
-
<form action='<%= url("/libraries/#{@library
|
|
9
|
+
<form action='<%= url("/libraries/#{@library.kind}/item") %>'>
|
|
10
10
|
<button type="submit">
|
|
11
11
|
New <%= @library[:label_singular].downcase %>
|
|
12
12
|
</button>
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
<br />
|
|
21
21
|
<br />
|
|
22
22
|
<% if @library[:can_create] %>
|
|
23
|
-
Create a <a href='<%= url("/libraries/#{@library
|
|
24
|
-
or try <a href='<%= url("/libraries/#{@library
|
|
23
|
+
Create a <a href='<%= url("/libraries/#{@library.kind}/item") %>'>new <%= @library[:label_singular].downcase %></a>
|
|
24
|
+
or try <a href='<%= url("/libraries/#{@library.kind}") %>'>clearing</a> your search filters.
|
|
25
25
|
<% end %>
|
|
26
26
|
</div>
|
|
27
27
|
<% else %>
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
<% for item in @items %>
|
|
41
41
|
<tr>
|
|
42
42
|
<td>
|
|
43
|
-
<a href='<%= url("/libraries/#{@library
|
|
43
|
+
<a href='<%= url("/libraries/#{@library.kind}/item/#{item.id}") %>'>
|
|
44
44
|
<%= item.display_name %>
|
|
45
45
|
</a>
|
|
46
46
|
</td>
|
|
47
47
|
<% if @library.drafts_enabled? %>
|
|
48
48
|
<td>
|
|
49
|
-
<a href='<%= url("/libraries/#{@library
|
|
49
|
+
<a href='<%= url("/libraries/#{@library.kind}/item/#{item.id}") %>'>
|
|
50
50
|
<span class="badge --<%= item.published? ? 'published' : 'draft' %>">
|
|
51
51
|
<%= item.published_label %>
|
|
52
52
|
</span>
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
</td>
|
|
55
55
|
<% end %>
|
|
56
56
|
<td>
|
|
57
|
-
<a href='<%= url("/libraries/#{@library
|
|
57
|
+
<a href='<%= url("/libraries/#{@library.kind}/item/#{item.id}") %>'>
|
|
58
58
|
<%= item.created_at.strftime("%b %d, %Y") %>
|
|
59
59
|
</a>
|
|
60
60
|
</td>
|
|
61
61
|
<td>
|
|
62
|
-
<a href='<%= url("/libraries/#{@library
|
|
62
|
+
<a href='<%= url("/libraries/#{@library.kind}/item/#{item.id}") %>'>
|
|
63
63
|
<%= item.updated_at.strftime("%b %d, %Y") %>
|
|
64
64
|
</a>
|
|
65
65
|
</td>
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
<form
|
|
8
8
|
class="card"
|
|
9
9
|
<% if @item.id %>
|
|
10
|
-
action='<%= url("/libraries/#{@library
|
|
10
|
+
action='<%= url("/libraries/#{@library.kind}/item/#{@item.id}") %>'
|
|
11
11
|
<% else %>
|
|
12
|
-
action='<%= url("/libraries/#{@library
|
|
12
|
+
action='<%= url("/libraries/#{@library.kind}/item") %>'
|
|
13
13
|
<% end %>
|
|
14
14
|
method="post"
|
|
15
15
|
enctype="multipart/form-data"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: robin_cms
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aron Lebani
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-10-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bcrypt
|