gin icon indicating copy to clipboard operation
gin copied to clipboard

Adds a new StringHTML Render method

Open afiune opened this issue 6 years ago • 12 comments

This new StringHTML() method will allow users to render HTML without the need of an actual file on disk.

Example:

r.GET("/saludos", func(c *gin.Context) {
	c.StringHTML(200, "<html><body>Hola amigo!</body></html>")
})

Signed-off-by: Salim Afiune [email protected]

afiune avatar Jul 27 '17 19:07 afiune

Codecov Report

Merging #1043 into master will increase coverage by <.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1043      +/-   ##
==========================================
+ Coverage   96.66%   96.67%   +<.01%     
==========================================
  Files          16       16              
  Lines        1711     1713       +2     
==========================================
+ Hits         1654     1656       +2     
  Misses         49       49              
  Partials        8        8
Impacted Files Coverage Δ
context.go 96.63% <100%> (+0.01%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 81007d2...a6d38b2. Read the comment docs.

codecov[bot] avatar Jul 27 '17 20:07 codecov[bot]

I added tests so that the coverage doesn't decrease. Now it should be in the same percentage or even more:

coverage: 97.0% of statements

tenor-162916584

afiune avatar Jul 27 '17 20:07 afiune

@appleboy I'll be interested in having your feedback about this PR. 👍

afiune avatar Jul 28 '17 18:07 afiune

@appleboy Thanks for the review! 👍 I have updated the assert's to match the right parameter order. Since I took some of the tests as example I thought it would be a good idea to correct them. Finally just added a quick snipped of documentation in the README. Cheers! 🍻

afiune avatar Jul 31 '17 14:07 afiune

I just updated my branch to be in sync with master 😄

afiune avatar Aug 01 '17 18:08 afiune

there was some issue with that same method two years ago here ( https://github.com/gin-gonic/gin/issues/197#issuecomment-102701461 ), the pr is ok, just need to clarify with manu why he didn't wanted that...

sorry for the delay @afiune

javierprovecho avatar Aug 02 '17 22:08 javierprovecho

@javierprovecho Thank you for looking out for this change, much appreciated. I read the comment and It make sense to do that if there is not proper method to do it (natively). I just feel it is valuable to have it available and also documented since some micro-services wont be carrying HTML files and instead automatically generating it, so this would be very useful for users that are planning to do so.

I'll be waiting to hear from Manu. :v:

afiune avatar Aug 03 '17 14:08 afiune

@javierprovecho @appleboy Hello! 👋 I was just passing by and remembered this PR, I have rebased from master and updated anything that needs to be updated!

Is this something we still want to merge?

afiune avatar Sep 03 '19 19:09 afiune

+1 need this feature

ghost avatar Sep 07 '19 01:09 ghost

Codecov Report

Merging #1043 (152b648) into master (7742ff5) will increase coverage by 0.13%. The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1043      +/-   ##
==========================================
+ Coverage   98.48%   98.61%   +0.13%     
==========================================
  Files          41       40       -1     
  Lines        1974     2235     +261     
==========================================
+ Hits         1944     2204     +260     
- Misses         17       18       +1     
  Partials       13       13              
Impacted Files Coverage Δ
render/text.go 89.47% <81.81%> (-10.53%) :arrow_down:
context.go 98.45% <100.00%> (+0.94%) :arrow_up:
mode.go 90.90% <0.00%> (-9.10%) :arrow_down:
fs.go 100.00% <0.00%> (ø)
auth.go 100.00% <0.00%> (ø)
path.go 100.00% <0.00%> (ø)
tree.go 100.00% <0.00%> (ø)
errors.go 100.00% <0.00%> (ø)
logger.go 100.00% <0.00%> (ø)
deprecated.go 100.00% <0.00%> (ø)
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7742ff5...b1703a2. Read the comment docs.

codecov[bot] avatar Nov 26 '20 21:11 codecov[bot]

Hi, Is this function going to be merged anytime soon? Or shall I try to make it work?

HarishTeens avatar Oct 13 '21 17:10 HarishTeens

It has been a long time, @appleboy @javierprovecho @manucorporat - I am still interested in merging this PR, wondering if anyone is available for a quick review. 👍🏽

afiune avatar Jul 05 '22 21:07 afiune