Posted By

StrawMan on 08/20/10


Tagged

css ruby


Versions (?)

Simple Ruby Inline CSS Application Class


 / Published in: Ruby
 

For all the advanced personal mobile technology over here in Japan, most mobile phone carriers remain quirky, inconsistent and downright annoying in their handling of modern web technologies.

I use the following simple ruby CSS class to streamline the process of in-lining CSS declarations in dynamically generated markup, when designing sites geared towards the Japanese mobile market.

  1. ###########################################
  2. #Class: CSSdef - Sitewide CSS styling.
  3. ###########################################
  4. class CSSdef
  5.  
  6. #Public/instance variables.
  7. attr_accessor :body_css
  8. attr_accessor :width_100
  9. attr_accessor :center_css
  10. attr_accessor :left_css
  11. attr_accessor :right_css
  12. attr_accessor :whiteborder_css
  13. attr_accessor :underlinetxt_css
  14. attr_accessor :tinytinytxt_css
  15. attr_accessor :tinytxt_css
  16. attr_accessor :smalltxt_css
  17. attr_accessor :mediumtxt_css
  18. attr_accessor :orangetxt_css
  19. attr_accessor :boldorangetxt_css
  20. attr_accessor :boldwhitetxt_css
  21. attr_accessor :tinygreytxt_css
  22. attr_accessor :smallgreytxt_css
  23. attr_accessor :mediumgreytxt_css
  24. attr_accessor :defaultgreytxt_css
  25. attr_accessor :blueunderlinetxt_css
  26. attr_accessor :blue_css
  27. attr_accessor :purple_css
  28. attr_accessor :pink_css
  29. attr_accessor :orange_css
  30. attr_accessor :yellow_css
  31. attr_accessor :lightgrey_css
  32. attr_accessor :imglarge_css
  33. attr_accessor :darkred_css
  34. attr_accessor :hr_css
  35. attr_accessor :a_link
  36. attr_accessor :a_visited
  37. attr_accessor :a_hover
  38. attr_accessor :a_active
  39. attr_accessor :pinklink_css
  40. attr_accessor :bluelink_css
  41.  
  42. #Constructor.
  43. def initialize()
  44. #Structure.
  45. @body_css = "font-size: medium; background: #ffffff; width: 100%; color: #404040;"
  46. @width_100 = "width: 100%;"
  47. #Containers.
  48. @center_css = "width: 100%; text-align: center;"
  49. @left_css = "width: 100%; text-align: left;"
  50. @right_css = "width: 100%; text-align: right;"
  51. @whiteborder_css = "border-width: 1px; border-style:solid; border-color: #FFFFFF;"
  52. #Text.
  53. @tinytinytxt_css = "font-size: xx-small;"
  54. @tinytxt_css = "font-size: x-small;"
  55. @smalltxt_css = "font-size: small;"
  56. @mediumtxt_css = "font-size: medium;"
  57. @orangetxt_css = "color: #FFC000;"
  58. @boldorangetxt_css = "color: #FFC000; font-weight: bold; font-size: medium;"
  59. @boldwhitetxt_css = "color: #FFFFFF; font-weight: bold; font-size: medium;"
  60. @tinygreytxt_css = "color: #B2B2B2; font-size: x-small;"
  61. @smallgreytxt_css = "color: #B2B2B2; font-size: small;"
  62. @mediumgreytxt_css = "color: #B2B2B2; font-size: medium;"
  63. @underlinetxt_css = "text-decoration: underline;"
  64. @blueunderlinetxt_css = "border-bottom: 1px solid #00b0f0;"
  65. @defaultgreytxt_css = "color: #404040;"
  66. #Basic colors.
  67. @blue_css = "color: #558ed5;"
  68. @purple_css = "color: #7030a0;"
  69. @pink_css = "color: #ff0066;"
  70. @orange_css = "color: #ff6600;"
  71. @yellow_css = "color: #ffc000;"
  72. @lightgrey_css = "color: #d9d9d9;"
  73. @darkred_css = "color: #a60000;"
  74. #Horizontal ruler
  75. @hr_css = "color: #FFFFFF;"
  76. #Images.
  77. @imglarge_css = "width: 240px;"
  78. #Links.
  79. @pinklink_css = "color: #ff0066;"
  80. @bluelink_css = "color: #00b0f0;"
  81. @a_link = "font-size: medium; text-decoration: underline; color: #fff;"
  82. @a_visited = "font-size: medium; text-decoration: underline; color: #fff;"
  83. @a_hover = "font-size: medium; text-decoration: underline; color: #76C5E9;"
  84. @a_active = "font-size: medium; text-decoration: underline; color: #76C5E9;"
  85. end
  86.  
  87. ###########################################
  88. #Public methods.
  89. public()
  90. ###########################################
  91. #Method: printStyle().
  92. def printStyle(styledec_a, styledec_b = nil, styledec_c = nil)
  93. stylestring = "style="
  94. if(styledec_b)
  95. stylestring.concat("\"#{styledec_a} #{styledec_b}\"")
  96. elsif(styledec_c)
  97. stylestring.concat("\"#{styledec_a} #{styledec_b} #{styledec_c}\"")
  98. else
  99. stylestring.concat("\"#{styledec_a}\"")
  100. end
  101. end
  102. ###########################################
  103.  
  104. ###########################################
  105. #Private methods.
  106. private()
  107. ###########################################
  108.  
  109. ###########################################
  110.  
  111. ###########################################
  112. #Protected methods.
  113. protected()
  114. ###########################################
  115.  
  116. ###########################################
  117. end
  118. ###########################################

Report this snippet  

You need to login to post a comment.