robin_cms 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a9634aa2592fdf851123491cc53c9b1b347b6e6ca3f7f37d4adbd9e0fb494c7
4
- data.tar.gz: 3885036d121802207eb4ae9cf80c372211ee199f60fa30c7e11f5b916af5c570
3
+ metadata.gz: 68c3b702cf90bbb615ebeea6303a3f12e4e5da64b3360b295a198b9347ea11bb
4
+ data.tar.gz: d266f45a2863ee190014bcd3174f0413fb70a5f745aaef74780f0a9ca7d6b3eb
5
5
  SHA512:
6
- metadata.gz: f38e98b366edb3294b56e2b97c80819149163020d41dd565e893ec3d4d8c84f2332f108de62858a9d55bf135176bf8f042ee28980bd1eb6f6d6ddaf7d330f210
7
- data.tar.gz: 29d90d7896c8366dbe5373bdd89193d4dcd336577cd8c517d2b5b5082b1aa65ffef18c0b733b5387bb9bf53405c8fcf77b8afdb700e1a682c98bc37ae1c51540
6
+ metadata.gz: 12d3f8064c84a26a3e3899ca964e411609ca03de3c193466aab157530d1022ffa0ae45237545260ad9a35377e07ff5cb09325c00c682cfd790247c1879b6dde4
7
+ data.tar.gz: d73739c5b1b1c83b4fc7f3d80363353318a0b69164fba07ad784a738d8e5c23c8cea6c73c1d55542279c6a38929dc65ffc673870669781cf9df2a631cb21bebd
data/lib/robin_cms/cms.rb CHANGED
@@ -37,7 +37,7 @@ module RobinCMS
37
37
  end
38
38
 
39
39
  get "/" do
40
- redirect to(home_page)
40
+ redirect to(root_url)
41
41
  end
42
42
 
43
43
  get "/login" do
@@ -47,7 +47,7 @@ module RobinCMS
47
47
  post "/login" do
48
48
  authenticate!(params[:username], params[:password])
49
49
  session[:auth_user] = params[:username]
50
- redirect to(home_page)
50
+ redirect to(root_url)
51
51
  rescue AuthenticationError
52
52
  flash[:error] = "Incorrect username or password"
53
53
  redirect to("/login")
@@ -155,13 +155,14 @@ module RobinCMS
155
155
  end
156
156
 
157
157
  post "/publish" do
158
- if system(@config[:build_command])
158
+ system(@config[:build_command])
159
+ if $?.exitstatus == 0
159
160
  flash[:success_dialog] = "Your site has been successfully published!"
160
161
  else
161
- flash[:errors] = "There was an error publishing the site"
162
+ flash[:error_dialog] = "There was an error publishing the site."
162
163
  end
163
164
 
164
- redirect to(home_page)
165
+ redirect to(root_url)
165
166
  end
166
167
 
167
168
  not_found do
@@ -37,13 +37,50 @@ module RobinCMS
37
37
  URI.decode_www_form(request.query_string).to_h
38
38
  end
39
39
 
40
- def current_page
41
- _, libraries, item = request.path_info.split("/")
42
- item || libraries
40
+ def root_url
41
+ url("/libraries/#{@config[:libraries].first[:id]}")
42
+ end
43
+
44
+ def profile_url
45
+ url("/profile")
46
+ end
47
+
48
+ def logout_url
49
+ url("/logout")
50
+ end
51
+
52
+ def change_password_url
53
+ url("/change-password")
54
+ end
55
+
56
+ def library_url(library)
57
+ url("/libraries/#{library[:id]}")
43
58
  end
44
59
 
45
- def home_page
46
- "/libraries/#{@config[:libraries].first[:id]}"
60
+ def library_item_url(library, item = nil)
61
+ if item
62
+ url("/libraries/#{library[:id]}/item/#{item.id}")
63
+ else
64
+ url("/libraries/#{library[:id]}/item")
65
+ end
66
+ end
67
+
68
+ def delete_library_item_url(library, item)
69
+ url("/libraries/#{library[:id]}/item/#{item.id}/delete")
70
+ end
71
+
72
+ def item_image_url(item)
73
+ url(item.image_src)
74
+ end
75
+
76
+ def publish_url
77
+ url("/publish")
78
+ end
79
+
80
+ def current_page?(library)
81
+ _, libraries, item = request.path_info.split("/")
82
+ current_page = item || libraries
83
+ library[:id].to_s == current_page
47
84
  end
