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

Move url & icon helpers to dexlib #117

Open
magical opened this issue Apr 24, 2018 · 1 comment
Open

Move url & icon helpers to dexlib #117

magical opened this issue Apr 24, 2018 · 1 comment

Comments

@magical
Copy link
Member

magical commented Apr 24, 2018

To help with #115, we want to move the url and icon helper functions — pokemon_url, type_icon, make_thingy_url, etc — from the helpers module to dexlib (templates/pokedex/lib.mako), where they'll have access to the template context variables.

@magical
Copy link
Member Author

magical commented Apr 28, 2018

Started on this. As expected, it causes a lot of little problems that are a pain in the ass to fix.

magical added a commit that referenced this issue Apr 28, 2018
Pyramid requires access to the request object to be able to generate
URLs, so move helpers that generate URLs to dexlib, where they'll have
access to the template context. This seems easier than adding an
explicit 'request' or 'url' parameter to all of them.

The next commit will fix up calls to the old functions.

- The _=_ parameters are no longer necessary because we already have
  access to the translator. Keep the parameters so that we don't break
  callers, but change the default to _=None because there is no longer
  a global _ variable in scope.

Updates #115.
Updates #117.
magical added a commit that referenced this issue Apr 28, 2018
Mechanically update calls from the old h.pokedex functions to the new
dexlib functions.

Performed by sed

    sed -r -f update-helpers.sed -i templates/pokedex/{,gadgets,search,conquest}/*.mako

    s|h\.pokedex\.(pokedex_img)|dexlib.\1|g
    s|h\.pokedex\.(chrome_img)|dexlib.\1|g
    s|h\.pokedex\.(generation_icon)|dexlib.\1|g
    s|h\.pokedex\.(version_icons)|dexlib.\1|g
    s|h\.pokedex\.(version_group_icon)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_has_media)|dexlib.\1|g
    s|h\.pokedex\.(species_image)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_form_image)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_icon)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_link)|dexlib.\1|g
    s|h\.pokedex\.(form_flavor_link)|dexlib.\1|g
    s|h\.pokedex\.(damage_class_icon)|dexlib.\1|g
    s|h\.pokedex\.(type_icon)|dexlib.\1|g
    s|h\.pokedex\.(type_link)|dexlib.\1|g
    s|h\.pokedex\.(item_link)|dexlib.\1|g

Updates #117.
magical added a commit that referenced this issue Apr 28, 2018
The previous commit changed a bunch of h.pokedex references to dexlib.
Some templates didn't import dexlib before, so update those templates.

Updates #117.
magical added a commit that referenced this issue Apr 28, 2018
magical added a commit that referenced this issue Apr 28, 2018
It is needed by the flavor page controller.

Updates #117
magical added a commit that referenced this issue Jul 20, 2019
For the pyramid port, which doesn't have threadlocal globals like
config. Most of the other helpers are going to be moving to dexlib,
where they'll have access to the request context, but pokemon_has_media
has to stay because it is used in a controller, so we have to get the
context to it some other way.

Also add a convenient wrapper function to dexlib which passes the config
parameter implicitly, and update the template code to call it.

Updates #117
magical added a commit that referenced this issue Jul 20, 2019
Pyramid requires access to the request object to be able to generate
URLs, so the plan is to move helpers that generate URLs to dexlib, where
they'll have access to the template context and thus the request object.
This seems easier than adding an explicit 'request' or 'url' parameter
to all of them.

Copy image and url helpers from splinext.pokedex.helpers to dexlib.
Update any internal references to those helpers, but leave external
callers alone for now. The next few commits will start fixing up calls
to the old functions.

Keep the old functions around (for now) so as not to break anything.
We can't do a move+update in one commit anyway because there is code in
the `veekun` repository which still uses the old helpers.

The _=_ parameters are no longer necessary because template functions
already have access to the translator. Keep the parameters so that we
don't break callers, but change the default to _=None because there is
no longer a global _ variable in scope. (The default value doesn't
matter - it gets immediately overwritten by a line that gets injected
into template functions, `_ = i18n.get_translator(lambda i18n, c)`)

Updates #115.
Updates #117.
magical added a commit that referenced this issue Jul 20, 2019
A bunch of helper functions are moving to dexlib, so there are a lot of
templates that are going to need to import dexlib now.

Updates #117.
magical added a commit that referenced this issue Jul 20, 2019
Mechanically update calls from the old h.pokedex icon and url helpers
functions to the new dexlib functions.

Performed by sed

    sed -r -f update-helpers.sed -i templates/pokedex/{,gadgets,search,conquest}/*.mako
    git checkout HEAD -- templates/pokedex/lib.mako

    s|h\.pokedex\.(pokedex_img)|dexlib.\1|g
    s|h\.pokedex\.(chrome_img)|dexlib.\1|g
    s|h\.pokedex\.(generation_icon)|dexlib.\1|g
    s|h\.pokedex\.(version_icons)|dexlib.\1|g
    s|h\.pokedex\.(version_group_icon)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_has_media)|dexlib.\1|g
    s|h\.pokedex\.(species_image)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_form_image)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_icon)|dexlib.\1|g
    s|h\.pokedex\.(pokemon_link)|dexlib.\1|g
    s|h\.pokedex\.(form_flavor_link)|dexlib.\1|g
    s|h\.pokedex\.(damage_class_icon)|dexlib.\1|g
    s|h\.pokedex\.(type_icon)|dexlib.\1|g
    s|h\.pokedex\.(type_link)|dexlib.\1|g
    s|h\.pokedex\.(item_link)|dexlib.\1|g

Updates #117.
magical added a commit that referenced this issue Jul 20, 2019
Mechanically rewrite calls to the icon and url helpers from
h.pokedex to dexlib. Same sed script as previous commit.

Import statement added manually.

Updates #117
magical added a commit that referenced this issue Jul 20, 2019
Mechanically rewrite calls to the icon and url helpers from
h.pokedex to dexlib. Same sed script as previous commit.

Updates #117
magical added a commit that referenced this issue Jul 20, 2019
Functions in templates already have access to _, so we don't need to
provide it explicitly.

Updates #117
magical added a commit that referenced this issue Jul 20, 2019
No longer necessary

Updates #117
magical added a commit that referenced this issue Jul 20, 2019
This deletes the image and url helper functions which were moved from
h.pokedex to dexlib.

Except:
- pokedex_img, which is used in veekun
- generation_icon, which is used in the pokedex_search controller
- version_icons, which is used in the pokedex_search controller
- chrome_img, because it is needed by generation_icon

Updates #117
magical added a commit that referenced this issue Jul 20, 2019
Needs access to dexlib.pokemon_form_image to generate pokemon icons.
Rather than moving it to dexlib, introduce a callback for getting the
icon.

Updates #115
Updates #117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant