Class: Goldberg::ContentPage

Inherits:
ActiveRecord::Base show all
Includes:
Model
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

included

Methods inherited from ActiveRecord::Base

#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?

Instance Attribute Details

#content_htmlObject

Returns the value of attribute content_html.



12
13
14
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 12

def content_html
  @content_html
end

Class Method Details

.find_for_permission(p_ids) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 36

def find_for_permission(p_ids)
  if p_ids.blank?
    return []
  else
    return find(:all, 
                :conditions => ['permission_id in (?)', p_ids],
                :order => 'name')
  end
end

.javascript_esc(string) ⇒ Object



74
75
76
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 74

def javascript_esc(string)
  string.gsub(/'/, "\\'")
end

.markup_stylesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 15

def markup_styles
  if not @markup_styles
    @markup_styles = []
    # If FCKeditor is installed, allow it.
    if File.directory?(File.join RAILS_ROOT, 'public', 'fckeditor')
      @markup_styles << 'FCKeditor'
    end
    # These are the basic styles.
    @markup_styles += ['Raw HTML', 'Plain text']
    # If redcloth is available add Textile and Markdown,
    # otherwise trap the exception.
    begin
      RedCloth
      @markup_styles += ['Textile', 'Markdown']
    rescue MissingSourceFile
      nil
    end
  end
  return @markup_styles
end

.speller_pages(text) ⇒ Object



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
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 46

def speller_pages(text)
  opts =  '-a --encoding=utf-8 -H 2>&1'
  if RUBY_PLATFORM =~ /mswin/i
    cmd = '"C:\Program Files\aspell\bin\aspell" ' + opts
  else
    cmd = "aspell #{opts}"
  end
  
  results = []
  IO.popen(cmd, 'r+') do |io|
    io.puts text
    io.close_write
    while not io.eof?
      line = io.readline.chomp
      if line =~ /^\&/
        parts = line.split(' ', 5)
      word = parts[1]
        suggestions = parts[4].split(', ').collect do |suggestion|
          "'#{javascript_esc(suggestion)}'"
        end
        results << [javascript_esc(word), suggestions.join(', ')] 
      end
    end
  end
  
  return results
end

Instance Method Details

#before_saveObject



95
96
97
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 95

def before_save
  self.content_cache = self.markup_content
end

#content=(new_content) ⇒ Object



89
90
91
92
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 89

def content=(new_content)
  write_attribute(:content, new_content)
  self.content_cache = nil
end

#fullnameObject



84
85
86
87
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 84

def fullname
  "#{ERB::Util.html_escape(self.name)}" <<
    (self.title ? " -- #{ERB::Util.html_escape(self.title)}" : '')
end

#urlObject

class << self



80
81
82
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/content_page.rb', line 80

def url
  return "/#{self.name}"
end