Created
February 28, 2013 00:16
-
-
Save rbistolfi/5053129 to your computer and use it in GitHub Desktop.
Google maps rest extension for Nikola
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2012 Roberto Alsina y otros. | |
# Permission is hereby granted, free of charge, to any | |
# person obtaining a copy of this software and associated | |
# documentation files (the "Software"), to deal in the | |
# Software without restriction, including without limitation | |
# the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the | |
# Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice | |
# shall be included in all copies or substantial portions of | |
# the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | |
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | |
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | |
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | |
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
from docutils import nodes | |
from docutils.parsers.rst import directives | |
CODE = """\ | |
<iframe width="{width}" height="{height}" frameborder="0" scrolling="no" \ | |
marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q={location}&\ | |
num=1&ie=UTF8&t=m&z={zoom}&ll={location}&output=embed&iwloc=near"></iframe>""" | |
def gmaps(name, args, options, content, lineno, | |
contentOffset, blockText, state, stateMachine): | |
""" Restructured text extension for inserting google embedded maps """ | |
if len(content) == 0: | |
return | |
string_vars = { | |
'location': content[0], | |
'width': 425, | |
'height': 344, | |
'zoom': 20, | |
} | |
extra_args = content[1:] # Because content[0] is location | |
extra_args = [ea.strip().split("=") for ea in extra_args] # key=value | |
extra_args = [ea for ea in extra_args if len(ea) == 2] # drop bad lines | |
extra_args = dict(extra_args) | |
string_vars.update(extra_args) | |
return [nodes.raw('', CODE.format(**string_vars), format='html')] | |
gmaps.content = True | |
directives.register_directive('gmaps', gmaps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment