Method: Styles.define

Defined in:
lib/xiki/styles.rb

.define(name, options) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/xiki/styles.rb', line 113

def self.define name, options

  return if ! $el

  self.exand_colors options, [:bg, :fg]

  code = "(set-face-attribute (make-face '#{name.to_s.gsub("_", "-")}) nil\n"
  code << "  :background \"##{options[:bg]}\"\n" if options[:bg]
  code << "  :foreground \"##{options[:fg]}\"\n" if options[:fg]
  code << "  :family \"#{options[:face]}\"\n" if options[:face]

  if options[:size]
    size = options[:size]
    size = self.size(size.to_i) if size.is_a? String   # If a string, convert to relative size
    code << "  :height #{size}\n"
  end

  code += options[:strike] ? "  :strike-through t\n" : "  :strike-through nil\n" if options.has_key?(:strike)

  code += options[:underline] ? "  :underline t\n" : "  :underline nil\n" if options.has_key?(:underline)
  code += options[:overline] ? "  :overline t\n" : "  :overline nil\n" if options.has_key?(:overline)

  code += options[:bold] ? "  :weight 'bold\n" : "  :weight 'normal\n" if options.has_key?(:bold)
  if options[:border]
    border = options[:border]
    code <<
      if border.class == Symbol
        ":box nil\n"
      elsif border.class == String
        ":box '(:line-width 1 :color \"##{border}\")\n"
      elsif border.class == Array
        ":box '(:line-width #{border[1]} :color \"##{border[0]}\" :style #{border[2] || 'nil'})\n"
      end
  end
  code << "  )"

  $el.el4r_lisp_eval code
end