Class: YardTheme

Inherits:
Object
  • Object
show all
Includes:
GladeGUI, YardThemeDefaults
Defined in:
lib/YardTheme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from YardThemeDefaults

#defaults, #maps, #prune

Constructor Details

#initializeYardTheme

Returns a new instance of YardTheme.



8
9
10
# File 'lib/YardTheme.rb', line 8

def initialize()
  defaults
end

Instance Attribute Details

#cssObject

Returns the value of attribute css.



6
7
8
# File 'lib/YardTheme.rb', line 6

def css
  @css
end

Instance Method Details

#before_showObject



12
13
14
15
16
17
18
19
# File 'lib/YardTheme.rb', line 12

def before_show
  theme = File.basename(@vr_yaml_file, ".*")
  if theme == "default"
    alert "The default theme can't be edited.  Make a clone of it, and edit the clone.", 
          parent: self, width: 300
  end
  @builder[:headline].label = "<big>Theme:  #{theme} </big>"
end

#buttonClone__clicked(*a) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/YardTheme.rb', line 47

def buttonClone__clicked(*a)
  clone = alert("This will make a clone of this theme.  " +
    "Enter the name of the new theme without any extension (only letters and underscores).",
    headline: "Clone Theme",
    data: "",
    width: 350,
    parent: self)
  alert clone
  if clone.is_a? String and clone != "default" and clone != ""
    # todo lowercase, strip, replace everything except letters, numbers and underscores.
    path = File.join(Dir.home, "my_yard", "themes", clone + ".yaml")
    if File.exists?(path)
      alert "The file, <b>#{clone}</b> already exists.", parent: self
    else
      get_glade_variables
      VR::save_yaml(self, path)
      @builder[:headline].label = "Theme:  #{clone}"
    end
  else
    
  end 
end

#export_to(file) ⇒ Object



21
22
23
# File 'lib/YardTheme.rb', line 21

def export_to(file)
  File.open(file, "w") { |f| f.puts to_css }
end

#import_google_fontsObject



37
38
39
40
41
42
43
44
45
# File 'lib/YardTheme.rb', line 37

def import_google_fonts()
  lines = []
  ["h1", "h2", "h3", "#toc", ".object_link", "#main p"].each do |tag|
    font = @css["#{tag} {font-family}"] 
    weight = @css["#{tag} {font-weight}"].strip == "" ? "" : ":" + @css["#{tag} {font-weight}"]
    lines << "@import url('https://fonts.googleapis.com/css?family=#{font.gsub(' ', '+')}#{weight}');\n"
  end
  return lines.uniq!.join
end

#save_stateObject



75
76
77
78
# File 'lib/YardTheme.rb', line 75

def save_state
  get_glade_variables
  VR::save_yaml(self)
end

#to_cssObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/YardTheme.rb', line 25

def to_css
  maps()
  out = import_google_fonts()
  @css.each do |key, val|
    if val.strip != "" # and val != $default_theme.css[key]
      val = "'#{val}'" if key.include?("{font-family}") # quotes around font names
      out = out + key.gsub("}", ": #{val};" ) + "}\n"
    end
  end
  return out + "#search { position: static; } .fixed_header { position: static; height: auto;} #full_list {margin-top: 0px;}"
end

#window1__destroy(*a) ⇒ Object



70
71
72
73
# File 'lib/YardTheme.rb', line 70

def window1__destroy(*a)
  save_state if File.exist?(@vr_yaml_file) # maybe deleted
  super
end