| 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 | = | "<!-- treebrowser tag -->" | 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 71
71: def self.enhance_file(path, snippets = Page.get_snippets)
72: h = IO.readlines(path).join
73: if h.index('epfwiki head start')
74: logger.info("File skipped (already enhanced): #{path}")
75: else
76: new_html = h.gsub(/<\/head>/i, snippets[0] + "\n</head>")
77: new_html = new_html.gsub("width=\"100%\"", "width=\"99%\"") # workaround to prevent scrollbar from being displayed
78: file = File.new(path, "w")
79: file.puts(new_html)
80: file.close
81: end
82: end
# File app/models/page.rb, line 65
65: def self.get_snippets
66: return [IO.readlines(File.expand_path('app/models/page_head_snippet.txt', RAILS_ROOT)).join]
67: end
UMA Name from HTML
# File app/models/page.rb, line 102
102: def self.uma_name_from_html(html)
103: return uma_value_from_html(html, /<meta.*? name="uma\.name".*?>/)
104: end
extracts and returns the UMA Presentation Name from HTML
# File app/models/page.rb, line 97
97: def self.uma_presentation_name_from_html(html)
98: return uma_value_from_html(html, /<meta.*? name="uma\.presentationName".*?>/)
99: end
UMA Type from HTML
# File app/models/page.rb, line 107
107: def self.uma_type_from_html(html)
108: return uma_value_from_html(html, /<meta.*? name="uma\.type".*?>/)
109: 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 113
113: def self.uma_value_from_html(html, pattern)
114: match = pattern.match(html)
115: result = ''
116: if match
117: match2 = /content="(.*?)"/.match(match[0])
118: result = match2[1] if match2
119: end
120: return result
121: end
# File app/models/page.rb, line 129
129: def before_create
130: h = self.html
131: self.uma_type = Page.uma_type_from_html(h)
132: self.uma_name = Page.uma_name_from_html(h)
133: logger.debug("...#{Page.uma_presentation_name_from_html(h)}")
134: self.presentation_name = Page.uma_presentation_name_from_html(h)
135: self.filename = File.basename(self.path)
136: self.body_tag = BODY_TAG_PATTERN.match(h).to_s
137: self.treebrowser_tag = TREEBROWSER_PATTERN.match(h).to_s
138: self.copyright_tag = COPYRIGHT_PATTERN.match(h).to_s
139: self.head_tag = Page::HEAD_PATTERN.match(h).to_s
140: end
# File app/models/page.rb, line 84
84: def path
85: return self.site.path + '/' + self.rel_path
86: end
# File app/models/page.rb, line 92
92: def url(absolute = false, request_host = nil)
93: self.site.url(absolute, request_host) + self.rel_path
94: end