Module: Cyberweb::Colours
- Defined in:
- lib/cyberweb/colours/colours.rb
Overview
Cyberweb::Colours
Class Method Summary collapse
-
.all_colours ⇒ Object
# === Cyberweb::Colours.all_colours.
-
.return_random_colour ⇒ Object
# === Cyberweb::Colours.return_random_colour.
-
.sanitize_for_colours(i = '') ⇒ Object
# === Cyberweb::Colours.sanitize_for_colours.
-
.show_all_colours(also_display_them_in_colours = false) ⇒ Object
# === Cyberweb::Colours.show_all_colours.
-
.show_html_colour_chart(use_this_css_style = 'margin-left: 2.5em; margin-right: 2.5em;'\ 'padding-left: 1.5em; padding-right: 1.5em', width_of_the_box = '75px', height_of_the_box = '35px') ⇒ Object
# === Cyberweb::Colours.show_html_colour_chart.
Instance Method Summary collapse
-
#sanitize_for_colours(i = '') ⇒ Object
# === sanitize_for_colours ========================================================================= #.
Class Method Details
.all_colours ⇒ Object
#
Cyberweb::Colours.all_colours
This method will return all available colours. We make use of project HtmlColours for this.
#
103 104 105 |
# File 'lib/cyberweb/colours/colours.rb', line 103 def self.all_colours return ::Colours.html_colours end |
.return_random_colour ⇒ Object
#
Cyberweb::Colours.return_random_colour
This method will return a String such as “mediumslateblue”.
#
112 113 114 |
# File 'lib/cyberweb/colours/colours.rb', line 112 def self.return_random_colour return Cyberweb::Colours.all_colours.sample end |
.sanitize_for_colours(i = '') ⇒ Object
#
Cyberweb::Colours.sanitize_for_colours
This method can be used to scan a string for the keyword RAND or other similar keywords. If such a keyword is found, it will be replaced with the proper colour(s). RANDOM_COLOUR would thus become a real, random colour.
Note that this method will also check for the keyword BACKGROUND. This is done to allow the user to use shortcut macros.
This method here is called specifically, for instance, from the method return_css_style().
#
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cyberweb/colours/colours.rb', line 29 def self.sanitize_for_colours( i = '' ) i = i.to_s.dup # Dup so that we don't work on a frozen string. # ======================================================================= # # === RANDOM_COLOUR # ======================================================================= # if i.include? 'RANDOM_COLOUR' i.gsub!(/RANDOM_COLOUR/, return_random_colour) end # ======================================================================= # # Handle macro entries for BACKGROUND next: # # background: url(images/menu7.gif) # BACKGROUND: BG_COLOURBAR_LIGHT.jpg # # ======================================================================= # if i.include? 'BACKGROUND' i.gsub!(/BACKGROUND: (\w+\.\w+)/, 'background: url(../../../../../images/wallpapers/\1); background-repeat: no-repeat;') end i.gsub!(/RBORDER1/, return_random_border ) if i.include? 'RBORDER1' i.gsub!(/RBORDER/, return_random_border ) if i.include? 'RBORDER1' # ======================================================================= # # If the following input includes at least the substring 'RCOL'. # ======================================================================= # if i.include? 'RCOL' i.gsub!(/RCOLOUR/, return_random_colour ) i.gsub!(/RCOL/, return_random_colour ) end # ======================================================================= # # Cut off UPCASED "PX". From this point no "PX" substring is possible # within the given input String. This may fail for images that have PX # as part of their name though, hence why this check is a bit # more complicated. # ======================================================================= # if i.include? 'PX' unless i.include?('.png') or i.include?('.jpg') i.gsub!(/PX/,'') end end if i.include? 'RAND' i.gsub!(/RANDOM/,'RAND') # exchange RANDOM with RAND i.gsub!(/BORDER_RAND/, 'RAND_BORDER') # want proper names i.gsub!(/RAND/, return_random_colour ) # ======================================================================= # # From this point forward, we invoke the method return_random_colour() # RAND_BORDER_1 means "create a random border here" with 1 px # ======================================================================= # i.gsub!(/RAND_BORDER_(.+)/, return_random_border('\\1') ) # ======================================================================= # # Create: border-left: 1 px RANDOM_COLOUR # ======================================================================= # i.gsub!(/BORD_LEFT_RAND_(.+)/, return_random_border('\\1') ) i.gsub!(/RAND_BORD_(.+)/, return_random_border('\\1') ) i.gsub!(/RAND_COLOUR/, return_random_colour ) elsif i.include? 'BORD' # ======================================================================= # # As above but with shorter BORD_ notation. # ======================================================================= # i.gsub!(/BORD_(.+)PX/, 'border: \\1px '+ARRAY_CSS_BORDER_STYLES.sample(1).first+ ' '+return_random_colour+';') end return i end |
.show_all_colours(also_display_them_in_colours = false) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/cyberweb/colours/colours.rb', line 126 def self.show_all_colours( also_display_them_in_colours = false ) if also_display_them_in_colours == :super_colourize also_display_them_in_colours = true end if also_display_them_in_colours all_colours.each { |colour| e colour,'','',"color: #{colour}" } else all_colours.each { |colour| e colour } end end |
.show_html_colour_chart(use_this_css_style = 'margin-left: 2.5em; margin-right: 2.5em;'\ 'padding-left: 1.5em; padding-right: 1.5em', width_of_the_box = '75px', height_of_the_box = '35px') ⇒ Object
#
Cyberweb::Colours.show_html_colour_chart
Take note that this method is significantly more sophisticated than the older method called Cyberweb.colour_chart; it also has a slightly different use case. The method here is ready-for-use, that is, for display in a webpage.
#
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/cyberweb/colours/colours.rb', line 147 def self.show_html_colour_chart( use_this_css_style = 'margin-left: 2.5em; margin-right: 2.5em;'\ 'padding-left: 1.5em; padding-right: 1.5em', width_of_the_box = '75px', height_of_the_box = '35px' ) p('','',use_this_css_style){ ee '<table style="margin-left: 0.75em; margin-right: 0.75em;">' Cyberweb::Colours.all_html_colours.each {|this_html_colour| ee '<tr>' ee '<td>' ee '<div class="marl2em bblack1 pad4px mar2px" style="width:'+ width_of_the_box+'; height:'+height_of_the_box+'; background-color: '+this_html_colour+'">' ee '</div>' ee '</td>' ee '<td>' ee '<b>'+this_html_colour+'</b>' ee '</td>' ee '<td><b>Hex value</b>: <b>' ee ::Colours.html_colour_to_hex_value(this_html_colour) ee '</b></td>' ee '<td>' # ===================================================================== # # Next we will also show the RGB value. # ===================================================================== # ee '<b>RGB value</b>: <b>'+ ::Colours.html_colour_to_rgb_value(this_html_colour). tr(';',',')+' </b>' ee '</td>' ee '</tr>' ee "\n" } ctable } end |
Instance Method Details
#sanitize_for_colours(i = '') ⇒ Object
#
sanitize_for_colours
#
187 188 189 |
# File 'lib/cyberweb/colours/colours.rb', line 187 def sanitize_for_colours(i = '') ::Cyberweb.sanitize_for_colours(i) end |