[1005] | 1 | """ |
---|
| 2 | Local templates for the qplone3_theme |
---|
| 3 | """ |
---|
| 4 | import os, sys, re, datetime |
---|
| 5 | from ConfigParser import SafeConfigParser |
---|
| 6 | from paste.script import pluginlib |
---|
| 7 | |
---|
| 8 | from zopeskel.base import var |
---|
| 9 | from zopeskel.localcommands import ZopeSkelLocalTemplate |
---|
[1357] | 10 | |
---|
| 11 | from quintagroup.themetemplate import getEggInfo |
---|
| 12 | from quintagroup.themetemplate import getThemeVarsFP |
---|
[1005] | 13 | from quintagroup.themetemplate.localcommands import QThemeSubTemplate |
---|
| 14 | |
---|
| 15 | RESP = re.compile("\s+") |
---|
| 16 | REBAN = re.compile("[\\\/\,\.\+\-\*\%\~\@\#\$\^\&\|\;\:\?\(\)\=\[\]\{\}\_]+") |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | class SkinLayerSubTemplate(QThemeSubTemplate): |
---|
| 20 | """ |
---|
| 21 | A Plone Skin layer skeleton |
---|
| 22 | """ |
---|
| 23 | _template_dir = 'templates/skinlayer' |
---|
| 24 | summary = "A Plone 3 Skin Layer" |
---|
| 25 | |
---|
| 26 | compo_template_markers = [ |
---|
| 27 | ('layer4Skin', 'extra layer stuff goes here'), |
---|
| 28 | ] |
---|
| 29 | |
---|
| 30 | vars = [ |
---|
| 31 | var('layer_name', 'Skin Layer name (should not contain spaces)', |
---|
| 32 | default="skin_layer"), |
---|
| 33 | var('insert_type', 'Where insert the layer ("after" or "before")', default="after"), |
---|
| 34 | var('insert_control_layer', |
---|
| 35 | 'Layer after or before which your layer will be inserted, "*" accepted, which mean all', |
---|
| 36 | default='custom'), |
---|
| 37 | ] |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | class CSSSubTemplate(QThemeSubTemplate): |
---|
| 41 | """ |
---|
| 42 | A Plone CSS resource skeleton |
---|
| 43 | """ |
---|
| 44 | _template_dir = 'templates/cssresource' |
---|
| 45 | summary = "A Plone 3 CSS resource template" |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | vars = [ |
---|
| 49 | var('css_resource_name', 'Name of CSS resource', |
---|
| 50 | default="main.css"), |
---|
| 51 | var('css_file_path', 'Path to CSS file. If no path-empty file will be created.', |
---|
| 52 | default=''), |
---|
| 53 | var('cssreg_media', 'Optional.Possible values:screen,print,projection,handheld', |
---|
| 54 | default="screen", ), |
---|
| 55 | var('cssreg_rel', 'Optional', default="stylesheet"), |
---|
| 56 | var('cssreg_rendering', 'Optional.Possible values:import,link,inline', default="inline"), |
---|
| 57 | var('cssreg_cacheable', '', default="True"), |
---|
| 58 | var('cssreg_compression', 'Compression type', default="safe"), |
---|
| 59 | var('cssreg_cookable', 'Boolean, aka merging allowed', default="True"), |
---|
| 60 | var('cssreg_enables', 'Optional.Boolean', default="1"), |
---|
| 61 | var('cssreg_expression', 'Optional.A tal condition.', default=""), |
---|
| 62 | ] |
---|
| 63 | |
---|
| 64 | def pre(self, command, output_dir, vars): |
---|
| 65 | """ Set 'css_resource_content' value from css_file_path |
---|
| 66 | """ |
---|
| 67 | super(CSSSubTemplate, self).pre(command, output_dir, vars) |
---|
| 68 | |
---|
| 69 | vars['css_resource_content'] = '' |
---|
| 70 | if os.path.isfile(vars['css_file_path']): |
---|
| 71 | vars['css_resource_content'] = file(vars['css_file_path'],'rb').read() |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | class JSSubTemplate(QThemeSubTemplate): |
---|
| 75 | """ |
---|
| 76 | A Plone JS resource skeleton |
---|
| 77 | """ |
---|
| 78 | _template_dir = 'templates/jsresource' |
---|
| 79 | summary = "A Plone 3 JS resource template" |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | vars = [ |
---|
| 83 | var('js_resource_name', 'Name of JS resource', default="foo.js"), |
---|
| 84 | var('js_file_path', 'Path to JS file. If no path - empty file will be created', |
---|
| 85 | default=''), |
---|
| 86 | var('jsreg_inline', 'Optional.Boolean', default="False"), |
---|
| 87 | var('jsreg_cacheable', '', default="True"), |
---|
| 88 | var('jsreg_compression', 'Compression type.Possible:none,safe,full,safe-encode,full-encode', |
---|
| 89 | default="safe"), |
---|
| 90 | var('jsreg_cookable', 'Boolean, aka merging allowed', default="True"), |
---|
| 91 | var('jsreg_enables', 'Optional.Boolean', default="1"), |
---|
| 92 | var('jsreg_expression', 'Optional.A tal condition.', default=""), |
---|
| 93 | ] |
---|
| 94 | |
---|
| 95 | def pre(self, command, output_dir, vars): |
---|
| 96 | """ Set 'js_resource_content' value from js_file_path |
---|
| 97 | """ |
---|
| 98 | super(JSSubTemplate, self).pre(command, output_dir, vars) |
---|
| 99 | |
---|
| 100 | vars['js_resource_content'] = '' |
---|
| 101 | if os.path.isfile(vars['js_file_path']): |
---|
| 102 | vars['js_resource_content'] = file(vars['js_file_path'],'rb').read() |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | class ViewletOrderSubTemplate(QThemeSubTemplate): |
---|
| 106 | """ |
---|
| 107 | A Plone Order Viewlet skeleton |
---|
| 108 | """ |
---|
| 109 | _template_dir = 'templates/viewlet' |
---|
| 110 | summary = "A Plone 3 Order Viewlet template" |
---|
| 111 | |
---|
| 112 | # list of 2 item tuple - |
---|
| 113 | # (compotemplate_name, compo marker), for ex.: |
---|
| 114 | compo_template_markers = [] |
---|
| 115 | |
---|
| 116 | shared_vars = ['viewlet_profile_marker',] |
---|
| 117 | |
---|
| 118 | vars = [ |
---|
| 119 | var('viewlet_name', "Viewlet name", default='example'), |
---|
| 120 | var('viewlet_manager_interface', "Viewlet manager interface", |
---|
| 121 | default="plone.app.layout.viewlets.interfaces.IPortalHeader"), |
---|
| 122 | var('viewlet_manager_name', "Viewlet manager name", default='plone.portalheader'), |
---|
| 123 | var('viewlet_permission', "Viewlet permission", default="zope2.View"), |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | var('insert_type', 'Where insert the viewlet ("after" or "before")', default="after"), |
---|
| 127 | var('insert_control_viewlet', 'Viewlet after or before which your viewlet will be inserted, ' \ |
---|
| 128 | '"*" accepted, which mean all', default='*'), |
---|
| 129 | |
---|
| 130 | var('layer_interface', "Layer interface for registry this viewlet on", |
---|
| 131 | default=".interfaces.IThemeSpecific"), |
---|
| 132 | var('layer_name', "Layer name for registry this viewlet on", default=""), |
---|
| 133 | #var('skinname', "Skin name, for bind viewlet to, '*' - mean for all", default=""), |
---|
| 134 | #var('skinbase', "Base skin, for get viewlets from", default=""), |
---|
| 135 | ] |
---|
| 136 | |
---|
| 137 | def pre(self, command, output_dir, vars): |
---|
| 138 | """ Set 'css_resource_content' value from css_file_path |
---|
| 139 | """ |
---|
| 140 | super(ViewletOrderSubTemplate, self).pre(command, output_dir, vars) |
---|
| 141 | |
---|
| 142 | vn_lower_nospc = RESP.sub('',vars['viewlet_name']).lower() |
---|
| 143 | vn_lower_under = RESP.sub('_',vars['viewlet_name']).lower() |
---|
| 144 | VnCamel = ''.join([i.capitalize() for i in REBAN.sub(' ',vars['viewlet_name']).split()]) |
---|
| 145 | vars['viewlet_class_name'] = VnCamel |
---|
| 146 | vars['viewlet_interface_name'] = "I"+VnCamel |
---|
| 147 | vars['viewlet_template_name'] = vn_lower_nospc+'_viewlet.pt' |
---|
| 148 | |
---|
| 149 | viewlet_profile_marker = "[order_%s] viewlet stuff goes here" % \ |
---|
| 150 | '.'.join([vars['viewlet_manager_name'], vars['qplone3_theme_skinname'], |
---|
| 151 | vars['qplone3_theme_skinbase']]) |
---|
| 152 | |
---|
| 153 | vars['add_order_tag'] = self.add_order_tag(output_dir, vars, viewlet_profile_marker) |
---|
| 154 | vars['viewlet_profile_marker'] = viewlet_profile_marker |
---|
| 155 | self.compo_template_markers.append( |
---|
| 156 | ('viewlet_profiles',viewlet_profile_marker)) |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | def add_order_tag(self, output_dir, vars, pmarker): |
---|
| 160 | need_update = True |
---|
[1357] | 161 | egg_info = getEggInfo(output_dir) |
---|
| 162 | theme_vars_fp = getThemeVarsFP(egg_info) |
---|
[1005] | 163 | |
---|
[1357] | 164 | if os.path.exists(theme_vars_fp): |
---|
[1005] | 165 | config = SafeConfigParser() |
---|
| 166 | config.read(theme_vars_fp) |
---|
| 167 | |
---|
| 168 | sec, opt = 'qplone3_theme', 'used_subtemplates' |
---|
| 169 | used_subtemplates = filter(None,[st.strip() \ |
---|
| 170 | for st in config.get(sec,opt).split(',')]) |
---|
| 171 | |
---|
| 172 | if self.name in used_subtemplates: |
---|
| 173 | sections = [self.name,] |
---|
| 174 | if config.has_section('multiple_templates') and \ |
---|
| 175 | config.has_option('multiple_templates',self.name): |
---|
| 176 | ms_sections = config.get('multiple_templates',self.name) |
---|
| 177 | sections = [s.strip() for s in ms_sections.split(',')] |
---|
| 178 | |
---|
| 179 | pmarkers = [config.get(sec, 'viewlet_profile_marker') \ |
---|
| 180 | for sec in sections] |
---|
| 181 | if pmarker in pmarkers: |
---|
| 182 | need_update = False |
---|
| 183 | |
---|
| 184 | return need_update |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | class ViewletHiddenSubTemplate(QThemeSubTemplate): |
---|
| 188 | """ |
---|
| 189 | A Plone Hidden Viewlet skeleton |
---|
| 190 | """ |
---|
| 191 | _template_dir = 'templates/viewlet_hidden' |
---|
| 192 | summary = "A Plone 3 Hidden Viewlet template" |
---|
| 193 | |
---|
| 194 | shared_vars = ['viewlet_profile_marker',] |
---|
| 195 | |
---|
| 196 | compo_template_markers = [] |
---|
| 197 | |
---|
| 198 | vars = [ |
---|
| 199 | var('viewlet_name', "Viewlet name", default='plone.global_sections'), |
---|
| 200 | var('viewlet_manager_name', "Viewlet manager name", default='plone.portalheader'), |
---|
| 201 | #var('skinname', "Skin name, for bind viewlet to, may be '*'", default=""), |
---|
| 202 | ] |
---|
| 203 | |
---|
| 204 | def pre(self, command, output_dir, vars): |
---|
| 205 | """ Set 'css_resource_content' value from css_file_path |
---|
| 206 | """ |
---|
| 207 | super(ViewletHiddenSubTemplate, self).pre(command, output_dir, vars) |
---|
| 208 | |
---|
| 209 | viewlet_profile_marker = "[hidden_%s] viewlet stuff goes here" % \ |
---|
| 210 | '.'.join([vars['viewlet_manager_name'], vars['qplone3_theme_skinname']]) |
---|
| 211 | |
---|
| 212 | vars['add_hidden_tag'] = self.add_hidden_tag(output_dir, vars, viewlet_profile_marker) |
---|
| 213 | vars['viewlet_profile_marker'] = viewlet_profile_marker |
---|
| 214 | self.compo_template_markers.append( |
---|
| 215 | ('viewlet_hidden_profiles',viewlet_profile_marker)) |
---|
| 216 | |
---|
| 217 | |
---|
| 218 | def add_hidden_tag(self, output_dir, vars, pmarker): |
---|
| 219 | add_hidden = True |
---|
[1357] | 220 | egg_info = getEggInfo(output_dir) |
---|
| 221 | theme_vars_fp = getThemeVarsFP(egg_info) |
---|
[1005] | 222 | |
---|
[1357] | 223 | if os.path.exists(theme_vars_fp): |
---|
[1005] | 224 | config = SafeConfigParser() |
---|
| 225 | config.read(theme_vars_fp) |
---|
| 226 | |
---|
| 227 | sec, opt = 'qplone3_theme', 'used_subtemplates' |
---|
| 228 | used_subtemplates = filter(None,[st.strip() \ |
---|
| 229 | for st in config.get(sec,opt).split(',')]) |
---|
| 230 | |
---|
| 231 | if self.name in used_subtemplates: |
---|
| 232 | sections = [self.name,] |
---|
| 233 | if config.has_section('multiple_templates') and \ |
---|
| 234 | config.has_option('multiple_templates',self.name): |
---|
| 235 | ms_sections = config.get('multiple_templates',self.name) |
---|
| 236 | sections = [s.strip() for s in ms_sections.split(',')] |
---|
| 237 | |
---|
| 238 | pmarkers = [config.get(sec, 'viewlet_profile_marker') \ |
---|
| 239 | for sec in sections] |
---|
| 240 | if pmarker in pmarkers: |
---|
| 241 | add_hidden = False |
---|
| 242 | return add_hidden |
---|
| 243 | |
---|
| 244 | class ImportSubTemplate(QThemeSubTemplate): |
---|
| 245 | """ |
---|
| 246 | A skeleton for importing zexp objects into portal on theme installation |
---|
| 247 | """ |
---|
| 248 | _template_dir = 'templates/importing' |
---|
| 249 | summary = "A template for importing zexp-objects into portal on installation" |
---|
| 250 | |
---|
| 251 | def pre(self, command, output_dir, vars): |
---|
| 252 | """ Set timestamp var for generate import_steps profile id |
---|
| 253 | """ |
---|
| 254 | super(ImportSubTemplate, self).pre(command, output_dir, vars) |
---|
| 255 | |
---|
| 256 | vars['timestamp'] = datetime.date.today().strftime("%Y%m%d") |
---|
| 257 | vars['already_used'] = self.already_used(vars) |
---|
| 258 | |
---|
| 259 | def already_used(self, vars): |
---|
| 260 | used = vars.get('qplone3_theme_used_subtemplates','').split(',') |
---|
| 261 | return self.name in filter(None,[st.strip() for st in used]) |
---|