48
85
 
49
86
  # For generating safe id's where the id needs to be based on user
@@ -7,7 +7,7 @@ module RobinCMS
7
7
  DATETIME_FORMAT = "%Y-%m-%d"
8
8
 
9
9
  # The keys which we don't want to serialize.
10
- FRONTMATTER_IGNORE_KEYS = [:id, :content, :image, :captures].freeze
10
+ FRONTMATTER_IGNORE_KEYS = [:id, :kind, :content, :image, :captures].freeze
11
11
 
12
12
  def initialize(id, attrs = {}, **schema)
13
13
  if !attrs.empty? && !attrs.has_key?(:title)
@@ -78,6 +78,14 @@ module RobinCMS
78
78
  end
79
79
  end
80
80
 
81
+ def image_src
82
+ @attributes[:image_src]
83
+ end
84
+
85
+ def image_alt
86
+ @attributes[:image_alt]
87
+ end
88
+
81
89
  # Get the frontmatter as a hash with stringified keys.
82
90
  def frontmatter
83
91
  frontmatter = @attributes.clone
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RobinCMS
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
@@ -16,7 +16,7 @@
16
16
  </div>
17
17
  <%= erb :flash %>
18
18
  <footer class="controls --align-right">
19
- <a href="/admin">Back</a>
19
+ <a href="<%= root_url %>">Back</a>
20
20
  <button type="submit">Update</button>
21
21
  </footer>
22
22
  </form>
@@ -9,7 +9,7 @@
9
9
  <button type="submit">Close</button>
10
10
  </form>
11
11
  <form
12
- action='<%= url("/libraries/#{@library.kind}/item/#{@item.id}/delete") %>'
12
+ action="<%= delete_library_item_url(@library, @item) %>"
13
13
  method="post"
14
14
  >
15
15
  <button type="submit" class="--danger">Delete</button>
@@ -13,7 +13,7 @@
13
13
  </select>
14
14
  <% if @library.drafts_enabled? %>
15
15
  <select id="published" name="published">
16
- <% for option in PUBLISHED_OPTIONS%>
16
+ <% for option in PUBLISHED_OPTIONS %>
17
17
  <option
18
18
  value="<%= option[:value] %>"
19
19
  <% if query_params["published"] == option[:value] %>
@@ -33,5 +33,5 @@
33
33
  placeholder="Search <%= @library[:label].downcase %>..."
34
34
  />
35
35
  <button type="submit">Apply</button>
36
- <a href="/admin/libraries/<%= @library.kind %>">Clear filters</a>
36
+ <a href="<%= library_url(@library) %>">Clear filters</a>
37
37
  </form>
@@ -11,8 +11,8 @@
11
11
  <img
12
12
  id="image-preview"
13
13
  class="image-preview"
14
- src="<%= url(@item.attributes[:image_src]) %>"
15
- alt="<%= @item.attributes[:image_alt] %>"
14
+ src="<%= item_image_url(@item) %>"
15
+ alt="<%= @item.image_alt %>"
16
16
  />
17
17
  <input
18
18
  id="<%= safe_id('image', 'field') %>"
@@ -9,23 +9,29 @@
9
9
  <%= erb :"stylesheet.css" %>
10
10
  </style>
11
11
  </head>
12
- <body <% if flash[:success_dialog] %>onload="successdialog.showModal()"<% end %>>
12
+ <body
13
+ <% if flash[:success_dialog] %>
14
+ onload="successdialog.showModal()"
15
+ <% elsif flash[:error_dialog] %>
16
+ onload="errordialog.showModal()"
17
+ <% end %>
18
+ >
13
19
  <% if session[:auth_user] %>
14
20
  <header id="site-header">
15
21
  <span class="controls">
16
- <h1><a href="/admin"><%= @config[:title] %> admin</a></h1>
22
+ <h1><a href="<%= root_url %>"><%= @config[:title] %> admin</a></h1>
17
23
  </span>
18
24
  <span class="controls --gap-md">
19
25
  <a href="<%= @config[:url] %>" target="_blank">
