Skip to content

Commit

Permalink
Merge pull request #323 from plone/erral-theme_barceloneta-subtemplate
Browse files Browse the repository at this point in the history
Add a theme_barceloneta subtemplate for addon template
  • Loading branch information
MrTango committed Oct 17, 2018
2 parents f92e81a + 25d0399 commit 7e47b06
Show file tree
Hide file tree
Showing 184 changed files with 164,177 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Changelog
3.4.3 (2018-10-17)
------------------

- Add a new subtemplate for addon that creates a full barceloneta-based theme
[erral]

- Add a build step to report coverage on gitlab and run tests on stages
[erral]

Expand All @@ -21,6 +24,7 @@ Changelog
was removed from barceloneta theme. fixes #317
[fredvd]


- Deactivated the dublicated template file definition in view Python class
[MrTango]

Expand Down
8 changes: 8 additions & 0 deletions bobtemplates/plone/bobregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def plone_theme():
return reg


def plone_theme_barceloneta():
reg = RegEntry()
reg.template = 'bobtemplates.plone:theme_barceloneta'
reg.plonecli_alias = 'theme_barceloneta'
reg.depend_on = 'plone_addon'
return reg


def plone_content_type():
reg = RegEntry()
reg.template = 'bobtemplates.plone:content_type'
Expand Down
131 changes: 131 additions & 0 deletions bobtemplates/plone/theme_barceloneta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# -*- coding: utf-8 -*-

from bobtemplates.plone.base import base_prepare_renderer
from bobtemplates.plone.base import echo
from bobtemplates.plone.base import git_commit
from bobtemplates.plone.base import update_file
from bobtemplates.plone.base import validate_packagename
from lxml import etree
from mrbob.bobexceptions import ValidationError

import os
import re


def pre_theme_name(configurator, question):
validate_packagename(configurator)

default = (
os.path.basename(configurator.target_directory)
.split('.')[-1]
.capitalize()
)
if default:
question.default = default


def post_theme_name(configurator, question, answer):
regex = r'^\w+[a-zA-Z0-9 \.\-_]*\w$'
if not re.match(regex, answer):
msg = u"Error: '{0}' is not a valid themename.\n".format(answer)
msg += u"Please use a valid name (like 'Tango' or 'my-tango.com')!\n"
msg += u'At beginning or end only letters|diggits are allowed.\n'
msg += u"Inside the name also '.-_' are allowed.\n"
msg += u'No umlauts!'
raise ValidationError(msg)
return answer


def prepare_renderer(configurator):
echo('Using theme_barceloneta subtemplate:', 'info')
configurator = base_prepare_renderer(configurator)
configurator.variables['template_id'] = 'theme_barceloneta'

def normalize_theme_name(value):
value = '-'.join(value.split('_'))
value = '-'.join(value.split())
return value

configurator.variables['theme.normalized_name'] = normalize_theme_name(
configurator.variables.get('theme.name'),
).lower()


def _update_metadata_xml(configurator):
"""Add plone.app.theming dependency metadata.xml in Generic Setup
profiles."""
metadata_file_name = u'metadata.xml'
metadata_file_dir = u'profiles/default'
metadata_file_path = configurator.variables['package_folder'] + '/' + \
metadata_file_dir + '/' + metadata_file_name

with open(metadata_file_path, 'r') as xml_file:
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(xml_file, parser)
dependencies = tree.xpath('/metadata/dependencies')[0]
dep = 'profile-plone.app.theming:default'
dep_exists = False
for e in dependencies.iter('dependency'):
dep_name = e.text
if dep_name == dep:
dep_exists = True

if dep_exists:
print(
'{dep} already in metadata.xml, skip adding!'.format(
dep=dep,
),
)
return
dep_element = etree.Element('dependency')
dep_element.text = dep
dependencies.append(dep_element)

with open(metadata_file_path, 'wb') as xml_file:
tree.write(
xml_file,
pretty_print=True,
xml_declaration=True,
encoding='utf-8',
)


def _update_configure_zcml(configurator):
file_name = u'configure.zcml'
file_path = configurator.variables['package_folder'] + '/' + file_name
namespaces = {'plone': 'http://namespaces.plone.org/plone'}

with open(file_path, 'r') as xml_file:
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(xml_file, parser)
tree_root = tree.getroot()
theme_name = configurator.variables['theme.normalized_name']
theme_xpath = "./plone:static[@name='{0}']".format(theme_name)
if len(tree_root.xpath(theme_xpath, namespaces=namespaces)):
print(
'{name} already in configure.zcml, skip adding!'.format(
name=theme_name,
),
)
return

match_str = '-*- extra stuff goes here -*-'
insert_str = """
<plone:static
directory="theme"
type="theme"
name="{0}"
/>
""".format(configurator.variables['theme.normalized_name'])
update_file(configurator, file_path, match_str, insert_str)


def post_renderer(configurator):
""""""
_update_configure_zcml(configurator)
_update_metadata_xml(configurator)
git_commit(
configurator,
'Add theme: {0}'.format(configurator.variables['theme.name']),
)
21 changes: 21 additions & 0 deletions bobtemplates/plone/theme_barceloneta/.mrbob.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[questions]
subtemplate_warning.question = Please commit your changes, before using a sub-template! Continue anyway? (n/y)
subtemplate_warning.required = True
subtemplate_warning.default = n
subtemplate_warning.pre_ask_question = bobtemplates.plone.base:git_clean_state_check
subtemplate_warning.post_ask_question = mrbob.hooks:validate_choices bobtemplates.plone.base:subtemplate_warning_post_question
subtemplate_warning.choices = y|n
subtemplate_warning.choices_delimiter = |

