panda_cms 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5a953aae667e1d450d28af607ecdc6c6cc0aa87ae622519c59362b7fc90385f
4
- data.tar.gz: b465ff1fa193637da7ad4f6fa5bd5128b86f8bf2f16d365ae80adc7467759e2c
3
+ metadata.gz: 23e115d751f17c8f528f17626e520797d040f582219836ba9b2fa996609cdc7b
4
+ data.tar.gz: 171b6cfcea626582610a896d7197f50abb6fa436aade77c15291d50a21ac528c
5
5
  SHA512:
6
- metadata.gz: 04e44f0c39f269a83611ad87ddbc09fb1ac7f195dc66403b10d38201f241303a248609cc3fc62763f9a7077c5c0b4b4348d2da4dfe4c6c6aa467ced31ad0e5fe
7
- data.tar.gz: edf4e1d30a60504886385f0615a5e64a3f19a2303ee155e0821829c21e8da14c302324447b1b62e9f10f3541cad89d64aa85b6665206676c02b20432b6019e2b
6
+ metadata.gz: 93cf0d36e41110790a6e9e08361dbfb843fb8607a5795a016247b2d4a9aa909d75bd4ef9f6af71a31ed7f9e967ac21eee6a0f80315caccad66bb790c1664d2c1
7
+ data.tar.gz: 25b6b5455c97a1a791edb38667890928d10ea5cdf29249f7d9e689911919ad9225f785eab6e94c41d8494726a9b03d83537b93f86a79f2825f8ce02f330e7d09
@@ -68,7 +68,7 @@ module PandaCms
68
68
  # @return PandaCms::post
69
69
  def post
70
70
  @post ||= if params[:id]
71
- PandaCms::Post.find(params[:id])
71
+ PandaCms::Post.find_by_slug(params[:id])
72
72
  else
73
73
  PandaCms::Post.new
74
74
  end
@@ -4,7 +4,7 @@ module PandaCms
4
4
  end
5
5
 
6
6
  def show
7
- post = PandaCms::Post.find_by(slug: "/" + params[:slug])
7
+ post = PandaCms::Post.find_by(slug: params[:slug])
8
8
 
9
9
  # TODO: Make this much nicer in future
10
10
  globals = {
@@ -47,8 +47,8 @@ module PandaCms
47
47
  "text-white hover:bg-mid/60 transition-all group flex gap-x-3 py-3 px-2 mb-2 rounded-md text-base leading-6 font-normal "
48
48
  end
49
49
 
50
- def table_indent(item_with_level_attribute)
51
- case item_with_level_attribute.level
50
+ def level_indent(level)
51
+ case level
52
52
  when 0
53
53
  "ml-0"
54
54
  when 1
@@ -76,6 +76,10 @@ module PandaCms
76
76
  end
77
77
  end
78
78
 
79
+ def table_indent(item_with_level_attribute)
80
+ level_indent(item_with_level_attribute.level)
81
+ end
82
+
79
83
  def menu_indent(item_with_level_attribute)
80
84
  case item_with_level_attribute.level
81
85
  when 0
@@ -1,23 +1,51 @@
1
- import { Controller as PandaCmsController } from "@hotwired/stimulus"
1
+ import { Controller as PandaCmsController } from "@hotwired/stimulus";
2
2
  export default class extends PandaCmsController {
3
- static targets = [ "existing_root", "input_select", "input_text", "output_text" ]
3
+ static targets = [
4
+ "existing_root",
5
+ "input_select",
6
+ "input_text",
7
+ "output_text",
8
+ ];
4
9
 
5
- connect() {
6
- }
10
+ connect() {}
7
11
 
8
12
  generatePath() {
9
- this.output_textTarget.value = "/" + this.createSlug(this.input_textTarget.value);
13
+ this.output_textTarget.value =
14
+ "/" + this.createSlug(this.input_textTarget.value);
10
15
  }
11
16
 
12
17
  setPrePath() {
13
- this.parent_slugs = this.input_selectTarget.options[this.input_selectTarget.selectedIndex].text.match(/.*\((.*)\)$/)[1];
14
- this.output_textTarget.previousSibling.innerHTML = (this.existing_rootTarget.value + this.parent_slugs).replace(/\/$/, '');;
18
+ this.parent_slugs =
19
+ this.input_selectTarget.options[
20
+ this.input_selectTarget.selectedIndex
21
+ ].text.match(/.*\((.*)\)$/)[1];
22
+ this.output_textTarget.previousSibling.innerHTML = (
23
+ this.existing_rootTarget.value + this.parent_slugs
24
+ ).replace(/\/$/, "");
15
25
  }
16
26
 
27
+ // TODO: Invoke a library or helper which can be shared with the backend
28
+ // and check for uniqueness at the same time
17
29
  createSlug(input) {
18
- return input.toLowerCase().trim()
30
+ var str = input
31
+ .toLowerCase()
32
+ .trim()
19
33
  .replace(/[^\w\s-]/g, "-")
20
- .replace(/&/, "and")
21
- .replace(/[\s_-]+/g, "-");
34
+ .replace(/&/g, "and")
35
+ .replace(/[\s_-]+/g, "-")
36
+ .trim();
37
+
38
+ return this.trimStartEnd(str, "-");
39
+ }
40
+
41
+ trimStartEnd(str, ch) {
42
+ var start = 0,
43
+ end = str.length;
44
+
45
+ while (start < end && str[start] === ch) ++start;
46
+
47
+ while (end > start && str[end - 1] === ch) --end;
48
+
49
+ return start > 0 || end < str.length ? str.substring(start, end) : str;
22
50
  }
23
51
  }
@@ -27,8 +27,14 @@ module PandaCms
27
27
  archived: "archived"
28
28
  }
29
29
 
30
- def excerpt(length = 100)
31
- content.gsub(/<[^>]*>/, "").truncate(length).html_safe
30
+ def to_param
31
+ slug.to_s
32
+ end
33
+
34
+ def excerpt(length = 100, squish: true)
35
+ excerpt = post_content.to_plain_text
36
+ excerpt = excerpt.squish if squish
37
+ excerpt.truncate(length).html_safe
32
38
  end
33
39
 
34
40
  def path
@@ -7,7 +7,7 @@
7
7
  <% table.column("Title") do |post| %>
8
8
  <div class="">
9
9
  <%= link_to post.title, edit_admin_post_path(post), class: "block h-full w-full" %>
10
- <span class="block text-xs text-black/60"><%= post.path %></span>
10
+ <span class="block text-xs text-black/60"><%= post_path(post) %></span>
11
11
  </div>
12
12
  <% end %>
13
13
  <% table.column("Status") { |post| render PandaCms::Admin::TagComponent.new(status: post.status) } %>
@@ -1,3 +1,3 @@
1
1
  module PandaCms
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Panda Software Limited