Class: MyYard

Inherits:
Object
  • Object
show all
Includes:
GladeGUI
Defined in:
lib/MyYard.rb

Instance Method Summary collapse

Constructor Details

#initializeMyYard

Returns a new instance of MyYard.



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

def initialize()
  defaults
end

Instance Method Details

#before_showObject



35
36
37
38
# File 'lib/MyYard.rb', line 35

def before_show()
  fill_combo_boxes
  set_glade_variables
end

#buttonCopy__clicked(*args) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/MyYard.rb', line 118

def buttonCopy__clicked(*args)
  copy = alert("Enter name for your new theme:  ", data: "my_theme", headline: "Create New Theme")
  if copy.is_a? String and copy != "" and copy != "default"
    current_theme = File.join(@theme_root, @theme + ".yaml")
    new_theme = File.join(@theme_root, copy + ".yaml")
    FileUtils.cp current_theme, new_theme
    fill_themes
    @theme = copy
    set_glade_variables # select new theme
    save_state
  end  
end

#buttonDeleteProject__clicked(*a) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/MyYard.rb', line 154

def buttonDeleteProject__clicked(*a)
  if alert("This will delete this project:\n<b>#{@project_root}</b>\nDo you want to continue?",
      button_yes: "Delete",
      button_no: "Cancel",
      parent: self,
      headline: "Delete This Project?")
    @env.projects.delete(@project_root)
    VR::save_yaml(@env)
    FileUtils.rm_rf File.join(@project_root, ".yardoc", "my_yard.yaml")
    $open_project = @env.projects.empty? ? :exit : $env.projects[0]
    @builder[:window1].destroy
  end
end

#buttonDeleteTheme__clicked(*a) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/MyYard.rb', line 168

def buttonDeleteTheme__clicked(*a)
  get_glade_variables
  return if @theme == "default"
  if alert "Delete theme: <b>#{@theme}</b>?", parent:self, button_no: "Cancel"
    theme = File.join(@theme_root, "#{@theme}.yaml")
    File.delete(theme)
    @theme = "default"
    fill_themes
    set_glade_variables
  end 
end

#buttonEditTheme__clicked(*a) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/MyYard.rb', line 131

def buttonEditTheme__clicked(*a)
  if @theme == "default"
    alert("You can't edit the default theme.  Make a copy of it, and edit the copy.")
    return
  end
  file = File.join(@theme_root, @theme + ".yaml")
  win = VR::load_yaml(YardTheme, file)
  win.show_glade(self)     
end

#buttonGenerate__clicked(*args) ⇒ Object



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
# File 'lib/MyYard.rb', line 40

def buttonGenerate__clicked(*args)
  save_state
  args = []
  @files.split.each { |glob| args << glob }
  if @extra_files.strip != ""
    args << "--files"
    args << @extra_files
  end
  args << "--private" if @include_private 
  args << "--no-public" if !@include_public 
  args << "--protected" if @include_protected
  args << "--no-private" if !@include_private_tag  
  args << "--output-dir"
  args << @output_dir 
  args << "--title" 
  args << @title 
  if @exclude.strip != ""
    args << "--exclude"
    args << @exclude 
  end
  if @main.strip != ""
    args << "--main"
    args << @main
  end
  if @template != "default"
    args << "--template-path"
    args << @template_root
    args << "--template"
    args << @template
  end
  if @export_db and @export_db_path.strip != ""
    args << "--db"
    args << @export_db_path
  else
    args << "--no-save"        
  end
  if File.directory?(@project_root) and @project_root != ENV["HOME"]
    YARD::Registry.clear
    old_dir = Dir.pwd
    FileUtils.cd(@project_root)
    YARD::CLI::Yardoc.run(*args)
    FileUtils.cd(old_dir)
  else
    alert "Invalid Project Folder.", parent: self
  end
  if @theme != "default"
    css = VR::load_yaml(YardTheme, File.join(@theme_root, @theme + ".yaml"))
    css.export_to(File.join(@project_root, @output_dir, "css", "common.css"))
#      $default_theme.export_to(File.join(@project_root, @output_dir, "css", "common.css"))
  else
    css = File.join(@project_root, @output_dir, "css", "common.css")
    File.delete(css) if File.exist?(css)
  end
  alert("Documents created in the '#{@output_dir}' folder.", headline: "Documents Generated", width: 500)
end

#buttonOpenProject__clicked(*a) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/MyYard.rb', line 141

def buttonOpenProject__clicked(*a)
  if folder = alert("Enter folder to open:",
      parent: self, data: Dir.home + "/",
      headline: "Open Folder", button_yes: "Open")
    if File.directory?(folder)
      save_state
      $open_project = folder
      @builder[:window1].destroy
    end  
  end
end

#defaultsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/MyYard.rb', line 10

def defaults
  unless File.directory?(File.join(Dir.home, "my_yard"))
    VR.copy_recursively File.join(File.dirname(__FILE__), "..", "home_my_yard"), File.join(Dir.home, "my_yard")
    VR::load_yaml(YardTheme, File.join(Dir.home, "my_yard", "themes", "default.yaml")) # create default theme
  end

  @project_root = Dir.pwd
  @theme_root = File.join(Dir.home, "my_yard", "themes")
  @template_root = File.join(Dir.home, "my_yard", "templates")
  @output_dir ||= "docs"
  @theme = "default" if @theme.nil? or !File.exist?(File.join(@theme_root, @theme + ".yaml")) 
  @template ||= "default" 
  @files ||= "*/**/*.rb */**/*.c"
  @extra_files ||= "*/**/*.md"
  @exclude ||= ""
  @include_public = true if @include_public.nil? # ||= no good on this one  
  @include_private ||= false
  @include_protected ||= false
  @include_private_tag ||= false
  @title ||= "Generated with my_yard "
  @main ||= "README.md"
  @export_db = false if @export_db.nil?
  @export_db_path ||= ".yardoc"
end

#fill_combo_boxesObject



101
102
103
104
105
106
107
108
# File 'lib/MyYard.rb', line 101

def fill_combo_boxes()
  @builder[:template].append_text "default"
  glob = File.join(@template_root, "*/")
  Dir.glob(glob).each do |path|
    @builder[:template].append_text File.basename(path)
  end
  fill_themes  
end

#fill_themesObject



110
111
112
113
114
115
116
# File 'lib/MyYard.rb', line 110

def fill_themes()
  @builder[:theme].model.clear
  glob = File.join(@theme_root, "*.yaml")
  Dir.glob(glob).each do |path|
  @builder[:theme].append_text File.basename(path, ".*")
  end
end

#save_stateObject



185
186
187
188
# File 'lib/MyYard.rb', line 185

def save_state
  get_glade_variables
  VR::save_yaml(self)
end

#theme__changed(*a) ⇒ Object



97
98
99
# File 'lib/MyYard.rb', line 97

def theme__changed(*a)
  get_glade_variables
end

#window1__delete_event(*a) ⇒ Object



180
181
182
183
# File 'lib/MyYard.rb', line 180

def window1__delete_event(*a)
  save_state
  return false
end