seiten 0.0.6 → 0.0.7

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: c07bb134e2faeb0ba5dd11af57a067fef28ceeb2
4
- data.tar.gz: 94f0e43ea9839d4bf1598ef7c63e0c8bb39a590a
3
+ metadata.gz: aac1c7e2cff18662cca1155e49a8f43b13df73f7
4
+ data.tar.gz: c6e449e0518a93591b26832d3c3dfa94aacef1c9
5
5
  SHA512:
6
- metadata.gz: 341550a0f7cdd4b7e6a9a01b685c70796b6ec8007b13256482c5a028c95e0ada6d42e164994926c5cf4307d819d085944c10874e3e91ca2c9de95e10ef8defb6
7
- data.tar.gz: 6657f6f1f45308fcab547c3dff423355c8ac887a154178a545230647829a824ace2361d921c3d94e6739288fe3a99a52a4b9f36d8ad586ebddd9f498b913bcbf
6
+ metadata.gz: 117b93f29193643c09bdaff2e2b663c9e636907c6e18ec6f300302fbe51bfca58ac69d0f14ca05a73b0bfdf759368e14973da4a24426367887e1b0b887bd2903
7
+ data.tar.gz: dee87d889d81b4d9698dd14c1e2453f1a1a4c5dcda62798d9f8b7c3841d8e4876ab5ee8c075b222058f4ace35ef0d31b8a25148c5da4fb1154dcd0bc33c1b20f
@@ -13,11 +13,7 @@ module Seiten
13
13
  filename = Seiten.config[:root_page_filename]
14
14
  end
15
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
16
+ file = Seiten::PageStore.current.file_path(filename: filename)
21
17
 
22
18
  if current_page.layout
23
19
  render file: file, layout: current_page.layout
data/lib/seiten/page.rb CHANGED
@@ -10,6 +10,7 @@ module Seiten
10
10
  @parent_id = options[:parent_id]
11
11
  @title = options[:title]
12
12
  @slug = options[:slug]
13
+ @external = options[:external]
13
14
  @redirect = options[:redirect]
14
15
  @layout = options[:layout]
15
16
  end
@@ -50,11 +51,30 @@ module Seiten
50
51
 
51
52
  end
52
53
 
54
+ # returns true if slug starts with http:// or https://
55
+ def external?
56
+ !!(slug.match(/^https?:\/\/.+/))
57
+ end
58
+
53
59
  # get parent of page
54
60
  def parent
55
61
  Page.find(parent_id)
56
62
  end
57
63
 
64
+ def parent?
65
+ parent.present?
66
+ end
67
+
68
+ # TODO: Find a better name for this
69
+ # get root page of current page branch
70
+ def branch_root
71
+ if self.parent?
72
+ self.parent.branch_root
73
+ else
74
+ self
75
+ end
76
+ end
77
+
58
78
  # get children of page
59
79
  def children
60
80
  Page.all.select { |page| page.parent_id == id }
@@ -13,15 +13,6 @@ module Seiten
13
13
  @pages = load_pages
14
14
  end
15
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
16
  @storages = []
26
17
 
27
18
  class << self
@@ -30,20 +21,39 @@ module Seiten
30
21
  @storages
31
22
  end
32
23
 
33
- def find_by_locale(locale=I18n.locale)
34
- storages.select { |storage| storage.storage_language == locale }.first
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
35
42
  end
36
- alias_method :current, :find_by_locale
37
43
 
38
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
39
48
  if File.directory?(File.join(Rails.root, Seiten.config[:default_storage_file]))
40
49
  Dir[File.join(Rails.root, Seiten.config[:default_storage_file], "*.yml")].each do |file|
41
50
  locale = File.basename(file, '.yml')
42
- Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: locale)
51
+ Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: locale, storage_directory: File.join(Rails.root, "app", "pages", locale))
43
52
  end
44
53
  else
45
54
  Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: I18n.default_locale)
46
55
  end
56
+ set_current_page_store(storage_language: I18n.default_locale)
47
57
  end
48
58
 
49
59
  end
@@ -57,7 +67,7 @@ module Seiten
57
67
  end
58
68
 
59
69
  def file_path(options={})
60
- File.join(storage_directory, options[:locale].to_s, options[:filename])
70
+ File.join(storage_directory, options[:filename])
61
71
  end
62
72
 
63
73
  def build_link(page, prefix_url="")
@@ -137,7 +147,7 @@ module Seiten
137
147
 
138
148
  # Load children
139
149
  if page["nodes"]
140
- load_pages(pages: page["nodes"], parent_id: page["id"], prefix_url: page["slug"], layout: inherited_layout)
150
+ load_pages(pages: page["nodes"], parent_id: page["id"], prefix_url: page["slug"], layout: inherited_layout, external: page["external"])
141
151
  end
142
152
 
143
153
  page_params = page.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
@@ -6,7 +6,7 @@ class ActionDispatch::Routing::Mapper
6
6
  if page.redirect
7
7
  get page.slug, to: redirect { |p, req|
8
8
  Rails.application.routes.url_helpers.seiten_page_path(page: page.redirect, locale: p[:locale])
9
- }
9
+ }, as: nil
10
10
  end
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Seiten
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/seiten.rb CHANGED
@@ -9,6 +9,7 @@ module Seiten
9
9
  default_storage_type: :yaml,
10
10
  default_storage_file: File.join('config', 'navigation'),
11
11
  default_storage_directory: File.join('app', 'pages'),
12
+ current_page_store: nil,
12
13
  root_page_filename: "home"
13
14
  }
14
15