chroma icon indicating copy to clipboard operation
chroma copied to clipboard

export to HTML palette

Open Trevoke opened this issue 9 years ago • 6 comments

It would be nice, for those of us who are hex-impaired, to be able to see it in a browser somehow. Maybe just export to HTML string for starters?

Trevoke avatar Jan 15 '15 01:01 Trevoke

Hi @Trevoke. I like this idea, but I think baked in HTML serialization is out of the scope of this gem. However, I do like the idea of supporting custom serialization similar to supporting custom palettes, so I would be comfortable with something like:

# call define_color_serializer with name and block that is instance_eval'd by the color
Chroma.define_color_serializer :to_html do
  %{<span class="color-swatch" style="background-color: #{to_hex}"></span>}
end

'red'.paint.to_html #=> <span class="color-swatch" style="background-color: #ff0000"></span>

Is that output kind of what you were referring to?

jfairbank avatar Jan 16 '15 02:01 jfairbank

I admit that, being a web developer, I just can't imagine any context for hex colors beyond CSS, which is why I thought it would be a wonderful addition to the gem.

I imagined something like a pre-baked, HTML+CSS, version of a palette like this one (first available on the site when I went to it): http://www.colourlovers.com/palette/3621455/fewer .

Beyond this, my suggestion is to solve for one use case first, and then make it more generic when more use cases come up.

And finally, I understand that HTML serialization might deform and denature the gem, so I do understand if you leave that out. Maybe I'll just have to build a wrapper gem :D

Trevoke avatar Jan 16 '15 13:01 Trevoke

Hey, @Trevoke. Sorry for the absence. I'm still not sure that I'm sold on this. It's a neat idea, but the main issue I see with serializing to HTML/CSS is the assumptions I need to make about what that looks like versus what others might want.

What is it you hope to achieve with this functionality? Do you want to just preview the colors and custom palettes? Or do you actually want some type of HTML/CSS output that you use directly in an app?

I have some ideas for either approach.

jfairbank avatar Feb 06 '15 05:02 jfairbank

The main purpose I hope to achieve is to view the colors.

Trevoke avatar Feb 06 '15 12:02 Trevoke

OK, so after thinking about this, I belive I'm good with this idea. It could be helpful to visualize the colors, especially for custom palettes you can define (in addition to the default palettes).

What I envision is a rack server for this that you can run locally to play with the colors. A command line binary could work as well, but the server would have the benefit of allowing you to type in the base color you want to try out instead of constantly rerunning a binary.

Does that sound like something you're looking for?

jfairbank avatar Feb 13 '15 02:02 jfairbank

That sounds pretty awesome, yes!

Trevoke avatar Feb 13 '15 13:02 Trevoke