Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#68] Add FontAwesome 4 icon names #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions ckanext/pages/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,26 @@ def get_recent_blog_posts(number=5, exclude=None):
return new_list


def get_plus_icon():
# Maps selected FontAwesome 4 icon names to FontAwesome 3
_FA4_TO_FA3 = {
'plus-square': 'plus-sign-alt',
'pencil-square-o': 'edit',
}


def get_icon(name):
'''
Get a FontAwesome icon name.

Given the FontAwesome 4 icon name returns the appropriate icon name
for the current CKAN version.

Raises a ``KeyError`` on CKAN versions prior to 2.7 if the
FontAwesome 3 name for the given icon is not known.
'''
if toolkit.check_ckan_version(min_version='2.7'):
return 'plus-square'
return 'plus-sign-alt'
return name
return _FA4_TO_FA3[name]


class PagesPlugin(PagesPluginBase):
Expand Down Expand Up @@ -131,7 +147,7 @@ def get_helpers(self):
'render_content': render_content,
'get_wysiwyg_editor': get_wysiwyg_editor,
'get_recent_blog_posts': get_recent_blog_posts,
'pages_get_plus_icon': get_plus_icon
'pages_get_icon': get_icon
}

def after_map(self, map):
Expand All @@ -141,7 +157,7 @@ def after_map(self, map):
map.connect('organization_pages_delete', '/organization/pages_delete/{id}{page:/.*|}',
action='org_delete', ckan_icon='delete', controller=controller)
map.connect('organization_pages_edit', '/organization/pages_edit/{id}{page:/.*|}',
action='org_edit', ckan_icon='edit', controller=controller)
action='org_edit', ckan_icon=get_icon('pencil-square-o'), controller=controller)
map.connect('organization_pages_index', '/organization/pages/{id}',
action='org_show', ckan_icon='file', controller=controller, highlight_actions='org_edit org_show', page='')
map.connect('organization_pages', '/organization/pages/{id}{page:/.*|}',
Expand All @@ -151,7 +167,7 @@ def after_map(self, map):
map.connect('group_pages_delete', '/group/pages_delete/{id}{page:/.*|}',
action='group_delete', ckan_icon='delete', controller=controller)
map.connect('group_pages_edit', '/group/pages_edit/{id}{page:/.*|}',
action='group_edit', ckan_icon='edit', controller=controller)
action='group_edit', ckan_icon=get_icon('pencil-square-o'), controller=controller)
map.connect('group_pages_index', '/group/pages/{id}',
action='group_show', ckan_icon='file', controller=controller, highlight_actions='group_edit group_show', page='')
map.connect('group_pages', '/group/pages/{id}{page:/.*|}',
Expand All @@ -161,7 +177,7 @@ def after_map(self, map):
map.connect('pages_delete', '/pages_delete{page:/.*|}',
action='pages_delete', ckan_icon='delete', controller=controller)
map.connect('pages_edit', '/pages_edit{page:/.*|}',
action='pages_edit', ckan_icon='edit', controller=controller)
action='pages_edit', ckan_icon=get_icon('pencil-square-o'), controller=controller)
map.connect('pages_index', '/pages',
action='pages_index', ckan_icon='file', controller=controller, highlight_actions='pages_edit pages_index pages_show')
map.connect('pages_show', '/pages{page:/.*|}',
Expand All @@ -172,7 +188,7 @@ def after_map(self, map):
map.connect('blog_delete', '/blog_delete{page:/.*|}',
action='blog_delete', ckan_icon='delete', controller=controller)
map.connect('blog_edit', '/blog_edit{page:/.*|}',
action='blog_edit', ckan_icon='edit', controller=controller)
action='blog_edit', ckan_icon=get_icon('pencil-square-o'), controller=controller)
map.connect('blog_index', '/blog',
action='blog_index', ckan_icon='file', controller=controller, highlight_actions='blog_edit blog_index blog_show')
map.connect('blog_show', '/blog{page:/.*|}',
Expand Down
2 changes: 1 addition & 1 deletion ckanext/pages/theme/templates_main/ckanext_pages/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block primary_content %}
<section class="module-content">
{% if h.check_access('ckanext_pages_update') %}
{% link_for _('Edit'), controller='ckanext.pages.controller:PagesController', action='blog_edit', page='/' + c.page.name, class_='btn btn-primary pull-right', icon='edit' %}
{% link_for _('Edit'), controller='ckanext.pages.controller:PagesController', action='blog_edit', page='/' + c.page.name, class_='btn btn-primary pull-right', icon=h.pages_get_icon('pencil-square-o') %}
{% endif %}
<h1 class="page-heading">{{ c.page.title }}</h1>
{% if c.page.publish_date %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block page_primary_action %}
{% if h.check_access('ckanext_pages_update', {}) %}
{% link_for _('Add Article'), controller='ckanext.pages.controller:PagesController', action='blog_edit', page='', class_='btn btn-primary', icon=h.pages_get_plus_icon() %}
{% link_for _('Add Article'), controller='ckanext.pages.controller:PagesController', action='blog_edit', page='', class_='btn btn-primary', icon=h.pages_get_icon('plus-square') %}
{% endif %}
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block subtitle %}{{ _('Pages') }} - {{ c.group_dict.display_name }}{% endblock %}

