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

@mention allow for custom regex to identify usernames. #157

Merged

Conversation

brittballard
Copy link

  • This allows for easier customization of the mention patter regex

@brittballard
Copy link
Author

@jch I believe this is the modification discussed in the previous PR.

@jch
Copy link
Contributor

jch commented Oct 6, 2014

@brittballard while this does allow a user to overload the MentionPattern regex, it still requires a user to subclass the filter in order to change it. A better implementation would be to have an :mention_pattern that's available in the context. For example, :base_url and :info_url are context variables. (https://github.com/brittballard/html-pipeline/blob/mentions-starting-with-underscore/lib/html/pipeline/%40mention_filter.rb#L9-L13)

Care to give that implementation a go?

@brittballard
Copy link
Author

Ah, yes that looks very nice. Sure I'll resubmit. Thank you.

@brittballard brittballard force-pushed the mentions-starting-with-underscore branch 8 times, most recently from 3632c23 to c468f29 Compare October 6, 2014 18:49
@brittballard
Copy link
Author

@jch what do you think of this? I set it up to only allow for modification of the username to avoid confusion. Allowing someone to change the entire regex was problematic because the rest of the class depends on the presence of the "@", which makes sense to me.

@jch
Copy link
Contributor

jch commented Oct 6, 2014

Downside to this is that a new regex object is created everytime the filter
is run. I do like your idea of only specifying the username pattern so
callers don't have to worry about trailing white space or the leading @.
Maybe only create a fresh pattern if a username pattern was specified in
the context?

On Monday, October 6, 2014, Britt Ballard [email protected] wrote:

@jch https://github.com/jch what do you think of this?


Reply to this email directly or view it on GitHub
#157 (comment).

Jerry Cheung
GitHub https://github.com/jch

@brittballard
Copy link
Author

@jch that's a good point. Sure I'll look into taking that route.

@brittballard brittballard force-pushed the mentions-starting-with-underscore branch 2 times, most recently from 3b06874 to effa0fd Compare October 6, 2014 20:39
@brittballard
Copy link
Author

@jch what do you think of this solution?

@brittballard
Copy link
Author

Working on that bad test now.

@brittballard brittballard force-pushed the mentions-starting-with-underscore branch from effa0fd to b639cca Compare October 6, 2014 20:59
@brittballard brittballard changed the title @mention includes a mention_pattern method that can be overloaded @mention allow for custom regex to identify usernames. Oct 6, 2014
@brittballard brittballard force-pushed the mentions-starting-with-underscore branch from b639cca to 8e0915b Compare October 6, 2014 21:09
$ # end of line
)
/ix
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simple and clever solution. 👍

Are the tests passing for you? The Hash#new docs suggest that you're responsible for storing the value. I haven't tried running it yet though.

It is the block’s responsibility to store the value in the hash if required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test do currently pass. I read that as telling me I had to include hash[key] in the block (line 46). If there is a simpler or cleaner way I'm all for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@brittballard brittballard force-pushed the mentions-starting-with-underscore branch from 8e0915b to 9e2a96c Compare October 6, 2014 23:14
expression = HTML::Pipeline::MentionFilter::MentionPatterns[/test/]

assert_same expression, HTML::Pipeline::MentionFilter::MentionPatterns[/test/]
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems too tied to the implementation to me. It's testing the definition of Hash.new rather than actual behavior. I think we can do without it. I think you can roll this test into the one below, and assert that filtering with the default regex leads to a pattern_count of 1, and filtering again with a custom regex gives a pattern_count of 2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll make the change.

@jch
Copy link
Contributor

jch commented Oct 7, 2014

@brittballard it's coming together!

I noticed you were doing force pushes for the changes, which is fine if you prefer it. But I don't have any problems with having the intermediate commits either. Your call.

* This allows for easier customization of the usernam mention pattern regex
@brittballard brittballard force-pushed the mentions-starting-with-underscore branch from 9e2a96c to 57f6cce Compare October 7, 2014 19:39
@brittballard
Copy link
Author

@jch I have gotten into the dangerous habit of using --amend when I'm working on my own branches. It has bitten me a time or two, I probably need to get back to not doing it!

@jch
Copy link
Contributor

jch commented Oct 7, 2014

@brittballard I like using amend also, but limit myself to only commits that haven't been pushed up yet. git rebase -i is also nice for tidying up history before a public push.

@brittballard
Copy link
Author

That's a good policy.

@jch
Copy link
Contributor

jch commented Oct 7, 2014

Ready for review again, or were there other changes you wanted to make?

@brittballard
Copy link
Author

Ready for review, sir.

@jch jch added this to the 2.0 milestone Oct 7, 2014
@jch
Copy link
Contributor

jch commented Oct 7, 2014

👍 slated for 2.0 release

🍻

jch added a commit that referenced this pull request Oct 7, 2014
…rscore

@mention allow for custom regex to identify usernames.
@jch jch merged commit e921fba into gjtorikian:master Oct 7, 2014
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

Successfully merging this pull request may close these issues.

2 participants