ecm_cms 0.0.2.pre → 0.0.3.pre

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.
@@ -62,8 +62,8 @@ class Ecm::Cms::NavigationItem < ActiveRecord::Base
62
62
  end
63
63
 
64
64
  def update_navigation_from_parent!
65
- self.update_navigation_from_parent
66
- self.save!
65
+ update_navigation_from_parent
66
+ save!
67
67
  end
68
68
 
69
69
  def update_children_navigations!
@@ -29,9 +29,7 @@ class Ecm::Cms::Page < ActiveRecord::Base
29
29
  # validations
30
30
  validates :title, :presence => true
31
31
 
32
- def home_page?
33
- p self.pathname
34
- p self.basename
32
+ def home_page?
35
33
  return self.pathname == '/' && self.basename == 'home'
36
34
  end
37
35
 
@@ -0,0 +1,30 @@
1
+ module Ecm
2
+ module Cms
3
+ module Importers
4
+ class Navigation
5
+ def initialize(yaml, option = {})
6
+ @navigations = nil
7
+ @yaml = YAML.load(yaml)
8
+ end
9
+
10
+ def build_navigations
11
+ navigations = []
12
+ @yaml.each do |navigation_data|
13
+ navigation = Ecm::Cms::Navigation.new(navigation_data)
14
+ navigations << navigation
15
+ end if @yaml.respond_to?(:each)
16
+ navigations
17
+ end
18
+
19
+ def navigations
20
+ @navigations ||= build_navigations
21
+ end
22
+
23
+ def yaml
24
+ @yaml
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,56 @@
1
+ module Ecm
2
+ module Cms
3
+ module Importers
4
+ class NavigationItem
5
+ def initialize(yaml, option = {})
6
+ @navigation_items = nil
7
+ @yaml = YAML.load(yaml)
8
+ end
9
+
10
+ def create_navigation_items
11
+ built_navigation_items = []
12
+ @yaml.each do |navigation_locale, navigation|
13
+ navigation.each do |navigation_name, navigation_items|
14
+ n = find_or_create_navigation(navigation_locale, navigation_name)
15
+ navigation_items.each do |navigation_item_attributes|
16
+ ni = create_navigation_item(navigation_item_attributes, n)
17
+ built_navigation_items << ni
18
+ end
19
+ end if navigation_locale.respond_to?(:each)
20
+ end if @yaml.respond_to?(:each)
21
+ built_navigation_items
22
+ end
23
+
24
+ def create_navigation_item(navigation_item_attributes, navigation)
25
+ subitems = navigation_item_attributes.delete('subitems')
26
+
27
+ ni = Ecm::Cms::NavigationItem.new(navigation_item_attributes)
28
+ ni.ecm_cms_navigation = navigation
29
+ ni.save!
30
+
31
+ subitems.each do |subitem_attributes|
32
+ subitem_attributes['parent'] = ni
33
+ create_navigation_item(subitem_attributes, navigation)
34
+ end if subitems.respond_to?(:each)
35
+
36
+ ni
37
+ end
38
+
39
+ def find_or_create_navigation(navigation_locale, navigation_name)
40
+ navigation = Ecm::Cms::Navigation.where(:locale => navigation_locale, :name => navigation_name).first
41
+ navigation = Ecm::Cms::Navigation.create!(:locale => navigation_locale, :name => navigation_name) if navigation.nil?
42
+ navigation
43
+ end
44
+
45
+ def navigation_items
46
+ @navigation_items ||= create_navigation_items
47
+ end
48
+
49
+ def yaml
50
+ @yaml
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,41 @@
1
+ module Ecm
2
+ module Cms
3
+ module Importers
4
+ class Page
5
+ def initialize(yaml, option = {})
6
+ @pages = nil
7
+ @yaml = YAML.load(yaml)
8
+ end
9
+
10
+ def build_pages
11
+ pages = []
12
+ @yaml.each do |page_data|
13
+ navigation_items = extract_navigation_items(page_data.delete('navigation_items'))
14
+ page = Ecm::Cms::Page.new(page_data)
15
+ page.ecm_cms_navigation_item_ids = navigation_items.map(&:id)
16
+ pages << page
17
+ end if @yaml.respond_to?(:each)
18
+ pages
19
+ end
20
+
21
+ def extract_navigation_items(navigation_item_data)
22
+ navigation_items = []
23
+ navigation_item_data.each do |nid|
24
+ navigation = Ecm::Cms::Navigation.where(:locale => nid['navigation_locale'], :name => nid['navigation_name']).first
25
+ navigation_items << navigation.ecm_cms_navigation_items.where(:name => nid['name']).first if navigation.respond_to?(:ecm_cms_navigation_items)
26
+ end
27
+ navigation_items
28
+ end
29
+
30
+ def pages
31
+ @pages ||= build_pages
32
+ end
33
+
34
+ def yaml
35
+ @yaml
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -1,5 +1,5 @@
1
1
  module Ecm