20
26
  <%= @config[:url] %><%= erb :"new_tab.svg" %>
21
27
  </a>
22
28
  <% if @config[:build_command] %>
23
- <form id="publish-form" action="/admin/publish" method="post">
29
+ <form id="publish-form" action="<%= publish_url %>" method="post">
24
30
  <button type="submit" form="publish-form">Publish site</button>
25
31
  </form>
26
32
  <% end %>
27
- <a href='<%= url("/profile") %>'>Account</a>
28
- <a href='<%= url("/logout") %>'>Log out</a>
33
+ <a href="<%= profile_url %>">Account</a>
34
+ <a href="<%= logout_url %>">Log out</a>
29
35
  </span>
30
36
  </header>
31
37
  <% end %>
@@ -44,8 +50,17 @@
44
50
  <h2>Success!</h2>
45
51
  <p><%= flash[:success_dialog] %></p>
46
52
  <div class="controls">
47
- <form id="dialog-close" method="dialog">
48
- <button type="submit" form="dialog-close">Continue</button>
53
+ <form id="success-dialog-close" method="dialog">
54
+ <button type="submit" form="success-dialog-close">Continue</button>
55
+ </form>
56
+ </div>
57
+ </dialog>
58
+ <dialog id="errordialog" class="card">
59
+ <h2>Oops, something went wrong.</h2>
60
+ <p><%= flash[:error_dialog] %></p>
61
+ <div class="controls">
62
+ <form id="err-dialog-close" method="dialog">
63
+ <button type="submit" form="err-dialog-close">Continue</button>
49
64
  </form>
50
65
  </div>
51
66
  </dialog>
@@ -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.kind}/item") %>'>
9
+ <form action="<%= library_item_url(@library) %>">
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.kind}/item") %>'>new <%= @library[:label_singular].downcase %></a>
24
- or try <a href='<%= url("/libraries/#{@library.kind}") %>'>clearing</a> your search filters.
23
+ Create a <a href="<%= library_item_url(@library) %>">new <%= @library[:label_singular].downcase %></a>
24
+ or try <a href="<%= library_url(@library) %>">clearing</a> your search filters.
25
25
  <% end %>
26
26
  </div>
27
27
  <% else %>
@@ -30,7 +30,7 @@
30
30
  <tr>
31
31
  <th>Name</th>
32
32
  <% if @library.drafts_enabled? %>
33
- <th>Status</th>
33
+ <th class="status">Status</th>
34
34
  <% end %>
35
35
  <th class="date">Created</th>
36
36
  <th class="date">Last updated</th>
@@ -40,26 +40,26 @@
40
40
  <% for item in @items %>
41
41
  <tr>
42
42
  <td>
43
- <a href='<%= url("/libraries/#{@library.kind}/item/#{item.id}") %>'>
43
+ <a href="<%= library_item_url(@library, item) %>">
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.kind}/item/#{item.id}") %>'>
50
- <span class="badge --<%= item.published? ? 'published' : 'draft' %>">
49
+ <a href="<%= library_item_url(@library, item) %>">
50
+ <span class="badge --<%= item.published_label.downcase %>">
51
51
  <%= item.published_label %>
52
52
  </span>
53
53
  </a>
54
54
  </td>
55
55
  <% end %>
56
56
  <td class="date">
57
- <a href='<%= url("/libraries/#{@library.kind}/item/#{item.id}") %>'>
57
+ <a href="<%= library_item_url(@library, item) %>">
58
58
  <%= item.created_at.strftime("%b %d, %Y") %>
59
59
  </a>
60
60
  </td>
61
61
  <td class="date">
62
- <a href='<%= url("/libraries/#{@library.kind}/item/#{item.id}") %>'>
62
+ <a href="<%= library_item_url(@library, item) %>">
63
63
  <%= item.updated_at.strftime("%b %d, %Y") %>
64
64
  </a>
65
65
  </td>
@@ -1,7 +1,5 @@
1
1
  <span class="controls">
2
- <a href='<%= url("/libraries/#{@library.kind}") %>'>Back</a>
2
+ <a href="<%= library_url(@library) %>">Back</a>
3
3
  <button form="<%= safe_id(@item.id, 'edit_item') %>" type="submit">Save</button>
