seiten 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/seiten/pages_controller.rb +19 -2
  3. data/app/helpers/seiten_helper.rb +11 -8
  4. data/config/initializers/seiten.rb +1 -0
  5. data/lib/seiten/controllers/helpers.rb +1 -1
  6. data/lib/seiten/page.rb +29 -23
  7. data/lib/seiten/page_store.rb +71 -6
  8. data/lib/seiten/routes_helper.rb +16 -0
  9. data/lib/seiten/version.rb +1 -1
  10. data/lib/seiten.rb +5 -3
  11. data/test/dummy/app/pages/de/produkte.html.erb +1 -0
  12. data/test/dummy/app/pages/en/about/partners.html.erb +1 -0
  13. data/test/dummy/app/pages/en/products.html.erb +1 -0
  14. data/test/dummy/app/pages/localization.html.erb +1 -0
  15. data/test/dummy/config/navigation/de.yml +36 -0
  16. data/test/dummy/config/navigation/en.yml +37 -0
  17. data/test/dummy/config/navigation.yml +3 -1
  18. data/test/dummy/config/routes.rb +2 -0
  19. data/test/dummy/log/development.log +7019 -2550
  20. data/test/dummy/log/test.log +11327 -3072
  21. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  22. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  23. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  24. data/test/dummy/tmp/pids/server.pid +1 -1
  25. data/test/integration/i18n_test.rb +37 -0
  26. data/test/integration/navigation_test.rb +7 -1
  27. data/test/page_test.rb +9 -5
  28. data/test/seiten_test.rb +4 -2
  29. data/test/test_helper.rb +0 -5
  30. metadata +48 -24
  31. data/app/views/seiten/pages/show.html.erb +0 -1
  32. data/config/routes.rb +0 -11
  33. data/test/dummy/app/pages/about/partners.html.erb +0 -1
  34. data/test/dummy/app/pages/products.html.erb +0 -0
  35. /data/test/dummy/app/pages/{about → en/about}/our-team/italy.html.erb +0 -0
  36. /data/test/dummy/app/pages/{about → en/about}/our-team/switzerland.html.erb +0 -0
  37. /data/test/dummy/app/pages/{about → en/about}/our-team.html.erb +0 -0
  38. /data/test/dummy/app/pages/{about → en/about}/works.html.erb +0 -0
  39. /data/test/dummy/app/pages/{contact.html.erb → en/contact.html.erb} +0 -0
  40. /data/test/dummy/app/pages/{home.html.erb → en/home.html.erb} +0 -0
  41. /data/test/dummy/app/pages/{products → en/products}/logo-design.html.erb +0 -0
  42. /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: a0ff873128338069249737ba993b223217dd98a8
4
- data.tar.gz: 940a0ebd9ce9c3edce4902f88936b3f6e2a9fb65
3
+ metadata.gz: c07bb134e2faeb0ba5dd11af57a067fef28ceeb2
4
+ data.tar.gz: 94f0e43ea9839d4bf1598ef7c63e0c8bb39a590a
5
5
  SHA512:
6
- metadata.gz: d776bf9d134f8d295b97f570e6429fd92e76f8e3d8bc550f9998c9ef69a3b93464a17120db62a2edc6ca2439eea8cb662ab96408f7f76d6456877dcbe6589b64
7
- data.tar.gz: 2ab6292b960d3fae73d9cff0e1344a997b6312c35a61af06ae261cb2197fc7a5486de44d2d21d7701b04ef5211fc5a7f11bd466d2f0b78e71276a246000f2472
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
- head :not_found
6
+ raise ActionController::RoutingError.new("Page /#{params[:page]} not found")
7
7
  else
8
8
  @title = current_page.title
9
- render layout: current_page.layout if current_page.layout
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 render_html
4
- if params[:page]
5
- filename = params[:page]
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
- filename = "home"
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}'>#{link_to(page.title, page.slug)}"
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 "> #{link_to(page.title, page.slug)}"
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
@@ -9,7 +9,7 @@ module Seiten
9
9
  end
10
10
 
11
11
  def current_page
12
- @current_page ||= Seiten::Page.find_by_slug(request.fullpath)
12
+ @current_page ||= Seiten::Page.find_by_slug(params[:page])
13
13
  end
14
14
  end
15
15
  end
data/lib/seiten/page.rb CHANGED
@@ -14,34 +14,40 @@ module Seiten
14
14
  @layout = options[:layout]
15
15
  end
16
16
 
17
- def self.all
18
- page_store = PageStore.new
19
- page_store.load_pages
20
- end
17
+ class << self
21
18
 
22
- # find page by id
23
- def self.find(id)
24
- Page.all.select { |page| page.id == id }.first
25
- end
19
+ def all
20
+ Seiten::PageStore.current.pages
21
+ end
26
22
 
27
- # find all pages by parent_id
28
- def self.find_by_parent_id(parent_id)
29
- Page.all.select { |page| page.parent_id == parent_id }
30
- end
23
+ # find page by id
24
+ def find(id)
25
+ all.select { |page| page.id == id }.first
26
+ end
31
27
 
32
- # find a page by slug
33
- def self.find_by_slug(slug)
34
- Page.all.select { |page| page.slug == slug }.first
35
- end
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
- # get breadcrumb of given page (reversed)
38
- def self.get_breadcrumb(page)
39
- pages ||= []
40
- pages << page
41
- if page.parent
42
- pages << Page.get_breadcrumb(page.parent)
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
- pages.flatten
50
+
45
51
  end
46
52
 
47
53
  # get parent of page
@@ -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
- @storage_file = options[:storage_file]
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
- @storage_type ||= Seiten.config[:storage_type]
12
- @storage_file ||= File.join(Rails.root, Seiten.config[:storage_file])
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
- unless slug[0] == "/" || !!(slug.match(/^https?:\/\/.+/))
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
@@ -1,3 +1,3 @@
1
1
  module Seiten
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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
- storage_type: :yaml,
9
- storage_file: File.join('config', 'navigation.yml'),
10
- storage_directory: File.join('app', 'pages')
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"
@@ -1,5 +1,5 @@
1
1
  - title: "Home"
2
- url: "/"
2
+ root: true
3
3
  layout: "home"
4
4
 
5
5
  - title: "Products"
@@ -33,3 +33,5 @@
33
33
  url: "http://kreatify.com"
34
34
 
35
35
  - title: "Contact"
36
+ - title: "I18n"
37
+ url: "/localization"
@@ -2,4 +2,6 @@ Dummy::Application.routes.draw do
2
2
  root :to => "seiten/pages#show"
3
3
 
4
4
  get "/secret", to: "pages#secret"
5
+
6
+ seiten_resources
5
7
  end