seiten 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/seiten/pages_controller.rb +19 -2
- data/app/helpers/seiten_helper.rb +11 -8
- data/config/initializers/seiten.rb +1 -0
- data/lib/seiten/controllers/helpers.rb +1 -1
- data/lib/seiten/page.rb +29 -23
- data/lib/seiten/page_store.rb +71 -6
- data/lib/seiten/routes_helper.rb +16 -0
- data/lib/seiten/version.rb +1 -1
- data/lib/seiten.rb +5 -3
- data/test/dummy/app/pages/de/produkte.html.erb +1 -0
- data/test/dummy/app/pages/en/about/partners.html.erb +1 -0
- data/test/dummy/app/pages/en/products.html.erb +1 -0
- data/test/dummy/app/pages/localization.html.erb +1 -0
- data/test/dummy/config/navigation/de.yml +36 -0
- data/test/dummy/config/navigation/en.yml +37 -0
- data/test/dummy/config/navigation.yml +3 -1
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/log/development.log +7019 -2550
- data/test/dummy/log/test.log +11327 -3072
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -1
- data/test/integration/i18n_test.rb +37 -0
- data/test/integration/navigation_test.rb +7 -1
- data/test/page_test.rb +9 -5
- data/test/seiten_test.rb +4 -2
- data/test/test_helper.rb +0 -5
- metadata +48 -24
- data/app/views/seiten/pages/show.html.erb +0 -1
- data/config/routes.rb +0 -11
- data/test/dummy/app/pages/about/partners.html.erb +0 -1
- data/test/dummy/app/pages/products.html.erb +0 -0
- /data/test/dummy/app/pages/{about → en/about}/our-team/italy.html.erb +0 -0
- /data/test/dummy/app/pages/{about → en/about}/our-team/switzerland.html.erb +0 -0
- /data/test/dummy/app/pages/{about → en/about}/our-team.html.erb +0 -0
- /data/test/dummy/app/pages/{about → en/about}/works.html.erb +0 -0
- /data/test/dummy/app/pages/{contact.html.erb → en/contact.html.erb} +0 -0
- /data/test/dummy/app/pages/{home.html.erb → en/home.html.erb} +0 -0
- /data/test/dummy/app/pages/{products → en/products}/logo-design.html.erb +0 -0
- /data/test/dummy/app/pages/{products → en/products}/web-development.html.erb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c07bb134e2faeb0ba5dd11af57a067fef28ceeb2
|
4
|
+
data.tar.gz: 94f0e43ea9839d4bf1598ef7c63e0c8bb39a590a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 341550a0f7cdd4b7e6a9a01b685c70796b6ec8007b13256482c5a028c95e0ada6d42e164994926c5cf4307d819d085944c10874e3e91ca2c9de95e10ef8defb6
|
7
|
+
data.tar.gz: 6657f6f1f45308fcab547c3dff423355c8ac887a154178a545230647829a824ace2361d921c3d94e6739288fe3a99a52a4b9f36d8ad586ebddd9f498b913bcbf
|
@@ -3,10 +3,27 @@ module Seiten
|
|
3
3
|
|
4
4
|
def show
|
5
5
|
if current_page.nil?
|
6
|
-
|
6
|
+
raise ActionController::RoutingError.new("Page /#{params[:page]} not found")
|
7
7
|
else
|
8
8
|
@title = current_page.title
|
9
|
-
|
9
|
+
|
10
|
+
if params[:page]
|
11
|
+
filename = params[:page]
|
12
|
+
else
|
13
|
+
filename = Seiten.config[:root_page_filename]
|
14
|
+
end
|
15
|
+
|
16
|
+
if File.exists? Seiten::PageStore.current.file_path(filename: "#{filename}.html.erb", locale: I18n.locale)
|
17
|
+
file = Seiten::PageStore.current.file_path(filename: filename, locale: I18n.locale)
|
18
|
+
else
|
19
|
+
file = Seiten::PageStore.current.file_path(filename: filename)
|
20
|
+
end
|
21
|
+
|
22
|
+
if current_page.layout
|
23
|
+
render file: file, layout: current_page.layout
|
24
|
+
else
|
25
|
+
render file: file
|
26
|
+
end
|
10
27
|
end
|
11
28
|
end
|
12
29
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module SeitenHelper
|
2
2
|
|
3
|
-
def
|
4
|
-
if
|
5
|
-
|
3
|
+
def link_to_seiten_page(title, slug, options={})
|
4
|
+
if !!(slug.to_s.match(/^https?:\/\/.+/))
|
5
|
+
link_to title, slug
|
6
|
+
elsif slug == nil
|
7
|
+
link_to title, seiten_page_path(page: "")
|
6
8
|
else
|
7
|
-
|
9
|
+
link_to title, seiten_page_path(page: slug)
|
8
10
|
end
|
9
|
-
render :file => File.join(Rails.root, Seiten.config[:storage_directory], filename)
|
10
11
|
end
|
11
12
|
|
12
13
|
def seiten_navigation(options={})
|
@@ -17,7 +18,7 @@ module SeitenHelper
|
|
17
18
|
if deep > 0
|
18
19
|
Seiten::Page.find_by_parent_id(parent_id).each do |page|
|
19
20
|
status = page.active?(current_page) ? "active" : "inactive"
|
20
|
-
output += "<li class='#{status}'>#{
|
21
|
+
output += "<li class='#{status}'>#{link_to_seiten_page(page.title, page.slug)}"
|
21
22
|
unless page.children.blank?
|
22
23
|
output += seiten_navigation(parent_id: page.id, deep: deep-1)
|
23
24
|
end
|
@@ -28,12 +29,14 @@ module SeitenHelper
|
|
28
29
|
raw output
|
29
30
|
end
|
30
31
|
|
31
|
-
def seiten_breadcrumb
|
32
|
+
def seiten_breadcrumb(options={})
|
33
|
+
link_separator = options[:link_separator] || ">"
|
34
|
+
|
32
35
|
if current_page
|
33
36
|
output = content_tag(:ul, class: "breadcrumb") do
|
34
37
|
Seiten::Page.get_breadcrumb(current_page).reverse.collect { |page|
|
35
38
|
content_tag :li do
|
36
|
-
raw "
|
39
|
+
raw "#{link_separator} #{link_to_seiten_page(page.title, page.slug)}"
|
37
40
|
end
|
38
41
|
}.join().html_safe
|
39
42
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Seiten::PageStore.initialize_page_stores
|
data/lib/seiten/page.rb
CHANGED
@@ -14,34 +14,40 @@ module Seiten
|
|
14
14
|
@layout = options[:layout]
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
page_store = PageStore.new
|
19
|
-
page_store.load_pages
|
20
|
-
end
|
17
|
+
class << self
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
19
|
+
def all
|
20
|
+
Seiten::PageStore.current.pages
|
21
|
+
end
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
# find page by id
|
24
|
+
def find(id)
|
25
|
+
all.select { |page| page.id == id }.first
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# find all pages by parent_id
|
29
|
+
def find_by_parent_id(parent_id)
|
30
|
+
all.select { |page| page.parent_id == parent_id }
|
31
|
+
end
|
32
|
+
|
33
|
+
# find a page by slug
|
34
|
+
def find_by_slug(slug)
|
35
|
+
if slug
|
36
|
+
slug = slug[1..-1] if slug[0] == "/"
|
37
|
+
end
|
38
|
+
all.select { |page| page.slug == slug }.first
|
39
|
+
end
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
# get breadcrumb of given page (reversed)
|
42
|
+
def get_breadcrumb(page)
|
43
|
+
pages ||= []
|
44
|
+
pages << page
|
45
|
+
if page.parent
|
46
|
+
pages << get_breadcrumb(page.parent)
|
47
|
+
end
|
48
|
+
pages.flatten
|
43
49
|
end
|
44
|
-
|
50
|
+
|
45
51
|
end
|
46
52
|
|
47
53
|
# get parent of page
|
data/lib/seiten/page_store.rb
CHANGED
@@ -2,21 +2,84 @@ module Seiten
|
|
2
2
|
|
3
3
|
class PageStore
|
4
4
|
|
5
|
-
attr_accessor :storage_type, :storage_file, :storage_directory
|
5
|
+
attr_accessor :storage_type, :storage_file, :storage_language, :storage_directory, :pages
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
@storage_type = options[:storage_type]
|
9
|
-
@
|
8
|
+
@storage_type = options[:storage_type] || Seiten.config[:default_storage_type]
|
9
|
+
@storage_directory = options[:storage_directory] || File.join(Rails.root, Seiten.config[:default_storage_directory])
|
10
|
+
@storage_language = options[:storage_language] || I18n.locale
|
11
|
+
@storage_language = @storage_language.to_sym
|
12
|
+
@storage_file = options[:storage_file] || load_storage_file
|
13
|
+
@pages = load_pages
|
14
|
+
end
|
15
|
+
|
16
|
+
# def self.new(options={})
|
17
|
+
# page_store = super(options)
|
18
|
+
# self.storages << page_store
|
19
|
+
# # page_store_key = options[:page_store_key] || options[:storage_languagea
|
20
|
+
# # options.delete :page_store_key if options[:page_store_key]
|
21
|
+
# # new_page_store = super(options)
|
22
|
+
# # Seiten.page_store[page_store_key] = new_page_store
|
23
|
+
# end
|
24
|
+
|
25
|
+
@storages = []
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
def storages
|
30
|
+
@storages
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_by_locale(locale=I18n.locale)
|
34
|
+
storages.select { |storage| storage.storage_language == locale }.first
|
35
|
+
end
|
36
|
+
alias_method :current, :find_by_locale
|
37
|
+
|
38
|
+
def initialize_page_stores
|
39
|
+
if File.directory?(File.join(Rails.root, Seiten.config[:default_storage_file]))
|
40
|
+
Dir[File.join(Rails.root, Seiten.config[:default_storage_file], "*.yml")].each do |file|
|
41
|
+
locale = File.basename(file, '.yml')
|
42
|
+
Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: locale)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: I18n.default_locale)
|
46
|
+
end
|
47
|
+
end
|
10
48
|
|
11
|
-
|
12
|
-
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_storage_file
|
52
|
+
if File.exists?(File.join(Rails.root, Seiten.config[:default_storage_file], "#{storage_language}.yml"))
|
53
|
+
File.join(Rails.root, Seiten.config[:default_storage_file], "#{storage_language}.yml")
|
54
|
+
else
|
55
|
+
File.join(Rails.root, "#{Seiten.config[:default_storage_file]}.yml")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def file_path(options={})
|
60
|
+
File.join(storage_directory, options[:locale].to_s, options[:filename])
|
13
61
|
end
|
14
62
|
|
15
63
|
def build_link(page, prefix_url="")
|
64
|
+
|
65
|
+
# if url is nil parameterize title otherwise just use url
|
16
66
|
slug = page["url"].nil? ? page["title"].parameterize : page["url"]
|
17
|
-
|
67
|
+
|
68
|
+
# prepend prefix_url if slug is not root or external url
|
69
|
+
unless slug[0] == "/" || !!(slug.match(/^https?:\/\/.+/)) || !prefix_url.present?
|
18
70
|
slug = "#{prefix_url}/#{slug}"
|
19
71
|
end
|
72
|
+
|
73
|
+
# return nil if page slug is /
|
74
|
+
if slug == "/" || page["root"] == true
|
75
|
+
slug = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
# remove leading slash if present
|
79
|
+
if slug
|
80
|
+
slug = slug[1..-1] if slug[0] == "/"
|
81
|
+
end
|
82
|
+
|
20
83
|
slug
|
21
84
|
end
|
22
85
|
|
@@ -67,6 +130,8 @@ module Seiten
|
|
67
130
|
if page["redirect"]
|
68
131
|
if page["redirect"].is_a?(TrueClass)
|
69
132
|
page["redirect"] = build_link(page["nodes"].first, page["slug"])
|
133
|
+
else
|
134
|
+
page["redirect"] = page["redirect"][1..-1] if page["redirect"][0] == "/"
|
70
135
|
end
|
71
136
|
end
|
72
137
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ActionDispatch::Routing::Mapper
|
2
|
+
|
3
|
+
def seiten_resources
|
4
|
+
Seiten::PageStore.storages.each do |page_store|
|
5
|
+
page_store.pages.each do |page|
|
6
|
+
if page.redirect
|
7
|
+
get page.slug, to: redirect { |p, req|
|
8
|
+
Rails.application.routes.url_helpers.seiten_page_path(page: page.redirect, locale: p[:locale])
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
get "(*page)" => "seiten/pages#show", as: :seiten_page
|
15
|
+
end
|
16
|
+
end
|
data/lib/seiten/version.rb
CHANGED
data/lib/seiten.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'seiten/engine'
|
2
2
|
require 'seiten/page_store'
|
3
3
|
require 'seiten/page'
|
4
|
+
require 'seiten/routes_helper'
|
4
5
|
|
5
6
|
module Seiten
|
6
7
|
|
7
8
|
@config = {
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
default_storage_type: :yaml,
|
10
|
+
default_storage_file: File.join('config', 'navigation'),
|
11
|
+
default_storage_directory: File.join('app', 'pages'),
|
12
|
+
root_page_filename: "home"
|
11
13
|
}
|
12
14
|
|
13
15
|
def self.config
|
@@ -0,0 +1 @@
|
|
1
|
+
Das ist die Produkte Seite
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= seiten_navigation parent_id: Seiten::Page.find_by_slug("about/partners").id %>
|
@@ -0,0 +1 @@
|
|
1
|
+
This is the products page
|
@@ -0,0 +1 @@
|
|
1
|
+
I18n is in root
|
@@ -0,0 +1,36 @@
|
|
1
|
+
- title: "Home"
|
2
|
+
url: "/"
|
3
|
+
layout: "home"
|
4
|
+
|
5
|
+
- title: "Produkte"
|
6
|
+
layout:
|
7
|
+
name: "products"
|
8
|
+
inherit: true
|
9
|
+
nodes:
|
10
|
+
- title: "Logo Design"
|
11
|
+
- title: "Web Development"
|
12
|
+
- title: "Heuere uns an"
|
13
|
+
redirect: "/kontakt" # links to Contact page
|
14
|
+
|
15
|
+
- title: "Über uns"
|
16
|
+
redirect: true # redirects /about to /about/our-team
|
17
|
+
nodes:
|
18
|
+
- title: "Unser Team"
|
19
|
+
layout:
|
20
|
+
name: "team"
|
21
|
+
inherit: false
|
22
|
+
nodes:
|
23
|
+
- title: "Schweiz"
|
24
|
+
- title: "Italien"
|
25
|
+
- title: "Arbeiten"
|
26
|
+
- title: "Partner"
|
27
|
+
nodes:
|
28
|
+
- title: "Daniel Puglisi"
|
29
|
+
url: "http://danielpuglisi.com"
|
30
|
+
- title: "Codegestalt"
|
31
|
+
url: "http://codegestalt.com"
|
32
|
+
- title: "Kreatify"
|
33
|
+
url: "http://kreatify.com"
|
34
|
+
|
35
|
+
- title: "Kontakt"
|
36
|
+
- title: "I18n"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
- title: "Home"
|
2
|
+
root: true
|
3
|
+
layout: "home"
|
4
|
+
|
5
|
+
- title: "Products"
|
6
|
+
layout:
|
7
|
+
name: "products"
|
8
|
+
inherit: true
|
9
|
+
nodes:
|
10
|
+
- title: "Logo Design"
|
11
|
+
- title: "Web Development"
|
12
|
+
- title: "Hire us"
|
13
|
+
redirect: "/contact" # links to Contact page
|
14
|
+
|
15
|
+
- title: "About"
|
16
|
+
redirect: true # redirects /about to /about/our-team
|
17
|
+
nodes:
|
18
|
+
- title: "Our Team"
|
19
|
+
layout:
|
20
|
+
name: "team"
|
21
|
+
inherit: false
|
22
|
+
nodes:
|
23
|
+
- title: "Switzerland"
|
24
|
+
- title: "Italy"
|
25
|
+
- title: "Works"
|
26
|
+
- title: "Partners"
|
27
|
+
nodes:
|
28
|
+
- title: "Daniel Puglisi"
|
29
|
+
url: "http://danielpuglisi.com"
|
30
|
+
- title: "Codegestalt"
|
31
|
+
url: "http://codegestalt.com"
|
32
|
+
- title: "Kreatify"
|
33
|
+
url: "http://kreatify.com"
|
34
|
+
|
35
|
+
- title: "Contact"
|
36
|
+
- title: "I18n"
|
37
|
+
url: "/localization"
|