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

Missing context keys for HTML::Pipeline::EmojiFilter: :asset_root #262

Closed
marcocanderle opened this issue Aug 22, 2016 · 2 comments
Closed

Comments

@marcocanderle
Copy link

marcocanderle commented Aug 22, 2016

Hi,

I'm with a Rails 5 application and adding html_pipeline gem with the EmojiFilter extension so that I can process the text sent by the users and filter the emojies.

I have the following:

def filtered_content
    pipeline = HTML::Pipeline.new [
     HTML::Pipeline::PlainTextInputFilter,
     HTML::Pipeline::MarkdownFilter,
     HTML::Pipeline::SanitizationFilter,
     HTML::Pipeline::AutolinkFilter,
     HTML::Pipeline::EmojiFilter
    ]
   pipeline.call(content)[:output].to_s
end

I followed the usual steps adding the gemoji gem so that I can use the EmojiFilter, but when I add it to the pipeline declaration and try to use the pipeline I get the error:

Missing context keys for HTML::Pipeline::EmojiFilter: :asset_root

I added this on my assets.rb initializer:

  Rails.application.config.assets.paths << Emoji.images_path
  Rails.application.config.assets.precompile << "emoji/**/*.png"

And also ran "rake emoji" but the error is still there.

Any ideas of I could solve this?

Thanks!
Marco

@JuanitoFatas
Copy link
Contributor

JuanitoFatas commented Aug 23, 2016

Hi! The asset_root is the base url to link emoji sprite, not related to Sprockets.

So you need to change your html-pipeline code:

def filtered_content
    pipeline = HTML::Pipeline.new [
     HTML::Pipeline::PlainTextInputFilter,
     HTML::Pipeline::MarkdownFilter,
     HTML::Pipeline::SanitizationFilter,
     HTML::Pipeline::AutolinkFilter,
     HTML::Pipeline::EmojiFilter
    ], { asset_root: "the url of your assets" } # <------
    # E.g. GitHub uses this: "https://assets-cdn.github.com/images/icons/emoji/unicode"
   pipeline.call(content)[:output].to_s
end

Hope this helps! 😊

@marcocanderle
Copy link
Author

That's exactly what I was looking for!
Thanks a lot @JuanitoFatas

Perhaps that exact example could be on the readme file?

Thanks a lot for your help and for this gem!

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