seiten 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: cdca338d9f41a0024b0b90dc5c87c7f602ad00aa
4
- data.tar.gz: ecb1044492d591194e9f1e7828193eb00ac96cd3
3
+ metadata.gz: a0ff873128338069249737ba993b223217dd98a8
4
+ data.tar.gz: 940a0ebd9ce9c3edce4902f88936b3f6e2a9fb65
5
5
  SHA512:
6
- metadata.gz: c27b5a89c616ea6d2ed275a9368baa8c25a63da8bef13d412913fa64841f880d27f1ad579877f32e490d71190a36a4493db9ddbc9e917982f7c2e1b8961c434e
7
- data.tar.gz: a243c6e2addbe1daaee53cdd46717bf8266801df708a0be0215569a9b3c0a7eeaa1f1263087575e7aadb213da7be710ddfbf22527e012223f32e85c405019602
6
+ metadata.gz: d776bf9d134f8d295b97f570e6429fd92e76f8e3d8bc550f9998c9ef69a3b93464a17120db62a2edc6ca2439eea8cb662ab96408f7f76d6456877dcbe6589b64
7
+ data.tar.gz: 2ab6292b960d3fae73d9cff0e1344a997b6312c35a61af06ae261cb2197fc7a5486de44d2d21d7701b04ef5211fc5a7f11bd466d2f0b78e71276a246000f2472
@@ -6,6 +6,7 @@ module Seiten
6
6
  head :not_found
7
7
  else
8
8
  @title = current_page.title
9
+ render layout: current_page.layout if current_page.layout
9
10
  end
10
11
  end
11
12
  end
@@ -23,8 +23,9 @@ module SeitenHelper
23
23
  end
24
24
  output += "</li>"
25
25
  end
26
+ output = "<ul>#{output}</ul>"
26
27
  end
27
- raw "<ul>#{output}</ul>"
28
+ raw output
28
29
  end
29
30
 
30
31
  def seiten_breadcrumb
data/config/routes.rb CHANGED
@@ -3,7 +3,7 @@ Rails.application.routes.draw do
3
3
  # Redirects
4
4
  Seiten::Page.all.each do |page|
5
5
  if page.redirect
6
- get page.slug => redirect(page.children.first.slug)
6
+ get page.slug => redirect(page.redirect)
7
7
  end
8
8
  end
9
9
 
data/lib/seiten/page.rb CHANGED
@@ -2,7 +2,7 @@ module Seiten
2
2
 
3
3
  class Page
4
4
 
5
- attr_accessor :id, :parent_id, :title, :children, :slug, :redirect
5
+ attr_accessor :id, :parent_id, :title, :children, :slug, :redirect, :layout
6
6
 
7
7
  # initialize Page object with attributes
8
8
  def initialize(options={})
@@ -11,6 +11,7 @@ module Seiten
11
11
  @title = options[:title]
12
12
  @slug = options[:slug]
13
13
  @redirect = options[:redirect]
14
+ @layout = options[:layout]
14
15
  end
15
16
 
16
17
  def self.all
@@ -12,41 +12,69 @@ module Seiten
12
12
  @storage_file ||= File.join(Rails.root, Seiten.config[:storage_file])
13
13
  end
14
14
 
15
+ def build_link(page, prefix_url="")
16
+ slug = page["url"].nil? ? page["title"].parameterize : page["url"]
17
+ unless slug[0] == "/" || !!(slug.match(/^https?:\/\/.+/))
18
+ slug = "#{prefix_url}/#{slug}"
19
+ end
20
+ slug
21
+ end
22
+
15
23
  def load_pages(options={})
16
24
 
17
- pages = options[:pages]
18
- parent_id = options[:parent_id]
19
- url = options[:url]
25
+ pages = options[:pages]
26
+ parent_id = options[:parent_id] # || nil
27
+ layout = options[:layout]
28
+ prefix_url = options[:prefix_url] || ""
20
29
 
21
30
  # Setting default values
22
31
  if storage_type == :yaml
23
32
  pages ||= YAML.load_file(storage_file)
24
33
  end
25
- parent_id ||= nil
26
- url ||= ""
34
+
27
35
  @id ||= 1
28
36
  @navigation ||= []
