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

Added CSS style and value modules to work with blaze-markup css branch #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikehat
Copy link

@mikehat mikehat commented May 30, 2015

Note: This branch accompanies the proposed css branch in blaze-markup. For now, you'll have to clone both repositories and merge the src/ directories if you want to test any of this. In other words, cabal build won't work unless the sources in my css branch of blaze-markup are in the src/ directory. But see the postscript below.

Along with some [slightly related] speed improvements, I proposed some minor changes in the conceptual model of an HTML element. I believe that all of these changes belong in either the blaze-html package or even in a separate blaze-css package altogether. Ideally, a Blaze syntax for CSS styles and classes would be part of a transformer stack on top of HTML and Markup layers. Maybe I'm just not good enough at this, but I really couldn't pull it off. I had to modify Internal.hs to get what I wanted.

An aside: In my humble opinion, the abstract model of elements in an HTML document would treat CSS styles and classes as equal in stature to HMTL attributes. The fact that both are transmitted as attribute values doesn't change the actual model. In practical terms, in an HTML document, a font-family might have been implemented as an attribute if something CSS-ish had been rolled into the HTML standard at the beginning.

The problem: I found myself loathing the

H.td ! A.style (compose_style_value $ the_font : [borderLeftStyle Solid, backgroundColor Silver])

that covered my sugary Blaze code like a rash. Yes, I know what a stylesheet is, but there is still a reason for the style attribute. Abusing A.class_ was prettier only by a small margin, and the stylesheet has to react to every whim found in the Haskell code. The root problem is that attribute value builders for style and class attributes are painful and ugly. I tried in vain to roll my own operators that worked well with (!) until I decided to just promote styles and classes to the same rank as attribute.

Now I get to write like this:

H.div ! S.position Absolute ! S.borderStyle Solid ! S.borderColor Black $
    H.span ! A.id "the-span" ! bold ! italic ! H.cssClass "class"

I understand that adding CSS functionality is a departure from the initial goal of producing markup with as little overhead as possible. But if the goal includes syntactic beauty, ease of use and raw speed - I think this has all of the above.

There's still work to do on non-String builders for Value.

Lastly, maybe someone could eventually work this CSS stuff into the BlazeFromHtml code. Probably not me.


P.S. For the authors: I'll set up a working copy of all the sources in blaze-builder, blaze-markup and blaze-html in a single repository to make it easier to see all of this together. I'm sure you have this already. But unless you're using a GIT_DIR trick or something to divide it all into multiple packages, it may be extra work for you to pull my work from multiple repositories. I'll put it at mikehat/blaze-all.

@mikehat
Copy link
Author

mikehat commented Jun 14, 2015

This is also available as a separate package called blaze-css. That package, as separate from blaze-html, is probably the way to go. The README there has some ideas for future directions...

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.

1 participant