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
distance_of_time_in_words returns a string instead of text element #781
Conversation
I think before merging this in wed also want to change a bunch of the other helpers methods that write directly to the IO. Otherwise some will work differently than others. Stuff like pluralize https://github.com/luckyframework/lucky/blob/master/src/lucky/page_helpers/text_helpers.cr Some use raw so it doesn’t make sense to convert. Those should be documented that they write directly to IO though and should probably use a Nil return type so people don’t try to use them |
Yeah, makes sense. I'll do that in a bit 👍 |
Nice branch name 😃 |
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
### Changes since v0.13 | |||
|
|||
- Change `Lucky::BaseApp` to `Lucky::BaseAppServer` | |||
- `time_ago_in_words` returns a `String` instead of an `text` element (IO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.14 has already been released, so this would more likely go under ### Changes since v0.14
. However, with that said, maybe all changelog changes can just go in a single commit? Kind of a pain to update all at once, but it helps to know what docs will need to be updated and such..
The goal is to make these easier to use inside other tags. The problem was that these would all output to the IO, so if you tried to use these in an element, it would print out the whole page HTML.
cb05ee0
to
f082a0f
Compare
I made some progress on this. However, I'm not sure how to approach require "./src/lucky"
require "./spec/support/context_helper"
include ContextHelper
class TextHelperTestPage
include Lucky::HTMLPage
def render
end
end
view = TextHelperTestPage.new(build_context)
view.link "#" do
text = view.truncate("Here is a long test and I need a continue to read link", length: 27) do
view.span "Continue"
end.to_s
view.text text
end.to_s This returns some extra HTML because it's grabbing the existing HTML in the truncate method. I'd love an assist. |
I think that is a pretty tricky edge case. Maybe for now we make the block version a different method. Like raw_truncate or something. What do you think? |
Yeah I like that. There's a private method called |
4e1857f
to
3b32d13
Compare
Cool, should be ready to go unless you want me to move the changelog stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 small things actually :D then ready to go!
# outputs: | ||
# ```html | ||
# You're such a <strong>nice</strong> and <strong>attractive</strong> person. | ||
# ``` | ||
def highlight(text : String, phrases : Array(String | Regex), highlighter : Proc | String = "<mark>\\1</mark>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, could you make the return types : Nil
for any of the methods that are meant to write HTML directly to the IO so that it won't ever accidentally be used as a String
? Might also be worth adding a note like: This method writes HTML directly to the page. It does not return a String
or something like that. Thoughts?
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
### Changes since v0.13 | |||
|
|||
- Change `Lucky::BaseApp` to `Lucky::BaseAppServer` | |||
- Many text helpers now return a `String` instead of appending to the view (`cycle`, `excerpt`, `highlight`, `pluralize`, `time_ago_in_words`, `to_sentence`, `word_wrap`) [#781](https://github.com/luckyframework/lucky/pull/781) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth putting in bold **Breaking change** - Many text...
since this will definitely break stuff using it
This change also made the tests have to change since we can no longer grab the output of the text helper to a string and then compare it with another string.
@paulcsmith done in 537ee85 |
Perfect! Thank you |
Purpose
closes #780
Description
Returning a text element (which uses the
IO
class) can cause weird bugs, like the entire HTML source of the page being printed out into the page. This alters thedistance_of_time_in_words
method to return a string instead which can be inserted into atext
element, as an attribute of a different element, or even outside of a view entirely!Checklist
crystal tool format spec src
./script/setup
./script/test