cms-fortress 1.0.12 → 1.1.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.
- data/VERSION +1 -1
- data/cms-fortress.gemspec +2 -1
- data/lib/cms-fortress.rb +2 -0
- data/lib/comfortable_mexican_sofa/fixture/page.rb +123 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/cms-fortress.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "cms-fortress"
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Melvin Sembrano"]
|
@@ -96,6 +96,7 @@ Gem::Specification.new do |s|
|
|
96
96
|
"lib/cms/fortress/rails/engine.rb",
|
97
97
|
"lib/cms/fortress/routes/admin.rb",
|
98
98
|
"lib/cms/fortress/routing.rb",
|
99
|
+
"lib/comfortable_mexican_sofa/fixture/page.rb",
|
99
100
|
"lib/generators/cms/fortress/USAGE",
|
100
101
|
"lib/generators/cms/fortress/fortress_generator.rb",
|
101
102
|
"lib/generators/cms/fortress/templates/README",
|
data/lib/cms-fortress.rb
CHANGED
@@ -2,6 +2,8 @@ require 'comfortable_mexican_sofa'
|
|
2
2
|
require 'devise'
|
3
3
|
require 'cancan'
|
4
4
|
|
5
|
+
require_relative 'comfortable_mexican_sofa/fixture/page'
|
6
|
+
|
5
7
|
require_relative 'cms/fortress/application_controller_methods'
|
6
8
|
require_relative 'cms/fortress/page_methods'
|
7
9
|
require_relative 'cms/fortress/rails/engine'
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module ComfortableMexicanSofa::Fixture::Page
|
2
|
+
class Importer < ComfortableMexicanSofa::Fixture::Importer
|
3
|
+
|
4
|
+
attr_accessor :target_pages
|
5
|
+
|
6
|
+
def import!(path = self.path, parent = nil)
|
7
|
+
Dir["#{path}*/"].each do |path|
|
8
|
+
slug = path.split('/').last
|
9
|
+
|
10
|
+
page = if parent
|
11
|
+
parent.children.where(:slug => slug).first || site.pages.new(:parent => parent, :slug => slug)
|
12
|
+
else
|
13
|
+
site.pages.root || site.pages.new(:slug => slug)
|
14
|
+
end
|
15
|
+
|
16
|
+
# setting attributes
|
17
|
+
categories = []
|
18
|
+
if File.exists?(attrs_path = File.join(path, 'attributes.yml'))
|
19
|
+
if fresh_fixture?(page, attrs_path)
|
20
|
+
attrs = get_attributes(attrs_path)
|
21
|
+
|
22
|
+
page.label = attrs['label']
|
23
|
+
page.layout = site.layouts.where(:identifier => attrs['layout']).first || parent.try(:layout)
|
24
|
+
page.is_published = attrs['is_published'].nil?? true : attrs['is_published']
|
25
|
+
page.position = attrs['position'] if attrs['position']
|
26
|
+
|
27
|
+
categories = attrs['categories']
|
28
|
+
|
29
|
+
page.page_workflow = Cms::PageWorkflow.new(attrs['page_workflow']) if page.page_workflow.nil?
|
30
|
+
|
31
|
+
if attrs['target_page']
|
32
|
+
self.target_pages ||= {}
|
33
|
+
self.target_pages[page] = attrs['target_page']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# setting content
|
39
|
+
blocks_to_clear = page.blocks.collect(&:identifier)
|
40
|
+
blocks_attributes = [ ]
|
41
|
+
Dir.glob("#{path}/*.html").each do |block_path|
|
42
|
+
identifier = block_path.split('/').last.gsub(/\.html\z/, '')
|
43
|
+
blocks_to_clear.delete(identifier)
|
44
|
+
if fresh_fixture?(page, block_path)
|
45
|
+
blocks_attributes << {
|
46
|
+
:identifier => identifier,
|
47
|
+
:content => read_as_haml(block_path)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# deleting removed blocks
|
53
|
+
page.blocks.where(:identifier => blocks_to_clear).destroy_all
|
54
|
+
|
55
|
+
page.blocks_attributes = blocks_attributes if blocks_attributes.present?
|
56
|
+
|
57
|
+
# saving
|
58
|
+
if page.changed? || page.blocks_attributes_changed || self.force_import
|
59
|
+
if page.save
|
60
|
+
save_categorizations!(page, categories)
|
61
|
+
ComfortableMexicanSofa.logger.warn("[FIXTURES] Imported Page \t #{page.full_path}")
|
62
|
+
else
|
63
|
+
ComfortableMexicanSofa.logger.warn("[FIXTURES] Failed to import Page \n#{page.errors.inspect}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
self.fixture_ids << page.id
|
68
|
+
|
69
|
+
# importing child pages
|
70
|
+
import!(path, page)
|
71
|
+
end
|
72
|
+
|
73
|
+
# linking up target pages
|
74
|
+
if self.target_pages.present?
|
75
|
+
self.target_pages.each do |page, target|
|
76
|
+
if target_page = self.site.pages.where(:full_path => target).first
|
77
|
+
page.target_page = target_page
|
78
|
+
page.save
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# cleaning up
|
84
|
+
unless parent
|
85
|
+
self.site.pages.where('id NOT IN (?)', self.fixture_ids).each{ |s| s.destroy }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class Exporter < ComfortableMexicanSofa::Fixture::Exporter
|
91
|
+
def export!
|
92
|
+
|
93
|
+
prepare_folder!(self.path)
|
94
|
+
|
95
|
+
self.site.pages.each do |page|
|
96
|
+
page.slug = 'index' if page.slug.blank?
|
97
|
+
page_path = File.join(path, page.ancestors.reverse.collect{|p| p.slug.blank?? 'index' : p.slug}, page.slug)
|
98
|
+
FileUtils.mkdir_p(page_path)
|
99
|
+
|
100
|
+
open(File.join(page_path, 'attributes.yml'), 'w') do |f|
|
101
|
+
f.write({
|
102
|
+
'label' => page.label,
|
103
|
+
'layout' => page.layout.try(:identifier),
|
104
|
+
'parent' => page.parent && (page.parent.slug.present?? page.parent.slug : 'index'),
|
105
|
+
'target_page' => page.target_page.try(:full_path),
|
106
|
+
'categories' => page.categories.map{|c| c.label},
|
107
|
+
'is_published' => page.is_published,
|
108
|
+
'position' => page.position,
|
109
|
+
'page_workflow' => {status_id: page.page_workflow.status_id, published_date: page.page_workflow.published_date }
|
110
|
+
}.to_yaml)
|
111
|
+
end
|
112
|
+
page.blocks_attributes.each do |block|
|
113
|
+
open(File.join(page_path, "#{block[:identifier]}.html"), 'w') do |f|
|
114
|
+
f.write(block[:content])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
ComfortableMexicanSofa.logger.warn("[FIXTURES] Exported Page \t #{page.full_path}")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cms-fortress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- lib/cms/fortress/rails/engine.rb
|
243
243
|
- lib/cms/fortress/routes/admin.rb
|
244
244
|
- lib/cms/fortress/routing.rb
|
245
|
+
- lib/comfortable_mexican_sofa/fixture/page.rb
|
245
246
|
- lib/generators/cms/fortress/USAGE
|
246
247
|
- lib/generators/cms/fortress/fortress_generator.rb
|
247
248
|
- lib/generators/cms/fortress/templates/README
|
@@ -273,7 +274,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
273
274
|
version: '0'
|
274
275
|
segments:
|
275
276
|
- 0
|
276
|
-
hash:
|
277
|
+
hash: 3309026815395472566
|
277
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
278
279
|
none: false
|
279
280
|
requirements:
|