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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc806b4a41b68c9af3375d1ccd5d69a5e5b44c73
4
- data.tar.gz: ddeae6d99a20118381e1e1108b19222b2e0aff79
3
+ metadata.gz: af38a4fa9a81bdada06d16f387634f6909d3fe0e
4
+ data.tar.gz: c89c6bbb8a8437d4a4462078f9025acf6c57a48b
5
5
  SHA512:
6
- metadata.gz: 15eeca877804476cae12e48b78f4d31a155d833acffceb0ebe5c87e5e03ccb16540063bb2ffcfe92ac627b13944928bd0dfc3d01382ee4ac4b8a9ddc40a902c3
7
- data.tar.gz: a37d0ee3e40e5b14381284e3a8a2eff9469bbf3bf79bc80cbb7737e3d86f5a0cfc88d3423b60c3ad3a340a9f8ee85b09f50e81f8fdd7683fc59e5748452b5e0b
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::FORMAT_DEFAULT, :type_id=>TemplateType::TYPE_PAGE})
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::FORMAT_DEFAULT})
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
- x = Dir.pwd
34
- #y = File.expand_path File.dirname(__FILE__)
35
- d = File.dirname(@optimacms_tpl)
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
- names = []
44
- names << [d, name+".html"]
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
- parts = name.split /\//
45
+ #
46
+ names = []
49
47
 
50
- parts[-1] = '_'+parts[-1]
51
- name2 = parts.join('/')
48
+ #
49
+ parts = name.split /\//
52
50
 
53
- names << [d, name2+".html"]
54
- names << ["", name2+".html"]
51
+ parts[-1] = '_'+parts[-1]
52
+ name2 = parts.join('/')
55
53
 
56
- # try 2
57
- names.each do |p|
58
- f = File.join(Dir.pwd, 'app', 'views', p[0], p[1])
59
- (return render file: f) if File.exists? f
54
+ #
55
+ names << [d, name]
56
+ names << ["", name]
60
57
 
61
- f = File.join(Dir.pwd, 'app', 'views', p[0], p[1]+".haml")
62
- (return render file: f) if File.exists? f
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
- # default render
69
- return render f
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
- FORMAT_DEFAULT = 'html'
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+self.basename+Template.content_filename_lang_postfix(lang)+'.'+Template.content_filename_ext(self.tpl_format)
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
- ### settings and helpers
183
+ ### helpers for path
162
184
 
163
- def self.base_dir
164
- Rails.root.to_s + '/app/views/'
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
- def self.content_filename_lang_postfix(lang)
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.content_filename_ext(format)
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
@@ -4,9 +4,15 @@ module Optimacms
4
4
 
5
5
  TYPE_LAYOUT = 1
6
6
  TYPE_PAGE = 2
7
+ TYPE_PARTIAL = 3
8
+ TYPE_BLOCKVIEW = 4
7
9
 
10
+ #
8
11
  has_many :templates
9
12
 
13
+
14
+ # properties
15
+
10
16
  def to_s
11
17
  title
12
18
  end
@@ -19,14 +19,15 @@
19
19
  = hidden_field_tag :modal, @modal
20
20
 
21
21
  -#= f.input :parent_id, as: :hidden
22
- = f.input :type_id, as: :hidden
23
- = f.input :type, disabled: true, label: 'Type'
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?"
@@ -1,3 +1,3 @@
1
1
  module Optimacms
2
- VERSION = "0.1.32"
2
+ VERSION = "0.1.34"
3
3
  end
@@ -0,0 +1 @@
1
+ <p>partial HTML</p>
@@ -0,0 +1 @@
1
+ text in partial - part1.html.haml
@@ -0,0 +1,6 @@
1
+ include html:
2
+
3
+ = block 'temp/h1'
4
+
5
+ include haml:
6
+ = block 'temp/part1'
@@ -0,0 +1 @@
1
+ xml.build