29
37
 
30
38
  pages.each_index do |i|
31
39
 
40
+ # Load page and set parent_id and generated page id
32
41
  page = pages[i]
33
42
  page["id"] = @id
34
43
  page["parent_id"] = parent_id
44
+ page["layout"] ||= layout
45
+
46
+ # Increment generated id
35
47
  @id += 1
36
48
 
37
49
  # Build link
38
- slug = page["url"].nil? ? page["title"].parameterize : page["url"]
39
- if slug[0] == "/" || !!(slug.match(/^https?:\/\/.+/))
40
- page["slug"] = slug
41
- else
42
- page["slug"] = "#{url}/#{slug}"
50
+ page["slug"] = build_link(page, prefix_url)
51
+
52
+ # Set layout
53
+ if page["layout"]
54
+ if page["layout"].is_a?(String)
55
+ inherited_layout = page["layout"]
56
+ elsif page["layout"].is_a?(Hash)
57
+ if page["layout"]["inherit"]
58
+ inherited_layout = page["layout"]
59
+ else
60
+ inherited_layout = nil
61
+ end
62
+ page["layout"] = page["layout"]["name"]
63
+ end
64
+ end
65
+
66
+ # Set redirect
67
+ if page["redirect"]
68
+ if page["redirect"].is_a?(TrueClass)
69
+ page["redirect"] = build_link(page["nodes"].first, page["slug"])
70
+ end
43
71
  end
44
72
 
73
+ # Load children
45
74
  if page["nodes"]
46
- load_pages(pages: page["nodes"], parent_id: page["id"], url: page["slug"])
75
+ load_pages(pages: page["nodes"], parent_id: page["id"], prefix_url: page["slug"], layout: inherited_layout)
47
76
  end
48
77
 
49
- page.delete("nodes")
50
78
  page_params = page.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
51
79
  @navigation << Page.new(page_params)
52
80
  end
@@ -1,3 +1,3 @@
1
1
  module Seiten
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -8,6 +8,8 @@
8
8
  </head>
9
9
  <body>
10
10
 
11
+ <p>Default Layout</p>
12
+
11
13
  <h1>Navigation</h1>
12
14
  <%= seiten_navigation %>
13
15
 
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%# <%= javascript_include_tag "application" %1> %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <p>Home Layout</p>
12
+
13
+ <h1>Navigation</h1>
14
+ <%= seiten_navigation %>
15
+
16
+ <h1>Breadcrumb</h1>
17
+ <%= seiten_breadcrumb %>
18
+
19
+ <%= yield %>
20
+
21
+ </body>
22
+ </html>
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%# <%= javascript_include_tag "application" %1> %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <p>Products Layout</p>
12
+
13
+ <h1>Navigation</h1>
14
+ <%= seiten_navigation %>
15
+
16
+ <h1>Breadcrumb</h1>
17
+ <%= seiten_breadcrumb %>
18
+
19
+ <%= yield %>
20
+
21
+ </body>
22
+ </html>
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%# <%= javascript_include_tag "application" %1> %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <p>Team Layout</p>
12
+
13
+ <h1>Navigation</h1>
14
+ <%= seiten_navigation %>
15
+
16
+ <h1>Breadcrumb</h1>
17
+ <%= seiten_breadcrumb %>
18
+
19
+ <%= yield %>
20
+
21
+ </body>
22
+ </html>
@@ -1,17 +1,24 @@
1
1
  - title: "Home"
2
2
  url: "/"
3
+ layout: "home"
3
4
 
4
5
  - title: "Products"
6
+ layout:
7
+ name: "products"
8
+ inherit: true
5
9
  nodes:
6
10
  - title: "Logo Design"
7
11
  - title: "Web Development"
8
12
  - title: "Hire us"
9
- url: "/contact" # links to Contact page
13
+ redirect: "/contact" # links to Contact page
10
14
 
11
15
  - title: "About"
12
16
  redirect: true # redirects /about to /about/our-team
13
17
  nodes:
14
18
  - title: "Our Team"
19
+ layout:
20
+ name: "team"
21
+ inherit: false
15
22
  nodes:
16
23
  - title: "Switzerland"
17
24
  - title: "Italy"