4
- <% if has_delete %>
5
- <%= erb :delete_dialog %>
6
- <% end %>
4
+ <%= erb :delete_dialog if has_delete %>
7
5
  </span>
@@ -8,29 +8,31 @@
8
8
  id="<%= safe_id(@item.id, 'edit_item') %>"
9
9
  class="card"
10
10
  <% if @item.id %>
11
- action='<%= url("/libraries/#{@library.kind}/item/#{@item.id}") %>'
11
+ action="<%= library_item_url(@library, @item) %>"
12
12
  <% else %>
13
- action='<%= url("/libraries/#{@library.kind}/item") %>'
13
+ action="<%= library_item_url(@library) %>"
14
14
  <% end %>
15
15
  method="post"
16
16
  enctype="multipart/form-data"
17
17
  >
18
18
  <% @library.sorted_fields.each do |field| %>
19
19
  <div class="field">
20
- <% case field[:type]
21
- when "text", "date", "number", "color", "email", "url" %>
22
- <%= erb :input_field, locals: { field: field } %>
23
- <% when "hidden" %>
24
- <%= erb :hidden_field, locals: { field: field } %>
25
- <% when "select" %>
26
- <%= erb :select_field, locals: { field: field } %>
27
- <% when "image" %>
28
- <%= erb :image_field, locals: { field: field } %>
29
- <% when "richtext" %>
30
- <%= erb :richtext_field, locals: { field: field } %>
31
- <% else %>
32
- <div></div>
33
- <% end %>
20
+ <%=
21
+ case field[:type]
22
+ when "text", "date", "number", "color", "email", "url"
23
+ erb :input_field, locals: { field: field }
24
+ when "hidden"
25
+ erb :hidden_field, locals: { field: field }
26
+ when "select"
27
+ erb :select_field, locals: { field: field }
28
+ when "image"
29
+ erb :image_field, locals: { field: field }
30
+ when "richtext"
31
+ erb :richtext_field, locals: { field: field }
32
+ else
33
+ ""
34
+ end
35
+ %>
34
36
  </div>
35
37
  <% end %>
36
38
  <%= erb :flash %>
@@ -1,10 +1,8 @@
1
1
  <nav id="site-nav">
2
2
  <ul class="controls">
3
3
  <% for library in @config[:libraries] %>
4
- <li <% if current_page == library[:id].to_s %>class="current"<% end %>>
5
- <a href='<%= url("/libraries/#{library[:id]}") %>'>
6
- <%= library[:label] %>
7
- </a>
4
+ <li <% if current_page?(library) %>class="current"<% end %>>
5
+ <a href="<%= library_url(library) %>"><%= library[:label] %></a>
8
6
  </li>
9
7
  <% end %>
10
8
  </ul>
@@ -4,8 +4,8 @@
4
4
  <section class="card">
5
5
  <p>You are currently logged in as <b><%= @username %></b>.</p>
6
6
  <div class="controls --align-right">
7
- <a href="/admin">Back</a>
8
- <form action="<%= url('/change-password') %>">
7
+ <a href="<%= root_url %>">Back</a>
8
+ <form action="<%= change_password_url %>">
9
9
  <button type="submit">Change password</button>
10
10
  </form>
11
11
  </div>
@@ -7,14 +7,8 @@
7
7
  <% for option in field[:options] %>
8
8
  <option
9
9
  value="<%= option[:value] %>"
10
- <% if field[:id] == "published" %>
11
- <% if option[:value] == true && @item.published? %>
12
- selected
13
- <% end %>
14
- <% else %>
15
- <% if option[:value].to_s == @item.field_value_or_default(field[:id]) %>
16
- selected
17
- <% end %>
10
+ <% if option[:value].to_s == @item.published?.to_s %>
11
+ selected
18
12
  <% end %>
19
13
  >
20
14
  <%= option[:label] %>
@@ -78,7 +78,9 @@ th {
78
78
  }
79
79
 
80
80
  th.date,
81
- td.date > * {
81
+ td.date > *,
82
+ th.status,
83
+ td.status > * {
82
84
  width: 7rem;
83
85
  text-align: right;
84
86
  }
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.6
4
+ version: 0.1.7
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-03 00:00:00.000000000 Z
11
+ date: 2025-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt