seiten 0.0.6 → 1.0.0

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.
Files changed (104) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +1 -0
  3. data/app/controllers/seiten/pages_controller.rb +2 -23
  4. data/config/initializers/seiten.rb +1 -1
  5. data/lib/seiten/errors/base_error.rb +4 -0
  6. data/lib/seiten/errors/page_error.rb +4 -0
  7. data/lib/seiten/errors/routing_error.rb +4 -0
  8. data/lib/seiten/helpers/backend.rb +23 -0
  9. data/lib/seiten/helpers/current.rb +33 -0
  10. data/lib/seiten/helpers/frontend.rb +19 -0
  11. data/lib/seiten/html/breadcrumb.rb +41 -0
  12. data/lib/seiten/html/helpers.rb +32 -0
  13. data/lib/seiten/html/navigation.rb +39 -0
  14. data/lib/seiten/navigation.rb +43 -0
  15. data/lib/seiten/page.rb +82 -40
  16. data/lib/seiten/page_collection.rb +54 -0
  17. data/lib/seiten/page_collection_builder.rb +63 -0
  18. data/lib/seiten/railtie.rb +7 -0
  19. data/lib/seiten/routes_helper.rb +16 -11
  20. data/lib/seiten/slug_builder.rb +32 -0
  21. data/lib/seiten/version.rb +1 -1
  22. data/lib/seiten.rb +63 -12
  23. data/test/controllers/helper_methods_test.rb +25 -0
  24. data/test/controllers/pages_controller_test.rb +9 -0
  25. data/test/controllers/posts_controller_test.rb +12 -0
  26. data/test/controllers/seiten/pages_controller_test.rb +39 -0
  27. data/test/dummy/app/controllers/application_controller.rb +10 -0
  28. data/test/dummy/app/controllers/pages_controller.rb +1 -1
  29. data/test/dummy/app/controllers/posts_controller.rb +10 -0
  30. data/test/dummy/app/helpers/application_helper.rb +1 -0
  31. data/test/dummy/app/pages/{de → application/de}/produkte.html.erb +0 -0
  32. data/test/dummy/app/pages/{en/about/our-team/switzerland.html.erb → application/en/about/our-team/italy.html.erb} +0 -0
  33. data/test/dummy/app/pages/{en/about/works.html.erb → application/en/about/our-team/switzerland.html.erb} +0 -0
  34. data/test/dummy/app/pages/application/en/about/our-team.html.erb +2 -0
  35. data/test/dummy/app/pages/application/en/about/partners.html.erb +1 -0
  36. data/test/dummy/app/pages/{en/contact.html.erb → application/en/about/works.html.erb} +0 -0
  37. data/test/dummy/app/pages/{en/about/our-team/italy.html.erb → application/en/about.html.erb} +0 -0
  38. data/test/dummy/app/pages/{en/products/logo-design.html.erb → application/en/contact.html.erb} +0 -0
  39. data/test/dummy/app/pages/{en → application/en}/home.html.erb +0 -0
  40. data/test/dummy/app/pages/{en/products/web-development.html.erb → application/en/products/hire-us.html.erb} +0 -0
  41. data/test/dummy/{db/test.sqlite3 → app/pages/application/en/products/logo-design.html.erb} +0 -0
  42. data/test/dummy/app/pages/application/en/products/web-development.html.erb +0 -0
  43. data/test/dummy/app/pages/{en → application/en}/products.html.erb +0 -0
  44. data/test/dummy/app/pages/{localization.html.erb → application/localization.html.erb} +0 -0
  45. data/test/dummy/app/pages/help/en/home.html.erb +0 -0
  46. data/test/dummy/app/pages/help/en/logging-in.html.erb +0 -0
  47. data/test/dummy/app/views/layouts/application.html.erb +1 -1
  48. data/test/dummy/app/views/layouts/home.html.erb +1 -1
  49. data/test/dummy/app/views/pages/secret.html.erb +1 -1
  50. data/test/dummy/app/views/posts/index.html.erb +1 -0
  51. data/test/dummy/config/application.rb +4 -41
  52. data/test/dummy/config/boot.rb +2 -9
  53. data/test/dummy/config/cable.yml +9 -0
  54. data/test/dummy/config/environments/development.rb +26 -21
  55. data/test/dummy/config/environments/production.rb +3 -0
  56. data/test/dummy/config/environments/test.rb +15 -19
  57. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  58. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  59. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  60. data/test/dummy/config/initializers/inflections.rb +6 -5
  61. data/test/dummy/config/initializers/mime_types.rb +0 -1
  62. data/test/dummy/config/initializers/new_framework_defaults.rb +20 -0
  63. data/test/dummy/config/initializers/session_store.rb +1 -6
  64. data/test/dummy/config/initializers/wrap_parameters.rb +5 -5
  65. data/test/dummy/config/{navigation/de.yml → navigations/application.de.yml} +5 -5
  66. data/test/dummy/config/{navigation.yml → navigations/application.en.yml} +21 -5
  67. data/test/dummy/config/navigations/help.en.yml +17 -0
  68. data/test/dummy/config/routes.rb +6 -3
  69. data/test/dummy/config/secrets.yml +22 -0
  70. data/test/dummy/log/development.log +1632 -8652
  71. data/test/dummy/log/test.log +43833 -13664
  72. data/test/fixtures/breadcrumb.html +1 -0
  73. data/test/fixtures/navigation.html +1 -0
  74. data/test/integration/layout_test.rb +10 -11
  75. data/test/integration/navigation_test.rb +50 -50
  76. data/test/lib/seiten/helpers/frontend_test.rb +37 -0
  77. data/test/lib/seiten/html/breadcrumb_test.rb +29 -0
  78. data/test/lib/seiten/html/helpers_test.rb +55 -0
  79. data/test/lib/seiten/html/navigation_test.rb +29 -0
  80. data/test/lib/seiten/navigation_test.rb +45 -0
  81. data/test/lib/seiten/page_collection_builder_test.rb +141 -0
  82. data/test/lib/seiten/page_collection_test.rb +59 -0
  83. data/test/lib/seiten/page_test.rb +188 -0
  84. data/test/lib/seiten/slug_builder_test.rb +47 -0
  85. data/test/lib/seiten_test.rb +16 -0
  86. data/test/test_helper.rb +2 -8
  87. metadata +136 -94
  88. data/app/helpers/seiten_helper.rb +0 -46
  89. data/lib/seiten/controllers/helpers.rb +0 -16
  90. data/lib/seiten/page_store.rb +0 -150
  91. data/test/dummy/app/assets/javascripts/application.js +0 -15
  92. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  93. data/test/dummy/app/pages/en/about/our-team.html.erb +0 -2
  94. data/test/dummy/app/pages/en/about/partners.html.erb +0 -1
  95. data/test/dummy/config/navigation/en.yml +0 -37
  96. data/test/dummy/db/development.sqlite3 +0 -0
  97. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  98. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  99. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  100. data/test/dummy/tmp/pids/server.pid +0 -1
  101. data/test/integration/i18n_test.rb +0 -37
  102. data/test/integration/redirect_test.rb +0 -15
  103. data/test/page_test.rb +0 -74
  104. data/test/seiten_test.rb +0 -9
