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

Add Budou custom filter #293

Closed
tushuhei opened this issue Sep 13, 2016 · 11 comments
Closed

Add Budou custom filter #293

tushuhei opened this issue Sep 13, 2016 · 11 comments

Comments

@tushuhei
Copy link

It would be great if we can add Budou as a custom filter in order to provide organized line breaks for CJK websites. Budou is a simple python script, so migration should go smoothly.
https://github.com/google/budou
Perhaps it's better to add caching functionality to Budou before we proceed to the migration.

@tushuhei
Copy link
Author

tushuhei commented Sep 15, 2016

I made a custom filter to apply Budou in my personal website.
https://github.com/tushuhei/tushuhei-portfolio/blob/master/extensions/wordwrap.py
The code should look like:

from jinja2 import Markup, contextfilter
from jinja2.ext import Extension
import jinja2

budou_parser = budou.authenticate('budou-cloud.json')

@contextfilter
def do_budou(context, value):
  doc = context.get('doc')
  if doc.locale == 'ja':
    data = budou_parser.parse(value)
    return Markup(data['html_code'])
  else:
    return value

class Wordwrap(Extension):
  def __init__(self, environment):
    super(Wordwrap, self).__init__(environment)
    environment.filters['budou'] = do_budou

@jeremydw
Is there any room to add some filters like this in Grow repo, or is this something should be delivered in a separated repo? Once we get a clear direction on this, I can create a pull request for that.

@jeremydw jeremydw mentioned this issue Sep 15, 2016
@tushuhei
Copy link
Author

@jeremydw Just a friendly ping to see if there's any update on this topic :) I'd love to commit once the structure is envisioned, so please let me know if there's anything I can help.

@jeremydw
Copy link
Member

jeremydw commented Feb 10, 2017 via email

@tushuhei
Copy link
Author

Great to hear that! Thanks, looking forward to hearing the update.

@tushuhei
Copy link
Author

I just wanted to check if there's any update :) Please let me know if there's anything I can help!

@jeremydw
Copy link
Member

Sorry for dropping the ball on this! Now that we're working on simplifying extension management via grow install, we're separating out extensions into their own repositories. I started an initial commit for a Budou extension right here - https://github.com/grow/grow-ext-budou

Some more work needs to be done for this to work entirely with grow install – PRs incoming.

@tushuhei
Copy link
Author

tushuhei commented Jun 17, 2017 via email

@jeremydw
Copy link
Member

Almost done! We've added tests to verify the behavior and quick README. Feel free to look over the extension and let me know if you'd like any improvements or suggestions to the system!

https://github.com/grow/grow-ext-budou

Now Grow users can use budou by simply changing extensions.txt, editing podspec.yaml, and running grow install.

We need to integrate #457 and make another grow release before this works with the frozen version of Grow, but it should work as-is with the pip install version right now.

@jeremydw
Copy link
Member

Also - the example data in that repository shows off a sample integration:
https://github.com/grow/grow-ext-budou/tree/master/example

@tushuhei
Copy link
Author

tushuhei commented Jun 28, 2017 via email

@jeremydw
Copy link
Member

jeremydw commented Jul 7, 2017

At long last we can now close this issue out, as Grow 0.2.0 is released and we have a separate extension making it very easy to use budou. (https://github.com/grow/grow-ext-budou) Thanks @tushuhei ! :) We can send out some communication about this internally now.

@jeremydw jeremydw closed this as completed Jul 7, 2017
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

2 participants