optimacms 0.1.32 → 0.1.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/optimacms/admin/templates_controller.rb +2 -3
- data/app/helpers/optimacms/application_helper.rb +29 -27
- data/app/models/optimacms/template.rb +48 -11
- data/app/models/optimacms/template_type.rb +6 -0
- data/app/views/optimacms/admin/templates/new.html.haml +3 -2
- data/lib/optimacms/version.rb +1 -1
- data/test/dummy/app/views/temp/_h1.html +1 -0
- data/test/dummy/app/views/temp/_part1.html.haml +1 -0
- data/test/dummy/app/views/temp/p1.html.haml +6 -0
- data/test/dummy/app/views/temp/sitemap.xml.builder +1 -0
- data/test/dummy/log/development.log +3531 -0
- data/test/dummy/tmp/pids/server.pid +1 -1
- metadata +10 -8
- data/test/dummy/app/views/temp/1.html.erb +0 -1
- data/test/dummy/app/views/temp/h1.html +0 -1
- data/test/dummy/app/views/temp/t5.html +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af38a4fa9a81bdada06d16f387634f6909d3fe0e
|
4
|
+
data.tar.gz: c89c6bbb8a8437d4a4462078f9025acf6c57a48b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9453f80617abf58a68fb85d1ef11dc62d10db2345c45e2687460b4844b9f292fe6b0c3b8a50773b6d285616e0acaa15bcd2c80d798c6be615254518e2bf5ccff
|
7
|
+
data.tar.gz: 70f282bca6e3df8361a0532c9d4e8601ba8f1a09ebd9445dadaa45acd58f952f9eb7427b0a095d76f290f7e0d45a6365a16cfe0e1602f3ab59edf547431c2817
|
@@ -71,7 +71,7 @@ module Optimacms
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def new
|
74
|
-
@item = model.new({:tpl_format=>Optimacms::Template::
|
74
|
+
@item = model.new({:tpl_format=>Optimacms::Template::EXTENSION_DEFAULT, :type_id=>TemplateType::TYPE_PAGE})
|
75
75
|
item_init_parent
|
76
76
|
@item.set_basedirpath_from_parent
|
77
77
|
|
@@ -80,7 +80,6 @@ module Optimacms
|
|
80
80
|
|
81
81
|
|
82
82
|
def create
|
83
|
-
#item_params[:type_id] = TemplateType::TYPE_PAGE
|
84
83
|
@item = model.new(item_params)
|
85
84
|
@res = @item.save
|
86
85
|
|
@@ -131,7 +130,7 @@ module Optimacms
|
|
131
130
|
|
132
131
|
|
133
132
|
def newattach
|
134
|
-
@item = model.new({:tpl_format=>Optimacms::Template::
|
133
|
+
@item = model.new({:tpl_format=>Optimacms::Template::EXTENSION_DEFAULT})
|
135
134
|
item_init_parent
|
136
135
|
@item.set_basedirpath_from_parent
|
137
136
|
|
@@ -30,44 +30,46 @@ module Optimacms
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def block(name)
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
x = Dir.pwd
|
34
|
+
#y = File.expand_path File.dirname(__FILE__)
|
35
|
+
d = File.dirname(@optimacms_tpl)
|
36
36
|
|
37
|
+
# extensions
|
38
|
+
extensions = ['', '.html.haml', '.html.erb', '.html']
|
37
39
|
|
38
|
-
# try1 - in the current folder
|
39
|
-
f = File.join(Dir.pwd, 'app', 'views', d, name+'.html')
|
40
|
-
return render file: f if File.exists? f
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
names << ["", name+".html"]
|
41
|
+
# try. HTML file in the current folder
|
42
|
+
f = File.join(Dir.pwd, 'app', 'views', d, name+'.html')
|
43
|
+
return render file: f if File.exists? f
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
#
|
46
|
+
names = []
|
49
47
|
|
50
|
-
|
51
|
-
|
48
|
+
#
|
49
|
+
parts = name.split /\//
|
52
50
|
|
53
|
-
|
54
|
-
|
51
|
+
parts[-1] = '_'+parts[-1]
|
52
|
+
name2 = parts.join('/')
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
(return render file: f) if File.exists? f
|
54
|
+
#
|
55
|
+
names << [d, name]
|
56
|
+
names << ["", name]
|
60
57
|
|
61
|
-
|
62
|
-
|
58
|
+
names << [d, name2]
|
59
|
+
names << ["", name2]
|
63
60
|
|
64
|
-
f = File.join(Dir.pwd, 'app', 'views', p[0], p[1]+".erb")
|
65
|
-
(return render file: f) if File.exists? f
|
66
|
-
end
|
67
61
|
|
68
|
-
|
69
|
-
|
62
|
+
# try 2
|
63
|
+
names.each do |p|
|
64
|
+
extensions.each do |ext|
|
65
|
+
f = File.join(Dir.pwd, 'app', 'views', p[0], p[1]+ext)
|
66
|
+
(return render file: f) if File.exists? f
|
70
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# default render
|
71
|
+
return render name
|
72
|
+
end
|
71
73
|
|
72
74
|
|
73
75
|
def site_page_path(h)
|
@@ -2,11 +2,10 @@ module Optimacms
|
|
2
2
|
class Template < ActiveRecord::Base
|
3
3
|
self.table_name = 'cms_templates'
|
4
4
|
|
5
|
-
|
6
|
-
EXTENSIONS = {'html'=>'html', 'erb'=>'html.erb', 'haml'=>'html.haml'}
|
5
|
+
EXTENSION_DEFAULT = 'html'
|
6
|
+
EXTENSIONS = {'blank'=>'', 'html'=>'html', 'erb'=>'html.erb', 'haml'=>'html.haml'}
|
7
7
|
|
8
8
|
|
9
|
-
#belongs_to :folder, :foreign_key => 'parent_id', :class_name => 'Template'
|
10
9
|
belongs_to :type, :foreign_key => 'type_id', :class_name => 'TemplateType'
|
11
10
|
|
12
11
|
before_validation :_before_validation
|
@@ -47,6 +46,16 @@ module Optimacms
|
|
47
46
|
end
|
48
47
|
|
49
48
|
|
49
|
+
### settings
|
50
|
+
|
51
|
+
def self.base_dir
|
52
|
+
Rails.root.to_s + '/app/views/'
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
50
59
|
### properties
|
51
60
|
|
52
61
|
def parent_title
|
@@ -55,13 +64,26 @@ module Optimacms
|
|
55
64
|
|
56
65
|
|
57
66
|
def has_code?
|
58
|
-
['haml', 'erb'].include?(self.tpl_format)
|
67
|
+
['haml', 'erb', 'blank'].include?(self.tpl_format)
|
59
68
|
end
|
60
69
|
|
61
70
|
def is_folder?
|
62
71
|
self.is_folder
|
63
72
|
end
|
64
73
|
|
74
|
+
def is_layout?
|
75
|
+
return self.type_id==TemplateType::TYPE_LAYOUT
|
76
|
+
end
|
77
|
+
|
78
|
+
def is_type_page?
|
79
|
+
return self.type_id==TemplateType::TYPE_PAGE
|
80
|
+
end
|
81
|
+
|
82
|
+
def is_type_partial?
|
83
|
+
return self.type_id==TemplateType::TYPE_PARTIAL
|
84
|
+
end
|
85
|
+
|
86
|
+
|
65
87
|
|
66
88
|
##### search
|
67
89
|
|
@@ -93,7 +115,7 @@ module Optimacms
|
|
93
115
|
|
94
116
|
def path(lang='')
|
95
117
|
return nil if self.basename.nil?
|
96
|
-
self.basedirpath+
|
118
|
+
self.basedirpath + filename_base + Template.filename_lang_postfix(lang) + Template.filename_ext_with_dot(self.tpl_format)
|
97
119
|
end
|
98
120
|
|
99
121
|
def fullpath(lang='')
|
@@ -158,23 +180,36 @@ module Optimacms
|
|
158
180
|
end
|
159
181
|
|
160
182
|
|
161
|
-
###
|
183
|
+
### helpers for path
|
162
184
|
|
163
|
-
|
164
|
-
|
185
|
+
# base filename depending on type
|
186
|
+
# for page = name
|
187
|
+
# for partial = _name
|
188
|
+
def filename_base
|
189
|
+
return '_'+self.basename if self.is_type_partial?
|
190
|
+
|
191
|
+
self.basename
|
165
192
|
end
|
166
193
|
|
167
|
-
|
194
|
+
|
195
|
+
def self.filename_lang_postfix(lang)
|
168
196
|
return '' if lang==''
|
169
197
|
return '.'+lang
|
170
198
|
end
|
171
199
|
|
172
|
-
def self.
|
200
|
+
def self.filename_ext(format)
|
173
201
|
EXTENSIONS[format]
|
174
202
|
end
|
175
203
|
|
204
|
+
def self.filename_ext_with_dot(format)
|
205
|
+
ext = filename_ext(format)
|
206
|
+
ext = '.'+ext unless ext.blank?
|
207
|
+
ext
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
### operations with path
|
176
212
|
|
177
|
-
###
|
178
213
|
def set_basepath
|
179
214
|
if self.parent.nil?
|
180
215
|
self.basepath = self.basename
|
@@ -219,6 +254,8 @@ module Optimacms
|
|
219
254
|
end
|
220
255
|
end
|
221
256
|
|
257
|
+
|
258
|
+
|
222
259
|
#### callbacks
|
223
260
|
|
224
261
|
def _before_validation
|
@@ -19,14 +19,15 @@
|
|
19
19
|
= hidden_field_tag :modal, @modal
|
20
20
|
|
21
21
|
-#= f.input :parent_id, as: :hidden
|
22
|
-
|
23
|
-
|
22
|
+
-#= f.input :type_id, as: :hidden
|
23
|
+
-#= f.input :type, disabled: true, label: 'Type'
|
24
24
|
|
25
25
|
= f.input :title, label: "Title"
|
26
26
|
|
27
27
|
= f.input :basedirpath, readonly: false, label: 'Folder', hint: "ex: news/"
|
28
28
|
= f.input :basename, label: "Name", :hint=>'ex: index, show'
|
29
29
|
|
30
|
+
= f.input :type_id, label: "Type", :collection=>Optimacms::TemplateType.all
|
30
31
|
= f.input :tpl_format, label: "Format", :collection=>Optimacms::Template::EXTENSIONS.keys
|
31
32
|
|
32
33
|
= f.input :is_translated, label: "Translate?"
|
data/lib/optimacms/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<p>partial HTML</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
text in partial - part1.html.haml
|
@@ -0,0 +1 @@
|
|
1
|
+
xml.build
|