use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
~69 users here now
The Haskell programming language community.
Daily news and info about all things Haskell related: practical stuff, theory, types, libraries, jobs, patches, releases, events and conferences and more...
Other community locations:
Compiling Mustache Templates (singpolyma.net)
submitted 2 years ago by singpolyma
[–]sfvisser 2 points3 points4 points 2 years ago (2 children)
Off topic, but I'm glad I have the readability function on my phone. This page is barely readable.
[–][deleted] 2 years ago* (1 child)
[–]yogsototh 1 point2 points3 points 2 years ago (13 children)
Thanks for that! I really love mustache, and I might try to integrate it to one of my yesod project.
Just a remark on the form:
For the love of all good on this Earth, could you change the background color of your blog post please? It is almost unreadable for me.
For other people like me, here is a link to an actually readable version of your article:
[–][deleted] 2 years ago (12 children)
[–]galvatron 2 points3 points4 points 2 years ago (8 children)
The orange background looks very busy to my eyes too and definitely makes it harder on the eyes than, say, a white background.
[–]singpolyma[S] 0 points1 point2 points 2 years ago* (6 children)
White backgrounds are super bright, which always hurts my eyes. This is why the orange in my background used to be darker, but that admittedly had problems. So I worked quite a bit to lighten it without putting it in so-bright-it-hurts like white or straight pumpkin orange.
Some people elsewhere have suggested a different foreground colour might work, but I haven't found anything other than black and near-black that even show up well on orange.
[–]the_starbase_kolob 1 point2 points3 points 2 years ago (0 children)
I find white backgrounds too bright sometimes as well. I use a green background in vim (#ddeedd) and like it quite a bit.
[–]onmach 0 points1 point2 points 2 years ago (4 children)
Trying to make a dark background with black text is never going to work. Either make the background dark and the text white, which people will complain about, but a lot less, or do it the normal way with a light background and black text.
[–]singpolyma[S] 0 points1 point2 points 2 years ago* (3 children)
The colour at the time of posting, and the colour now, are both quite light.
Edit: I've now lightened it even more.
[–]Tekmo 1 point2 points3 points 2 years ago (2 children)
The problem is that it is red, which doesn't make a good background color. If you change it to a more neutral color like grey (and still lighten it a bit more) it would be easier to read.
[–]winterkoninkje 0 points1 point2 points 2 years ago (1 child)
Indeed. After black and white, red is the most contrastive color. Thus, it is best avoided in backgrounds. Use black. Use white. Use grey. Use green. Use blue. Use purple. Just stop already with the red/orange. The only way you're going to get that to be anywhere near legible is if you head straight to the light salmon or the carnation pink.
If you absolutely must have a hot tone: this is a light color. This is a light color. What you have up there now is not "quite light".
[–]singpolyma[S] 0 points1 point2 points 2 years ago (0 children)
What I have up there now is peach, but ok. It seems I've reached a point where I'm not happy with my colour and people don't like it any better. Also, I finally understand that it's not a contrast/legibility issue, but a matter of taste, which makes more sense.
If I get some time I may look at doing a complete redesign. It's been awhile :)
[–]singpolyma[S] 0 points1 point2 points 2 years ago* (0 children)
Ok, I've changed the background colour again. Let me know if that's working better for you :)
[–][deleted] 2 years ago (2 children)
[–][deleted] 2 years ago (1 child)
[–]donri 0 points1 point2 points 2 years ago (19 children)
Why not wl-pprint-text?
[–]singpolyma[S] 0 points1 point2 points 2 years ago (18 children)
I did see that package, and I could use it. In this case, I'm just constructing a Builder, and the Builder fromText just unpacks anyway IIRC. Thoughts?
[–]donri 1 point2 points3 points 2 years ago (17 children)
Not sure what you're saying. I'm suggesting you make it act on text everywhere.
[–]singpolyma[S] 0 points1 point2 points 2 years ago (16 children)
Like, my return value is a Blaze Builder. I can construct a Blaze Builder from Text, but it just unpacks it anyway.
That said, I looked at the package again and it looks like it's probably better supported and such anyway, so that may be an advantage by itself.
[–]donri 0 points1 point2 points 2 years ago (15 children)
Ah you're right about blaze-builder's fromText. Weird. But why not use the Text builder instead? I'm not sure why people use bytestrings for things that are naturally text. I guess it is faster if you're rendering to exactly the one encoding you decided to default to?
[–]singpolyma[S] 0 points1 point2 points 2 years ago (2 children)
Hmm... I was using the Blaze Builder because I'm using this with WAI, but I should look into the Text Builder. Thanks :)
[–]donri 1 point2 points3 points 2 years ago (1 child)
wl-pprint-text uses a text builder internally, maybe we could have it exposed?
That would be useful.
[–]singpolyma[S] 0 points1 point2 points 2 years ago (11 children)
I've pushed up a port to use wl-pprint-text to a branch at https://github.com/singpolyma/mustache2hs/tree/text, but in tests it consistantly runs a tad slower. Any ideas?
[–]donri 0 points1 point2 points 2 years ago (10 children)
You seem to be doing a lot of Builder.fromString and T.pack. If you use OverloadedStrings you might benefit from the rewrite rules in the text package, which convert from string literals to Text at compile-time instead of runtime. Also, generating code like this all over the place:
Builder.fromLazyText $ displayT $ renderPretty 0.4 80 $ pretty
is probably suggestive of that you shouldn't be using a pprint library at all. If all you need is basically "Show without quotes for strings and text" it might be better to just write that type class yourself after all. Might also allow you to avoid some orphan instances; duno if you're running into those yet.
[–]singpolyma[S] 0 points1 point2 points 2 years ago* (9 children)
Show without quotes for String and Text, and with empty for Nothing and just the x for Just x, basically "formatting for display". I was pointed at these libraries as a way of doing that, and the default instances matched my expectations.
Interesting that the conversion from string literal to Text can happen at compile time with OverloadedStrings. I had always assumed that since it uses IsString it was still doing the conversion at runtime. Or else I would think it could also do it at compile time witthout OverloadedStrings, but maybe the extension has some extra magic beyond just inserting fromString everywhere?
[–]singpolyma[S] 0 points1 point2 points 2 years ago (3 children)
Switching to OverloadedStrings and using fromText had no noticible effect at all on performance. Using fromLazyText actually made it slower.
I'll keep playing with it :)
Profiling seems to show that basically all the time is spent in:
TL.putStr . TL.toLazyText
Which of course is not suprising, since all the work is basically deferred until the build step. Maybe the Text builder is just slower than Blaze?
[–]donri 0 points1 point2 points 2 years ago (4 children)
While pretty printing libraries do what you want, they also do a whole lot more, and the intended usage is that you print everything as one Doc and render that once, not that you render small things individually here and there. I use it to render JS and CSS syntax trees into actual JS and CSS with pretty indentation and alignment and such. You could do this instead of using a Builder for your Mustache thing, but it wouldn't really give you anything since Mustache is text templating without structure.
The text package uses GHC rewrite rules; see relevant commit. This will probably not be a win if you use blaze-builder though, so mostly relevant if you switch it to a text builder.
Yeah, those rewrite rules look like they should work even without OverloadedStrings, which is probably why the performance didn't really change when I switched.
Hmm, I see what you mean about pretty printing libraries being heavier than I need. I wonder if I'd get another noticible speed boost just doing the conversion myself. Worth thinking about.
REDDIT and the ALIEN Logo are registered trademarks of reddit inc.
π Rendered by PID 21079 on app-64 at 2015-03-03 18:52:31.209064+00:00 running 697792e country code: US.