@@ -1,46 +0,0 @@
1
- module SeitenHelper
2
-
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: "")
8
- else
9
- link_to title, seiten_page_path(page: slug)
10
- end
11
- end
12
-
13
- def seiten_navigation(options={})
14
- output ||= ""
15
- parent_id = options[:parent_id] || nil
16
- deep = options[:deep] || 2
17
-
18
- if deep > 0
19
- Seiten::Page.find_by_parent_id(parent_id).each do |page|
20
- status = page.active?(current_page) ? "active" : "inactive"
21
- output += "<li class='#{status}'>#{link_to_seiten_page(page.title, page.slug)}"
22
- unless page.children.blank?
23
- output += seiten_navigation(parent_id: page.id, deep: deep-1)
24
- end
25
- output += "</li>"
26
- end
27
- output = "<ul>#{output}</ul>"
28
- end
29
- raw output
30
- end
31
-
32
- def seiten_breadcrumb(options={})
33
- link_separator = options[:link_separator] || ">"
34
-
35
- if current_page
36
- output = content_tag(:ul, class: "breadcrumb") do
37
- Seiten::Page.get_breadcrumb(current_page).reverse.collect { |page|
38
- content_tag :li do
39
- raw "#{link_separator} #{link_to_seiten_page(page.title, page.slug)}"
40
- end
41
- }.join().html_safe
42
- end
43
- output
44
- end
45
- end
46
- end
@@ -1,16 +0,0 @@
1
- module Seiten
2
- module Controllers
3
- # Those helpers are convenience methods added to ApplicationController.
4
- module Helpers
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- helper_method :current_page
9
- end
10
-
11
- def current_page
12
- @current_page ||= Seiten::Page.find_by_slug(params[:page])
13
- end
14
- end
15
- end
16
- end
@@ -1,150 +0,0 @@
1
- module Seiten
2
-
3
- class PageStore
4
-
5
- attr_accessor :storage_type, :storage_file, :storage_language, :storage_directory, :pages
6
-
7
- def initialize(options={})
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
48
-
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])
61
- end
62
-
63
- def build_link(page, prefix_url="")
64
-
65
- # if url is nil parameterize title otherwise just use url
66
- slug = page["url"].nil? ? page["title"].parameterize : page["url"]
67
-
68
- # prepend prefix_url if slug is not root or external url
69
- unless slug[0] == "/" || !!(slug.match(/^https?:\/\/.+/)) || !prefix_url.present?
70
- slug = "#{prefix_url}/#{slug}"
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
-
83
- slug
84
- end
85
-
86
- def load_pages(options={})
87
-
88
- pages = options[:pages]
89
- parent_id = options[:parent_id] # || nil
90
- layout = options[:layout]
91
- prefix_url = options[:prefix_url] || ""
92
-
93
- # Setting default values
94
- if storage_type == :yaml
95
- pages ||= YAML.load_file(storage_file)
96
- end
97
-
98
- @id ||= 1
99
- @navigation ||= []
100
-
101
- pages.each_index do |i|
102
-
103
- # Load page and set parent_id and generated page id
104
- page = pages[i]
105
- page["id"] = @id
106
- page["parent_id"] = parent_id
107
- page["layout"] ||= layout
108
-
109
- # Increment generated id
110
- @id += 1
111
-
112
- # Build link
113
- page["slug"] = build_link(page, prefix_url)
114
-
115
- # Set layout
116
- if page["layout"]
117
- if page["layout"].is_a?(String)
118
- inherited_layout = page["layout"]
119
- elsif page["layout"].is_a?(Hash)
120
- if page["layout"]["inherit"]
121
- inherited_layout = page["layout"]
122
- else
123
- inherited_layout = nil
124
- end
125
- page["layout"] = page["layout"]["name"]
126
- end
127
- end
128
-
129
- # Set redirect
130
- if page["redirect"]
131
- if page["redirect"].is_a?(TrueClass)
132
- page["redirect"] = build_link(page["nodes"].first, page["slug"])
133
- else
134
- page["redirect"] = page["redirect"][1..-1] if page["redirect"][0] == "/"
135
- end
136
- end
137
-
138
- # Load children
139
- if page["nodes"]
140
- load_pages(pages: page["nodes"], parent_id: page["id"], prefix_url: page["slug"], layout: inherited_layout)
141
- end
142
-
143
- page_params = page.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
144
- @navigation << Page.new(page_params)
145
- end
146
-
147
- @navigation
148
- end
149
- end
150
- end
@@ -1,15 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
- //= require jquery
14
- //= require jquery_ujs
15
- //= require_tree .
@@ -1,13 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
@@ -1,2 +0,0 @@
1
- <h1>Subnavigation</h1>
2
- <%= seiten_navigation parent_id: Seiten::Page.find_by_slug("/about/our-team").id %>
@@ -1 +0,0 @@
1
- <%= seiten_navigation parent_id: Seiten::Page.find_by_slug("about/partners").id %>
@@ -1,37 +0,0 @@
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"
Binary file
@@ -1 +0,0 @@
1
- 80065
@@ -1,37 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nTest < ActionDispatch::IntegrationTest
4
-
5
- def test_returns_page_in_root_if_not_found_in_locale_directory
6
- visit "/localization"
7
- assert_equal 200, status_code
8
- assert has_content?("I18n is in root")
9
- end
10
-
11
- def test_returns_products_page_in_en_directory
12
- I18n.locale = :en
13
- visit "/products"
14
- assert has_content?("This is the products page")
15
- end
16
-
17
- def test_returns_products_page_in_de_directory
18
- I18n.locale = :de
19
- visit "/produkte"
20
- assert has_content?("Das ist die Produkte Seite")
21
- end
22
-
23
- def test_loads_de_navigation
24
- I18n.locale = :de
25
- assert_equal File.join(Rails.root, "config", "navigation", "de.yml"), Seiten::PageStore.new.storage_file
26
- end
27
-
28
- def test_loads_en_navigation
29
- I18n.locale = :en
30
- assert_equal File.join(Rails.root, "config", "navigation", "en.yml"), Seiten::PageStore.new.storage_file
31
- end
32
-
33
- # def test_loads_navigation_without_locale_if_not_found
34
- # I18n.locale = :fr
35
- # assert_equal File.join(Rails.root, "config", "navigation.yml"), Seiten::PageStore.new.storage_file
36
- # end
37
- end
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RedirectTest < ActionDispatch::IntegrationTest
4
-
5
- def test_redirects_to_specified_page
6
- visit "/"
7
- click_link "Hire us"
8
- assert_equal "/contact", current_path
9
- end
10
-
11
- def test_redirects_to_first_child_page
12
- visit "/about"
13
- assert_equal "/about/our-team", current_path
14
- end
15
- end
data/test/page_test.rb DELETED
@@ -1,74 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PageTest < Test::Unit::TestCase
4
-
5
- def test_returns_correct_number_of_page_objects
6
- pages = Seiten::Page.all
7
- assert_equal 16, pages.count
8
- end
9
-
10
- def test_returns_page_title
11
- assert_equal "Home", Seiten::Page.find(1).title
12
- end
13
-
14
- def test_returns_nil_for_root_page_slug
15
- assert_equal nil, Seiten::Page.find(1).slug
16
- end
17
-
18
- def test_returns_page_slug
19
- assert_equal "about/our-team", Seiten::Page.find(7).slug
20
- end
21
-
22
- def test_returns_page_layout
23
- assert_equal "home", Seiten::Page.find(1).layout
24
- end
25
-
26
- def test_returns_parent_page
27
- page = Seiten::Page.find(3)
28
- assert_equal Seiten::Page.find(2).title, page.parent.title
29
- end
30
-
31
- def test_returns_children_pages
32
- page = Seiten::Page.find(2)
33
- assert_equal ["Logo Design", "Web Development", "Hire us"], page.children.map(&:title)
34
- end
35
-
36
- def test_returns_true_if_page_is_child_of_parent
37
- child = Seiten::Page.find(3)
38
- assert_equal true, Seiten::Page.find(2).parent_of?(child)
39
- end
40
-
41
- def test_returns_true_if_page_child_is_deeply_nested
42
- child = Seiten::Page.find_by_slug("about/our-team")
43
- assert_equal true, Seiten::Page.find_by_slug("about").parent_of?(child)
44
- end
45
-
46
- def test_returns_false_if_page_is_not_child_of_parent
47
- wrong_child = Seiten::Page.find(1)
48
- assert_equal false, Seiten::Page.find(2).parent_of?(wrong_child)
49
- end
50
-
51
- def test_returns_true_for_active_page
52
- active_page = Seiten::Page.find(1)
53
- assert_equal true, active_page.active?(active_page)
54
- end
55
-
56
- def test_returns_true_for_parent_of_active_page
57
- active_page = Seiten::Page.find(3)
58
- assert_equal true, Seiten::Page.find(2).active?(active_page)
59
- end
60
-
61
- def test_returns_false_for_not_active_page
62
- active_page = Seiten::Page.find(1)
63
- assert_equal false, active_page.active?(Seiten::Page.find(2))
64
- end
65
-
66
- def test_finds_page_by_slug
67
- page = Seiten::Page.find_by_slug("products/logo-design")
68
- assert_equal "Logo Design", page.title
69
- end
70
-
71
- def test_returns_nil_for_active_method_when_current_page_is_nil
72
- assert_equal nil, Seiten::Page.find(1).active?(nil)
73
- end
74
- end
data/test/seiten_test.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SeitenTest < ActiveSupport::TestCase
4
-
5
- def test_returns_page_storage_path
6
- assert_equal File.join(Rails.root, "app/pages/home.html.erb"), Seiten::PageStore.current.file_path(filename: "home.html.erb")
7
- assert_equal File.join(Rails.root, "app/pages/en/contact.html.erb"), Seiten::PageStore.current.file_path(filename: "contact.html.erb", locale: "en")
8
- end
9
- end