2
2
  module Cms
3
- VERSION = "0.0.2.pre"
3
+ VERSION = "0.0.3.pre"
4
4
  end
5
5
  end
@@ -1,4 +1,8 @@
1
1
  # encoding: utf-8
2
+ require 'ecm/cms/yaml_page_import'
3
+ require 'ecm/cms/yaml_navigation_import'
4
+ require 'ecm/cms/yaml_navigation_item_import'
5
+
2
6
  namespace :ecm do
3
7
  namespace :cms do
4
8
  namespace :db do
@@ -64,12 +68,12 @@ namespace :ecm do
64
68
  :de => [
65
69
  { :name => 'i18n' },
66
70
  { :name => 'legal' },
67
- { :name => 'main' }
71
+ { :name => 'main' }
68
72
  ],
69
73
  :en => [
70
74
  { :name => 'i18n' },
71
75
  { :name => 'legal' },
72
- { :name => 'main' }
76
+ { :name => 'main' }
73
77
  ]
74
78
  }.with_indifferent_access
75
79
 
@@ -136,17 +140,17 @@ namespace :ecm do
136
140
  pages = {
137
141
  :en => [
138
142
  { :title => 'Home', :body => '<h1>Home (en)</h1>', :pathname => '/', :basename => 'home', :locale => 'en', :format => 'html', :handler => 'erb' },
139
- { :title => 'Imprint', :body => '<h1>Imprint (en)</h1>', :pathname => '/', :basename => 'imprint', :locale => 'en', :format => 'html', :handler => 'erb' },
143
+ { :title => 'Imprint', :body => '<h1>Imprint (en)</h1>', :pathname => '/', :basename => 'imprint', :locale => 'en', :format => 'html', :handler => 'erb' },
140
144
  { :title => 'About us', :body => '<h1>About us (en)</h1>', :pathname => '/', :basename => 'about-us', :locale => 'en', :format => 'html', :handler => 'erb' },
141
145
  { :title => 'Approach', :body => '<h1>Approach (en)</h1>', :pathname => '/', :basename => 'approach', :locale => 'en', :format => 'html', :handler => 'erb' },
142
- { :title => 'Terms of Service', :body => '<h1>Terms of Service (en)</h1>', :pathname => '/', :basename => 'terms-of-service', :locale => 'en', :format => 'html', :handler => 'erb' }
146
+ { :title => 'Terms of Service', :body => '<h1>Terms of Service (en)</h1>', :pathname => '/', :basename => 'terms-of-service', :locale => 'en', :format => 'html', :handler => 'erb' }
143
147
  ],
144
148
  :de => [
145
149
  { :title => 'Home', :body => '<h1>Home (de)</h1>', :pathname => '/', :basename => 'home', :locale => 'de', :format => 'html', :handler => 'erb' },
146
- { :title => 'Impressum', :body => '<h1>Impressum (de)</h1>', :pathname => '/', :basename => 'impressum', :locale => 'de', :format => 'html', :handler => 'erb' },
150
+ { :title => 'Impressum', :body => '<h1>Impressum (de)</h1>', :pathname => '/', :basename => 'impressum', :locale => 'de', :format => 'html', :handler => 'erb' },
147
151
  { :title => 'Über uns', :body => '<h1>Über uns (de)</h1>', :pathname => '/', :basename => 'ueber-uns', :locale => 'de', :format => 'html', :handler => 'erb' },
148
152
  { :title => 'Anfahrt', :body => '<h1>Anfahrt (de)</h1>', :pathname => '/', :basename => 'anfahrt', :locale => 'de', :format => 'html', :handler => 'erb' },
149
- { :title => 'AGB', :body => '<h1>AGB (de)</h1>', :pathname => '/', :basename => 'agb', :locale => 'de', :format => 'html', :handler => 'erb' }
153
+ { :title => 'AGB', :body => '<h1>AGB (de)</h1>', :pathname => '/', :basename => 'agb', :locale => 'de', :format => 'html', :handler => 'erb' }
150
154
  ]
151
155
  }.with_indifferent_access