theme.name.question = Theme name
theme.name.pre_ask_question = bobtemplates.plone.base:check_root_folder
theme.name.post_ask_question = bobtemplates.plone.theme:post_theme_name
theme.name.required = True
theme.name.default = My Theme
theme.name.help = The name under which the theme is shown in the control panel. Only letters, digits and '.-_' and blank are allowed.


[template]
pre_render = bobtemplates.plone.theme:prepare_renderer
post_render = bobtemplates.plone.theme:post_renderer
post_ask = bobtemplates.plone.base:set_global_vars
39 changes: 39 additions & 0 deletions bobtemplates/plone/theme_barceloneta/DEVELOP_THEME.rst.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Theme development
-----------------

In order to develop the theme you need to install grunt-cli global::

$ sudo npm install -g grunt-cli

And then run `npm install` both in the package root and in the theme folder:

$ npm install

$ cd ./src/{{{ package.namespace }}}/{{{ package.name }}}/theme
$ npm install


After executing these commands you can run grunt on the package root folder to watch for any less changes::

$ grunt watch

This will make sure that the many .less files are compiled to .css on the fly and then served up from the theme.

You can also use this command to automaticly reload the browser after changes::

$ grunt plone-bsync

It will run a Grunt browser sync task in a new browser window and will reload after every change of the less files in the less folder. If your Plone is not running on port 8080 you have to adjust the proxy option in the Gruntfile.js.

If you prefer to do a one time compile of the less files you can run::

$ grunt compile


Note
----

- If you are make changes TTW, make sure that Development Mode is enabled by going to the `Site Setup` > `Resource Registries`
and check the `Development Mode` checkbox, this ensures that your changes show up and aren't cached.
- this theme is using a Grunt setup to compile the resources. The grunt setup is outside of the theme folder in the package root. If you only have a Zip-file version of this theme, have a look at the example theme plonetheme.tango (github.com/collective) for the Gruntfile.js and package.json to setup your own Grunt above your theme folder.
- You can delete the "custom-theme-marker" in the index.html and in custom.less
104 changes: 104 additions & 0 deletions bobtemplates/plone/theme_barceloneta/Gruntfile.js.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// we could just concatenate everything, really
// but we like to have it the complex way.
// also, in this way we do not have to worry
// about putting files in the correct order
// (the dependency tree is walked by r.js)
less: {
dist: {
options: {
paths: [],
strictMath: false,
sourceMap: true,
outputSourceFiles: true,
sourceMapFileInline: false,
sourceMapURL: '++theme++{{{ theme.normalized_name }}}/less/theme-compiled.less.map',
sourceMapFilename: 'less/theme-compiled.less.map',
modifyVars: {
"isPlone": "false"
}
},
files: {
'less/theme-compiled.css': 'less/theme.local.less',
}
}
},
postcss: {
options: {
map: true,
processors: [
require('autoprefixer')({
browsers: ['last 2 versions']
})
]
},
dist: {
src: 'less/*.css'
}
},
watch: {
scripts: {
files: [
'less/*.less',
'barceloneta/less/*.less'
],
tasks: ['less', 'postcss']
}
},
browserSync: {
html: {
bsFiles: {
src : [
'less/*.less',
'barceloneta/less/*.less',
'*.html'
]
},
options: {
watchTask: true,
debugInfo: true,
online: true,
server: {
baseDir: "."
},
}
},
plone: {
bsFiles: {
src : [
'less/*.less',
'barceloneta/less/*.less',
'*.html',
'*.xml'
]
},
options: {
watchTask: true,
debugInfo: true,
proxy: "localhost:8080",
reloadDelay: 3000,
// reloadDebounce: 2000,
online: true
}
}
}
});


// grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-browser-sync');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-postcss');

// CWD to theme folder
grunt.file.setBase('./src/{{{ package.namespace }}}/{{{ package.name }}}/theme');

grunt.registerTask('compile', ['less', 'postcss']);
grunt.registerTask('default', ['compile']);
grunt.registerTask('bsync', ["browserSync:html", "watch"]);
grunt.registerTask('plone-bsync', ["browserSync:plone", "watch"]);
};
15 changes: 15 additions & 0 deletions bobtemplates/plone/theme_barceloneta/package.json.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"//": "Put here only devDependencies, theme dependencies should stay inside of the theme folder.",
"name": "{{{ package.dottedname }}}",
"version": "1.0.0",
"devDependencies": {
"grunt": "~0.4.4",
"grunt-browser-sync": "^2.2.0",
"grunt-contrib-less": "latest",
"grunt-contrib-watch": "latest",
"grunt-postcss": "^0.8.0",
"pixrem": "^3.0.2",
"cssnano": "^3.7.7",
"autoprefixer": "^6.5.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<theme>
<name>{{{ theme.normalized_name }}}</name>
<enabled>true</enabled>
</theme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<theme>

<name>barceloneta</name>
<enabled>true</enabled>

</theme>

0 comments on commit 7e47b06

Please sign in to comment.