{% block primary_content_inner %}
{% link_for _('Edit page'), controller='ckanext.pages.controller:PagesController', action='group_edit', id=c.group_dict.name, page='/' + c.page.name, class_='btn btn-primary pull-right', icon='edit' %}
{% link_for _('Edit page'), controller='ckanext.pages.controller:PagesController', action='group_edit', id=c.group_dict.name, page='/' + c.page.name, class_='btn btn-primary pull-right', icon=h.pages_get_icon('pencil-square-o') %}
<h1 class="page-heading">{{ c.page.title }}</h1>
{% if c.page.content %}
{% set editor = h.get_wysiwyg_editor() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block page_primary_action %}
{% if h.check_access('package_create', {'group_id': c.group_dict.id}) %}
{% link_for _('Add page'), controller='ckanext.pages.controller:PagesController', action='group_edit', id=c.group_dict.name, page='', class_='btn btn-primary', icon=h.pages_get_plus_icon() %}
{% link_for _('Add page'), controller='ckanext.pages.controller:PagesController', action='group_edit', id=c.group_dict.name, page='', class_='btn btn-primary', icon=h.pages_get_icon('plus-square') %}
{% endif %}
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block subtitle %}{{ _('Pages') }} - {{ c.group_dict.display_name }}{% endblock %}

{% block primary_content_inner %}
{% link_for _('Edit page'), controller='ckanext.pages.controller:PagesController', action='org_edit', id=c.group_dict.name, page='/' + c.page.name, class_='btn btn-primary pull-right', icon='edit' %}
{% link_for _('Edit page'), controller='ckanext.pages.controller:PagesController', action='org_edit', id=c.group_dict.name, page='/' + c.page.name, class_='btn btn-primary pull-right', icon=h.pages_get_icon('pencil-square-o') %}
<h1 class="page-heading">{{ c.page.title }}</h1>
{% if c.page.content %}
{% set editor = h.get_wysiwyg_editor() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block page_primary_action %}
{% if h.check_access('package_create', {'group_id': c.group_dict.id}) %}
{% link_for _('Add page'), controller='ckanext.pages.controller:PagesController', action='org_edit', id=c.group_dict.name, page='', class_='btn btn-primary', icon=h.pages_get_plus_icon() %}
{% link_for _('Add page'), controller='ckanext.pages.controller:PagesController', action='org_edit', id=c.group_dict.name, page='', class_='btn btn-primary', icon=h.pages_get_icon('plus-square') %}
{% endif %}
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion ckanext/pages/theme/templates_main/ckanext_pages/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block primary %}
<section class="module-content">
{% if h.check_access('ckanext_pages_update') %}
{% link_for _('Edit'), controller='ckanext.pages.controller:PagesController', action='pages_edit', page='/' + c.page.name, class_='btn btn-primary pull-right', icon='edit' %}
{% link_for _('Edit'), controller='ckanext.pages.controller:PagesController', action='pages_edit', page='/' + c.page.name, class_='btn btn-primary pull-right', icon=h.pages_get_icon('pencil-square-o') %}
{% endif %}
<h1 class="page-heading">{{ c.page.title }}</h1>
{% if c.page.content %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block page_primary_action %}
{% if h.check_access('ckanext_pages_update', {}) %}
{% link_for _('Add page'), controller='ckanext.pages.controller:PagesController', action='pages_edit', page='', class_='btn btn-primary', icon=h.pages_get_plus_icon() %}
{% link_for _('Add page'), controller='ckanext.pages.controller:PagesController', action='pages_edit', page='', class_='btn btn-primary', icon=h.pages_get_icon('plus-square') %}
{% endif %}
{% endblock %}

Expand Down