| Class | Page |
| In: |
app/models/page.rb
|
| Parent: | ActiveRecord::Base |
| PAGE_HEAD_SNIPPET_PATTERN | = | /<!-- epfwiki head.*head end -->/m | Used to remove HTML fragment that wikifies the HTML file so it can be edited. | |
| TREEBROWSER_PATTERN | = | /<script.*?scripts\/treebrowser\.js.*?<\/script>/i | Used to replace treebrowser.js from HTML files because it chrashes the HTML editor | |
| TREEBROWSER_PLACEHOLDER | = | "<div id=\"treebrowser_tag_placeholder\"/>" | Placeholder for TREEBROWSER_PATTERN , so we can easily place it back in the file | |
| BODY_TAG_PATTERN | = | /<body.*>/i | Used to remove onload event from HTML files because it chrashed the HTML Editor | |
| BODY_CLOSING_TAG_PATTERN | = | /<\/body>/i | Used to add the page_script | |
| SHIM_TAG_PATTERN | = | /images\/shim.gif(")?( )*\/?>.?( )*?.?( )*?<\/td>/im | Used to fix some layout problems with the ‘horizontal rule‘ | |
| SHIM_TAG | = | "images/shim.gif\" /></td>" | Used to fix some layout problems with the ‘horizontal rule‘ | |
| COPYRIGHT_PATTERN | = | /<p>( )*?(.)?( )*?copyright(.)*?<\/p>/im | Used to replace copyright notice from the file so it can be edited. | |
| COPYRIGHT_PLACEHOLDER | = | "<!-- copyright statement -->" | Placeholder for copyright notice we find with COPYRIGHT_PATTERN | |
| TITLE_PATTERN | = | /<title>(.)*<\/title>/i | ||
| HEAD_PATTERN | = | /<head>(.)*<\/head>/im | ||
| TITLE2_PATTERN | = | /class="pageTitle">(.)*<\/td>/ | ||
| TITLE2_START | = | /class="pageTitle">/i | ||
| TITLE2_END | = | /<\/td>/ | ||
| ELEMENT_TYPE_PATTERN | = | /<meta(.)*element_type(.)*>/i |
| note | [RW] | When creating a new page, use to supply a note for creating the version |
| source_version | [RW] | For creating a new page, use to specify the source version of the template or page NOTE: depending where it is used (view or model) this stores an Id or and object. |
| user | [RW] | For creating a new page, use to specify the user |
Method enhance_file enhances a file if it hasn‘t been enhanced yet with e.g. Javascript libs, CSS, (script) elements
# File app/models/page.rb, line 73
73: def self.enhance_file(path, snippets = Page.get_snippets)
74: h = IO.readlines(path).join
75: if h.index('epfwiki head start')
76: logger.info("File skipped (already enhanced): #{path}")
77: else
78: new_html = h.gsub(/<\/head>/i, snippets[0] + "\n</head>")
79: new_html = new_html.gsub("width=\"100%\"", "width=\"99%\"") # workaround to prevent scrollbar from being displayed
80: file = File.new(path, "w")
81: file.puts(new_html)
82: file.close
83: end
84: end
# File app/models/page.rb, line 67
67: def self.get_snippets
68: return [IO.readlines(File.expand_path('app/models/page_head_snippet.txt', RAILS_ROOT)).join]
69: end
UMA Name from HTML
# File app/models/page.rb, line 104
104: def self.uma_name_from_html(html)
105: return uma_value_from_html(html, /<meta.*? name="uma\.name".*?>/)
106: end
extracts and returns the UMA Presentation Name from HTML
# File app/models/page.rb, line 99
99: def self.uma_presentation_name_from_html(html)
100: return uma_value_from_html(html, /<meta.*? name="uma\.presentationName".*?>/)
101: end
UMA Type from HTML
# File app/models/page.rb, line 109
109: def self.uma_type_from_html(html)
110: return uma_value_from_html(html, /<meta.*? name="uma\.type".*?>/)
111: end
Order of content and name does not seem to be always the same? So this method is independent of order
# File app/models/page.rb, line 115
115: def self.uma_value_from_html(html, pattern)
116: match = pattern.match(html)
117: result = ''
118: if match
119: match2 = /content="(.*?)"/.match(match[0])
120: result = match2[1] if match2
121: end
122: return result
123: end
# File app/models/page.rb, line 145
145: def before_create
146: h = self.html
147: self.uma_type = Page.uma_type_from_html(h)
148: self.uma_name = Page.uma_name_from_html(h)
149: logger.debug("...#{Page.uma_presentation_name_from_html(h)}")
150: self.presentation_name = Page.uma_presentation_name_from_html(h)
151: self.filename = File.basename(self.path)
152: self.body_tag = BODY_TAG_PATTERN.match(h).to_s
153: self.treebrowser_tag = TREEBROWSER_PATTERN.match(h).to_s
154: self.copyright_tag = COPYRIGHT_PATTERN.match(h).to_s
155: self.head_tag = Page::HEAD_PATTERN.match(h).to_s
156: end
# File app/models/page.rb, line 125
125: def overview_table
126: match = /class="overviewTable".*?>(.*?)<\/table>/m.match(self.html)
127: if match # some pages may not have overviewTable section
128: match1 = /td.*?>(.*?)<\/td>/m.match(match[1]) # returns only the text from the overviewTable section
129: if match1
130: result = match1[1]
131: end
132: else
133: result = ""
134: end
135:
136: return result
137: end
# File app/models/page.rb, line 86
86: def path
87: return self.site.path + '/' + self.rel_path
88: end
# File app/models/page.rb, line 94
94: def url(absolute = false, request_host = nil)
95: self.site.url(absolute, request_host).gsub('/index.htm','/') + self.rel_path
96: end