Class: Kinbote::Site
- Inherits:
-
Object
show all
- Includes:
- Util
- Defined in:
- lib/kinbote/site.rb
Constant Summary
collapse
- BAD_PAGE_SLUGS =
["kinbote"]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util
#dir_from_file, #file_without_extension, #output_path, #print_state, #slug_from_file, #slugify, #sorted_attributes, #type_from_file, #varify, #view_path
Constructor Details
#initialize ⇒ Site
Returns a new instance of Site.
8
9
10
11
12
13
14
15
|
# File 'lib/kinbote/site.rb', line 8
def initialize
@pages = []
@attributes = []
@values = []
@kinbote_path = nil
@config = {}
@messages = []
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4
5
6
|
# File 'lib/kinbote/site.rb', line 4
def config
@config
end
|
#kinbote_path ⇒ Object
Returns the value of attribute kinbote_path.
4
5
6
|
# File 'lib/kinbote/site.rb', line 4
def kinbote_path
@kinbote_path
end
|
Instance Method Details
#add_attribute(attribute) ⇒ Object
107
108
109
|
# File 'lib/kinbote/site.rb', line 107
def add_attribute(attribute)
@attributes << attribute if !has_attribute?(attribute.name)
end
|
#add_message(message) ⇒ Object
115
|
# File 'lib/kinbote/site.rb', line 115
def add_message(message); @messages << message if !@messages.include?(message); end
|
#attributes ⇒ Object
97
98
99
|
# File 'lib/kinbote/site.rb', line 97
def attributes
sorted_attributes(@attributes)
end
|
#bulk_update(slugs = [], action = {}) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/kinbote/site.rb', line 73
def bulk_update(slugs=[], action={})
return if !slugs || slugs.size == 0
slugs.each do |slug|
page = find_page(slug)
next if !page
if action["type"] == "add_attribute"
next if (!action.has_key?("attribute") || action["attribute"].strip.size == 0) || (!action.has_key?("value") || action["value"].strip.size == 0)
page.add_attribute(action["attribute"], [action["value"]])
elsif action["type"] == "rem_attribute"
next if !action.has_key?("attribute") || action["attribute"].strip.size == 0
if action.has_key?("value") && action["value"].strip.size > 0
page.rem_value(action["attribute"], action["value"])
else
page.rem_attribute(action["attribute"])
end
end
Page.add_metadata(page)
end
end
|
#create_page(title, file = nil, attributes = nil) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/kinbote/site.rb', line 46
def create_page(title, file=nil, attributes=nil)
if BAD_PAGE_SLUGS.include?(slugify(title))
add_message("#{title} #{file ? "(#{file})" : ""} is an invalid page title")
return false
end
@pages << Page.new(title, file, attributes)
end
|
#delete_page(slug) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/kinbote/site.rb', line 54
def delete_page(slug)
page = find_page(slug)
@attributes.map{|att| att.rem_page(page)}
@attributes.delete_if{|att| att.pages.size == 0}
page.delete_files([:html, :css])
@pages.delete_if{|p| p.slug == page.slug}
Page.add_metadata
end
|
#find_attribute(name, page = nil) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/kinbote/site.rb', line 32
def find_attribute(name, page=nil)
(page ? page.attributes : @attributes).each do |attribute|
return attribute if (attribute.name == name || attribute.varname == varify(name))
end
nil
end
|
#find_page(slug) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/kinbote/site.rb', line 25
def find_page(slug)
@pages.each do |page|
return page if page.slug == slug
end
nil
end
|
#find_value(val, attribute) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/kinbote/site.rb', line 39
def find_value(val, attribute)
attribute.values.each do |value|
return value if (value.value == val && (attribute.name == value.attribute.name || attribute.varname == varify(value.attribute.name)))
end
nil
end
|
#has_attribute?(att_name) ⇒ Boolean
111
112
113
|
# File 'lib/kinbote/site.rb', line 111
def has_attribute?(att_name)
@attributes.map{|a| a.name}.include?(att_name)
end
|
#has_messages? ⇒ Boolean
116
|
# File 'lib/kinbote/site.rb', line 116
def has_messages?; @messages.size > 0; end
|
#load ⇒ Object
17
18
|
# File 'lib/kinbote/site.rb', line 17
def load
end
|
#pages ⇒ Object
93
94
95
|
# File 'lib/kinbote/site.rb', line 93
def pages
@pages.sort{|x, y| x.title.downcase <=> y.title.downcase }
end
|
#print_sample_code? ⇒ Boolean
101
102
103
|
# File 'lib/kinbote/site.rb', line 101
def print_sample_code?
@config.has_key?("print_sample_code") && @config["print_sample_code"] != false
end
|
#reload ⇒ Object
20
21
22
23
|
# File 'lib/kinbote/site.rb', line 20
def reload
read_config
reload_pages
end
|
#rem_page_attribute(page, att_name) ⇒ Object
68
69
70
71
|
# File 'lib/kinbote/site.rb', line 68
def rem_page_attribute(page, att_name)
@attributes.map{|att| att.rem_page(page) if att.name == att_name}
@attributes.delete_if{|att| att.pages.size == 0}
end
|
#rem_page_attributes(page) ⇒ Object
63
64
65
66
|
# File 'lib/kinbote/site.rb', line 63
def rem_page_attributes(page)
@attributes.map{|att| att.rem_page(page)}
@attributes.delete_if{|att| att.pages.size == 0}
end
|
#render_messages ⇒ Object
117
|
# File 'lib/kinbote/site.rb', line 117
def render_messages; m = Array.new(@messages); @messages = []; m; end
|