jasonlong / geo_pattern

Create beautiful generative geometric background images from a string.
http://jasonlong.github.io/geo_pattern/
MIT License
1.25k stars 88 forks source link

[Proposal] Add Pattern-class #44

Closed maxmeyer closed 9 years ago

maxmeyer commented 9 years ago

Looking here and here it seems to be a little bit weird to speak of a pattern pattern = [...]. Furthermore we`ve now some problems to write good tests.

So I suggest to add a Pattern-class which also add some support for introspection like

pattern.pattern? XesPattern
# => true/false
pattern.background_color? '#0a0a0a'
# => true/false
pattern.color? '#0a0a0a'
# => true/false

This class would be generated by the PatternGenerator.

module GeoPattern
  def self.generate(string=Time.now, opts={})
  GeoPattern::PatternGenerator.new.generate(string.to_s, opts)
  # => Pattern
  end
end

It would also the responsibility of that class to output the pattern in the correct format (link)

def to_svg
  svg.to_s
end
alias_method :to_s, :to_svg
alias_method :svg_string, :to_svg

def to_base64
  Base64.strict_encode64(svg_string)
end
alias_method :base64_string, :to_base64

def to_data_uri
  "url(data:image/svg+xml;base64,#{base64_string});"
end
alias_method :uri_image, :to_data_uri

@jasonlong @ttaylorr What do you think?

ttaylorr commented 9 years ago

:+1: from me.

On Sun, Jan 25, 2015 at 2:02 AM, maxmeyer notifications@github.com wrote:

Looking here https://github.com/jasonlong/geo_pattern/blob/master/lib/geo_pattern.rb#L32 and here https://github.com/jasonlong/geo_pattern/blame/master/README.md#L37 it seems to be a little bit weird to speak of a pattern pattern = [...]. Furthermore we`ve now some problems to write good tests.

So I suggest to add a Pattern-class which also add some support for introspection like

pattern.pattern? XesPattern

=> true/false

pattern.background_color? '#0a0a0a'

=> true/false

pattern.color? '#0a0a0a'

=> true/false

It would also the responsibility of that class to output the pattern in the correct format (link https://github.com/jasonlong/geo_pattern/blob/master/lib/geo_pattern/pattern_generator.rb#L44 )

def to_svg svg.to_sendalias_method :to_s, :to_svgalias_method :svg_string, :to_svg def to_base64 Base64.strict_encode64(svg_string)endalias_method :base64_string, :to_base64 def to_data_uri "url(data:image/svg+xml;base64,#{base64_string});"endalias_method :uri_image, :to_data_uri

@jasonlong https://github.com/jasonlong @ttaylorr https://github.com/ttaylorr What do you think?

— Reply to this email directly or view it on GitHub https://github.com/jasonlong/geo_pattern/issues/44.

Thanks, Taylor Blau

ttaylorr.com

jasonlong commented 9 years ago

Seems ok to me. If I understand right, the syntax for the end user would remain the same?

maxmeyer commented 9 years ago

Yes. I would just add some deprecation warnings for the "old" api.

maxmeyer commented 9 years ago

Should I open a new PR or should I add this functinality in #40?

maxmeyer commented 9 years ago

I would prefer to open a new one as #40 contains quite a lot changes already.

maxmeyer commented 9 years ago

Fixed by #46