seiten 0.0.7 → 1.0.1

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 (105) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +1 -0
  3. data/app/controllers/seiten/pages_controller.rb +2 -19
  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 +7 -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 +71 -49
  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 -13
  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 +1716 -4558
  71. data/test/dummy/log/test.log +43833 -13898
  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 +147 -93
  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 -160
  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 -31
  102. data/test/integration/redirect_test.rb +0 -15
  103. data/test/page_store_test.rb +0 -28
  104. data/test/page_test.rb +0 -98
  105. data/test/seiten_test.rb +0 -11
@@ -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,160 +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
- @storages = []
17
-
18
- class << self
19
-
20
- def storages
21
- @storages
22
- end
23
-
24
- def storages=(storages)
25
- @storages = storages
26
- end
27
-
28
- def current
29
- Seiten.config[:current_page_store]
30
- end
31
-
32
- def set_current_page_store(options={})
33
- Seiten.config[:current_page_store] = find_by(options) if options
34
- end
35
-
36
- def find_by(options={})
37
- tmp_storages = storages
38
- options.each do |option|
39
- tmp_storages = tmp_storages.select { |storage| storage.send(option[0]) == option[1] }
40
- end
41
- tmp_storages.first
42
- end
43
-
44
- def initialize_page_stores
45
- # Check if config/navigation exists?
46
- # If true: Initialize localized navigation page stores with locale language and directory
47
- # If false: Initialize the default storage file
48
- if File.directory?(File.join(Rails.root, Seiten.config[:default_storage_file]))
49
- Dir[File.join(Rails.root, Seiten.config[:default_storage_file], "*.yml")].each do |file|
50
- locale = File.basename(file, '.yml')
51
- Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: locale, storage_directory: File.join(Rails.root, "app", "pages", locale))
52
- end
53
- else
54
- Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: I18n.default_locale)
55
- end
56
- set_current_page_store(storage_language: I18n.default_locale)
57
- end
58
-
59
- end
60
-
61
- def load_storage_file
62
- if File.exists?(File.join(Rails.root, Seiten.config[:default_storage_file], "#{storage_language}.yml"))
63
- File.join(Rails.root, Seiten.config[:default_storage_file], "#{storage_language}.yml")
64
- else
65
- File.join(Rails.root, "#{Seiten.config[:default_storage_file]}.yml")
66
- end
67
- end
68
-
69
- def file_path(options={})
70
- File.join(storage_directory, options[:filename])
71
- end
72
-
73
- def build_link(page, prefix_url="")
74
-
75
- # if url is nil parameterize title otherwise just use url
76
- slug = page["url"].nil? ? page["title"].parameterize : page["url"]
77
-
78
- # prepend prefix_url if slug is not root or external url
79
- unless slug[0] == "/" || !!(slug.match(/^https?:\/\/.+/)) || !prefix_url.present?
80
- slug = "#{prefix_url}/#{slug}"
81
- end
82
-
83
- # return nil if page slug is /
84
- if slug == "/" || page["root"] == true
85
- slug = nil
86
- end
87
-
88
- # remove leading slash if present
89
- if slug
90
- slug = slug[1..-1] if slug[0] == "/"
91
- end
92
-
93
- slug
94
- end
95
-
96
- def load_pages(options={})
97
-
98
- pages = options[:pages]
99
- parent_id = options[:parent_id] # || nil
100
- layout = options[:layout]
101
- prefix_url = options[:prefix_url] || ""
102
-
103
- # Setting default values
104
- if storage_type == :yaml
105
- pages ||= YAML.load_file(storage_file)
106
- end
107
-
108
- @id ||= 1
109
- @navigation ||= []
110
-
111
- pages.each_index do |i|
112
-
113
- # Load page and set parent_id and generated page id
114
- page = pages[i]
115
- page["id"] = @id
116
- page["parent_id"] = parent_id
117
- page["layout"] ||= layout
118
-
119
- # Increment generated id
120
- @id += 1
121
-
122
- # Build link
123
- page["slug"] = build_link(page, prefix_url)
124
-
125
- # Set layout
126
- if page["layout"]
127
- if page["layout"].is_a?(String)
128
- inherited_layout = page["layout"]
129
- elsif page["layout"].is_a?(Hash)
130
- if page["layout"]["inherit"]
131
- inherited_layout = page["layout"]
132
- else
133
- inherited_layout = nil
134
- end
135
- page["layout"] = page["layout"]["name"]
136
- end
137
- end
138
-
139
- # Set redirect
140
- if page["redirect"]
141
- if page["redirect"].is_a?(TrueClass)
142
- page["redirect"] = build_link(page["nodes"].first, page["slug"])
143
- else
144
- page["redirect"] = page["redirect"][1..-1] if page["redirect"][0] == "/"
145
- end
146
- end
147
-
148
- # Load children
149
- if page["nodes"]
150
- load_pages(pages: page["nodes"], parent_id: page["id"], prefix_url: page["slug"], layout: inherited_layout, external: page["external"])
151
- end
152
-
153
- page_params = page.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
154
- @navigation << Page.new(page_params)
155
- end
156
-
157
- @navigation
158
- end
159
- end
160
- 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
- 47202
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nTest < ActionDispatch::IntegrationTest
4
-
5
- def test_returns_products_page_in_en_directory
6
- Seiten::PageStore.set_current_page_store(storage_language: :en)
7
- visit "/products"
8
- assert has_content?("This is the products page")
9
- end
10
-
11
- def test_returns_products_page_in_de_directory
12
- Seiten::PageStore.set_current_page_store(storage_language: :de)
13
- visit "/produkte"
14
- assert has_content?("Das ist die Produkte Seite")
15
- end
16
-
17
- def test_loads_de_navigation
18
- I18n.locale = :de
19
- assert_equal File.join(Rails.root, "config", "navigation", "de.yml"), Seiten::PageStore.new.storage_file
20
- end
21
-
22
- def test_loads_en_navigation
23
- I18n.locale = :en
24
- assert_equal File.join(Rails.root, "config", "navigation", "en.yml"), Seiten::PageStore.new.storage_file
25
- end
26
-
27
- # def test_loads_navigation_without_locale_if_not_found
28
- # I18n.locale = :fr
29
- # assert_equal File.join(Rails.root, "config", "navigation.yml"), Seiten::PageStore.new.storage_file
30
- # end
31
- 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
@@ -1,28 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PageStoreTest < Test::Unit::TestCase
4
-
5
- def test_returns_storages
6
- assert_equal 2, Seiten::PageStore.storages.count
7
- end
8
-
9
- # TODO: Split into two tests
10
- def test_sets_and_returns_current_page_store
11
- page_store = Seiten::PageStore.find_by(storage_language: :de)
12
- Seiten::PageStore.set_current_page_store(storage_language: :de)
13
- assert_equal page_store, Seiten::PageStore.current
14
- Seiten::PageStore.set_current_page_store(storage_language: :en)
15
- end
16
-
17
- def test_find_by_with_one_argument
18
- page_store = Seiten::PageStore.find_by(storage_language: :de)
19
- assert_equal File.join(Rails.root, "config", "navigation", "de.yml"), page_store.storage_file
20
- end
21
-
22
- def test_find_by_with_multiple_arguments
23
- page_store = Seiten::PageStore.find_by(storage_language: :de, storage_file: File.join(Rails.root, "config", "navigation", "de.yml"))
24
- assert_equal File.join(Rails.root, "config", "navigation", "de.yml"), page_store.storage_file
25
- end
26
-
27
- # TODO: Write more tests
28
- end
data/test/page_test.rb DELETED
@@ -1,98 +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_external?
27
- assert_equal true, Seiten::Page.find(13).external?
28
- assert_equal false, Seiten::Page.find(4).external?
29
- end
30
-
31
- def test_returns_parent_page
32
- page = Seiten::Page.find(3)
33
- assert_equal Seiten::Page.find(2).title, page.parent.title
34
- end
35
-
36
- def test_returns_true_if_page_has_a_parent
37
- page = Seiten::Page.find(3)
38
- assert_equal true, page.parent?
39
- end
40
-
41
- def test_returns_false_if_page_has_no_parent
42
- page = Seiten::Page.find(1)
43
- assert_equal false, page.parent?
44
- end
45
-
46
- def test_returns_branch_root_page
47
- page = Seiten::Page.find(13)
48
- assert_equal Seiten::Page.find(6), page.branch_root
49
- page = Seiten::Page.find(3)
50
- assert_equal Seiten::Page.find(2), page.branch_root
51
- page = Seiten::Page.find(1)
52
- assert_equal Seiten::Page.find(1), page.branch_root
53
- end
54
-
55
- def test_returns_children_pages
56
- page = Seiten::Page.find(2)
57
- assert_equal ["Logo Design", "Web Development", "Hire us"], page.children.map(&:title)
58
- end
59
-
60
- def test_returns_true_if_page_is_child_of_parent
61
- child = Seiten::Page.find(3)
62
- assert_equal true, Seiten::Page.find(2).parent_of?(child)
63
- end
64
-
65
- def test_returns_true_if_page_child_is_deeply_nested
66
- child = Seiten::Page.find_by_slug("about/our-team")
67
- assert_equal true, Seiten::Page.find_by_slug("about").parent_of?(child)
68
- end
69
-
70
- def test_returns_false_if_page_is_not_child_of_parent
71
- wrong_child = Seiten::Page.find(1)
72
- assert_equal false, Seiten::Page.find(2).parent_of?(wrong_child)
73
- end
74
-
75
- def test_returns_true_for_active_page
76
- active_page = Seiten::Page.find(1)
77
- assert_equal true, active_page.active?(active_page)
78
- end
79
-
80
- def test_returns_true_for_parent_of_active_page
81
- active_page = Seiten::Page.find(3)
82
- assert_equal true, Seiten::Page.find(2).active?(active_page)
83
- end
84
-
85
- def test_returns_false_for_not_active_page
86
- active_page = Seiten::Page.find(1)
87
- assert_equal false, active_page.active?(Seiten::Page.find(2))
88
- end
89
-
90
- def test_finds_page_by_slug
91
- page = Seiten::Page.find_by_slug("products/logo-design")
92
- assert_equal "Logo Design", page.title
93
- end
94
-
95
- def test_returns_nil_for_active_method_when_current_page_is_nil
96
- assert_equal nil, Seiten::Page.find(1).active?(nil)
97
- end
98
- end
data/test/seiten_test.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SeitenTest < ActiveSupport::TestCase
4
-
5
- def test_returns_page_storage_path
6
- Seiten::PageStore.set_current_page_store(storage_language: :en)
7
- assert_equal File.join(Rails.root, "app/pages/en/home.html.erb"), Seiten::PageStore.current.file_path(filename: "home.html.erb")
8
- Seiten::PageStore.set_current_page_store(storage_language: :de)
9
- assert_equal File.join(Rails.root, "app/pages/de/kontakt.html.erb"), Seiten::PageStore.current.file_path(filename: "kontakt.html.erb")
10
- end
11
- end