152
156
 
@@ -167,5 +171,44 @@ namespace :ecm do
167
171
 
168
172
  end
169
173
  end
174
+
175
+ namespace :import do
176
+ desc "Imports navigations"
177
+ task :navigations, [] => [:environment] do |t, args|
178
+ I18n.available_locales.map(&:to_s).each do |locale|
179
+ filename = File.join(Rails.root, "import", "navigations.#{locale}.yml")
180
+ if File.exists?(filename)
181
+ data = File.open( filename ).read
182
+ navigations = Ecm::Cms::Importers::Navigation.new(data).navigations
183
+ navigations.map(&:save!)
184
+ end
185
+ end
186
+ end
187
+
188
+ desc "Imports navigation items"
189
+ task :navigation_items, [] => [:environment] do |t, args|
190
+ I18n.available_locales.map(&:to_s).each do |locale|
191
+ filename = File.join(Rails.root, "import", "navigation_items.#{locale}.yml")
192
+ if File.exists?(filename)
193
+ data = File.open( filename ).read
194
+ navigation_items = Ecm::Cms::Importers::NavigationItem.new(data).navigation_items
195
+ navigation_items.map(&:save!)
196
+ end
197
+ end
198
+ end
199
+
200
+ desc "Imports pages"
201
+ task :pages, [] => [:environment] do |t, args|
202
+ I18n.available_locales.map(&:to_s).each do |locale|
203
+ filename = File.join(Rails.root, "import", "pages.#{locale}.yml")
204
+ if File.exists?(filename)
205
+ data = File.open( filename ).read
206
+ pages = Ecm::Cms::Importers::Page.new(data).pages
207
+ pages.map(&:save!)
208
+ end
209
+ end
210
+ end
211
+ end
170
212
  end
171
213
  end
214
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecm_cms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 961915980
4
+ hash: 961915976
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
9
+ - 3
10
10
  - pre
11
- version: 0.0.2.pre
11
+ version: 0.0.3.pre
12
12
  platform: ruby
13
13
  authors:
14
14
  - Roberto Vasquez Angel
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-11-15 00:00:00 Z
19
+ date: 2012-11-16 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rails
@@ -419,6 +419,9 @@ files:
419
419
  - lib/ecm/cms/engine.rb
420
420
  - lib/ecm/cms/version.rb
421
421
  - lib/ecm/cms/routing.rb
422
+ - lib/ecm/cms/importers/navigation_item.rb
423
+ - lib/ecm/cms/importers/navigation.rb
424
+ - lib/ecm/cms/importers/page.rb
422
425
  - lib/ecm/cms/configuration.rb
423
426
  - MIT-LICENSE
424
427
  - Rakefile