Class: AsciiBinderGabrielRH::TopicEntity
- Inherits:
-
Object
- Object
- AsciiBinderGabrielRH::TopicEntity
- Defined in:
- lib/ascii_binder_gabriel_rh/topic_entity.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#distro_keys ⇒ Object
readonly
Returns the value of attribute distro_keys.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#subitems ⇒ Object
readonly
Returns the value of attribute subitems.
-
#topic_alias ⇒ Object
readonly
Returns the value of attribute topic_alias.
Instance Method Summary collapse
- #alias_list(distro_key) ⇒ Object
- #basename_path ⇒ Object
- #breadcrumb ⇒ Object
- #errors ⇒ Object
- #group_filepaths ⇒ Object
- #id ⇒ Object
-
#include?(distro_key, single_page_path) ⇒ Boolean
Is this topic entity or any of its children used in the specified distro / single page chain.
-
#initialize(topic_entity, actual_distro_keys, dir_path = '', parent_group = nil, depth = 0) ⇒ TopicEntity
constructor
A new instance of TopicEntity.
- #is_alias? ⇒ Boolean
- #is_group? ⇒ Boolean
- #is_topic? ⇒ Boolean
- #is_valid? ⇒ Boolean
- #nav_tree(distro_key) ⇒ Object
- #package_path(site_id, branch_dir) ⇒ Object
- #path_list(distro_key) ⇒ Object
- #preview_path(distro_key, branch_dir) ⇒ Object
- #repo_path ⇒ Object
- #repo_path_html ⇒ Object
- #source_path ⇒ Object
- #topic_publish_url(distro_url, branch_dir) ⇒ Object
Constructor Details
#initialize(topic_entity, actual_distro_keys, dir_path = '', parent_group = nil, depth = 0) ⇒ TopicEntity
Returns a new instance of TopicEntity.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 10 def initialize(topic_entity,actual_distro_keys,dir_path='',parent_group=nil,depth=0) @raw = topic_entity @parent = parent_group @dir_path = dir_path @name = topic_entity['Name'] @dir = topic_entity['Dir'] @file = topic_entity['File'] @topic_alias = topic_entity['Alias'] @depth = depth @actual_distro_keys = actual_distro_keys @distro_keys = topic_entity.has_key?('Distros') ? parse_distros(topic_entity['Distros']) : actual_distro_keys @nav_trees = {} @alias_lists = {} @path_lists = {} @subitems = [] if topic_entity.has_key?('Topics') entity_dir = @dir.nil? ? '<nil_dir>' : @dir subdir_path = dir_path == '' ? entity_dir : File.join(dir_path,entity_dir) topic_entity['Topics'].each do |sub_entity| @subitems << AsciiBinderGabrielRH::TopicEntity.new(sub_entity,actual_distro_keys,subdir_path,self,depth+1) end end end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def depth @depth end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def dir @dir end |
#distro_keys ⇒ Object (readonly)
Returns the value of attribute distro_keys.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def distro_keys @distro_keys end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def parent @parent end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def raw @raw end |
#subitems ⇒ Object (readonly)
Returns the value of attribute subitems.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def subitems @subitems end |
#topic_alias ⇒ Object (readonly)
Returns the value of attribute topic_alias.
8 9 10 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 8 def topic_alias @topic_alias end |
Instance Method Details
#alias_list(distro_key) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 111 def alias_list(distro_key) @alias_lists[distro_key] ||= begin sub_aliases = [] if distro_keys.include?(distro_key) if is_group? subitems.each do |subitem| sub_list = subitem.alias_list(distro_key) sub_list.each do |sub_list_alias| sub_aliases << sub_list_alias end end elsif is_alias? sub_aliases << { :alias_path => basename_path, :redirect_path => topic_alias } end end sub_aliases end end |
#basename_path ⇒ Object
46 47 48 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 46 def basename_path @basename_path ||= File.join(File.dirname(repo_path),File.basename(repo_path,'.adoc')) end |
#breadcrumb ⇒ Object
180 181 182 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 180 def @breadcrumb ||= hierarchy.map{ |entity| { :id => entity.id, :name => entity.name, :url => entity.repo_path_html } } end |
#errors ⇒ Object
204 205 206 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 204 def errors validate(true) end |
#group_filepaths ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 70 def group_filepaths @group_filepaths ||= begin group_filepaths = [] if is_topic? and not is_alias? group_filepaths << File.join(File.dirname(repo_path),File.basename(repo_path,'.adoc')) elsif is_group? subitems.each do |subitem| group_filepaths.concat(subitem.group_filepaths) end group_filepaths.uniq! end group_filepaths end end |
#id ⇒ Object
184 185 186 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 184 def id @id ||= hierarchy.map{ |entity| camelize(entity.name) }.join('::') end |
#include?(distro_key, single_page_path) ⇒ Boolean
Is this topic entity or any of its children used in the specified distro / single page chain
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 151 def include?(distro_key,single_page_path) # If this entity isn't for this distro, bail out return false unless distro_keys.include?(distro_key) # If we're building a single page, check if we're on the right track. if single_page_path.length > 0 and not single_page_path[depth].nil? if is_group? return false unless single_page_path[depth] == dir elsif is_topic? return false unless single_page_path[depth] == file else return false end elsif is_group? # If this is a topic group that -is- okay for this distro, but # none of its subitems are okay for this distro, then bail out. subitems_for_distro = false subitems.each do |subitem| if subitem.include?(distro_key,[]) subitems_for_distro = true break end end return false unless subitems_for_distro end return true end |
#is_alias? ⇒ Boolean
196 197 198 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 196 def is_alias? @is_alias ||= is_topic? and not topic_alias.nil? end |
#is_group? ⇒ Boolean
188 189 190 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 188 def is_group? @is_group ||= file.nil? and not name.nil? and not dir.nil? and subitems.length > 0 end |
#is_topic? ⇒ Boolean
192 193 194 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 192 def is_topic? @is_topic ||= dir.nil? and not name.nil? and not file.nil? and subitems.length == 0 end |
#is_valid? ⇒ Boolean
200 201 202 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 200 def is_valid? validate end |
#nav_tree(distro_key) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 85 def nav_tree(distro_key) @nav_trees[distro_key] ||= begin nav_tree = {} if distro_keys.include?(distro_key) and not is_alias? nav_tree[:id] = id nav_tree[:name] = name if is_topic? nav_tree[:path] = "../" + repo_path_html elsif is_group? sub_nav_items = [] subitems.each do |subitem| sub_nav = subitem.nav_tree(distro_key) next if sub_nav.empty? sub_nav_items << sub_nav end if sub_nav_items.empty? nav_tree = {} else nav_tree[:topics] = sub_nav_items end end end nav_tree end end |
#package_path(site_id, branch_dir) ⇒ Object
66 67 68 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 66 def package_path(site_id,branch_dir) File.join(package_dir,site_id,branch_dir,repo_path_html) end |
#path_list(distro_key) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 130 def path_list(distro_key) @path_lists[distro_key] ||= begin sub_paths = [] if distro_keys.include?(distro_key) if is_group? subitems.each do |subitem| sub_list = subitem.path_list(distro_key) sub_list.each do |sub_list_path| sub_paths << sub_list_path end end elsif is_topic? and not is_alias? sub_paths << basename_path end end sub_paths end end |
#preview_path(distro_key, branch_dir) ⇒ Object
58 59 60 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 58 def preview_path(distro_key,branch_dir) File.join(preview_dir,distro_key,branch_dir,repo_path_html) end |
#repo_path ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 34 def repo_path @repo_path ||= begin this_step = '<nil_item>' if is_group? this_step = dir elsif is_topic? this_step = file.end_with?('.adoc') ? file : "#{file}.adoc" end @dir_path == '' ? this_step : File.join(@dir_path,this_step) end end |
#repo_path_html ⇒ Object
50 51 52 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 50 def repo_path_html @repo_path_html ||= is_topic? ? File.join(File.dirname(repo_path),File.basename(repo_path,'.adoc')) + ".html" : repo_path end |
#source_path ⇒ Object
54 55 56 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 54 def source_path @source_path ||= File.join(docs_root_dir,repo_path) end |
#topic_publish_url(distro_url, branch_dir) ⇒ Object
62 63 64 |
# File 'lib/ascii_binder_gabriel_rh/topic_entity.rb', line 62 def topic_publish_url(distro_url,branch_dir) File.join(distro_url,branch_dir,repo_path_html) end |