Class: MyYard

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

Instance Method Summary collapse

Constructor Details

#initializeMyYard

Returns a new instance of MyYard



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

def initialize
  defaults
end

Instance Method Details

#before_showObject



28
29
30
# File 'src/MyYard.rb', line 28

def before_show()
  fill_combo_boxes
end

#buttonBrowse__clicked(*a) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
# File 'src/MyYard.rb', line 137

def buttonBrowse__clicked(*a)
  save_state
  begin
    IO.popen("#{$env.browser} #{File.join(@project_root, @output_dir, @main)}")  
  rescue
    if answer = alert("Enter command to start your browser:", parent: self, input_text: $env.browser)
      $env.browser = answer
      VR::save_yaml($env)
    end  
  end
end

#buttonCancel__clicked(*a) ⇒ Object



181
182
183
184
185
# File 'src/MyYard.rb', line 181

def buttonCancel__clicked(*a)
  save_state
  $open_project = :exit
  super
end

#buttonDeleteProject__clicked(*a) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'src/MyYard.rb', line 149

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



163
164
165
166
167
168
169
170
171
172
173
# File 'src/MyYard.rb', line 163

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($env.theme_root, "#{@theme}.yaml")
    File.delete(theme)
    @theme = "default"
    fill_themes
    set_glade_variables
  end 
end

#buttonEditTheme__clicked(*a) ⇒ Object



115
116
117
118
119
120
121
122
# File 'src/MyYard.rb', line 115

def buttonEditTheme__clicked(*a)
  get_glade_variables
  file = File.join($env.theme_root, @theme + ".yaml")
  win = VR::load_yaml(YardTheme, file)
  win.show_glade(self)
  fill_themes
  set_glade_variables # select theme again      
end

#buttonGenerate__clicked(*args) ⇒ Object



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

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 << $env.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
    YARD::Templates::ErbCache.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($env.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
    File.delete(File.join(@project_root, @output_dir, "css", "common.css"))
  end
end

#buttonOpenProject__clicked(*a) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'src/MyYard.rb', line 124

def buttonOpenProject__clicked(*a)
  if folder = alert("Enter folder to open:",
      parent: self, input_text: Dir.home + "/",
      headline: "Open Folder", button_yes: "Open",
      button_no: "Cancel")
    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
# File 'src/MyYard.rb', line 10

def defaults
  @project_root = $open_project
  @output_dir ||= "doc"
  @theme = "default" if @theme.nil? or !File.exist?(File.join($env.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 Yard 0.8.7.6"
  @main ||= "README.md"
  @export_db = true if @export_db.nil?
  @export_db_path ||= ".yardoc"
end

#fill_combo_boxesObject



95
96
97
98
99
100
101
102
103
104
105
# File 'src/MyYard.rb', line 95

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

#fill_themesObject



107
108
109
110
111
112
113
# File 'src/MyYard.rb', line 107

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

#project_root__changed(*a) ⇒ Object



87
88
89
90
91
92
93
# File 'src/MyYard.rb', line 87

def project_root__changed(*a)
  return unless @builder[:project_root].model.count == $env.projects.size 
  return if @builder[:project_root].active_text == $open_project 
  save_state
  $open_project = @builder[:project_root].active_text
  @builder[:window1].destroy  
end

#save_stateObject



188
189
190
191
192
# File 'src/MyYard.rb', line 188

def save_state
  get_glade_variables
  @project_root = $open_project
  VR::save_yaml(self)
end

#window1__delete_event(*a) ⇒ Object



175
176
177
178
179
# File 'src/MyYard.rb', line 175

def window1__delete_event(*a)
  save_state
  $open_project = :exit
  return false
end