Module: ServerHelpers
- Defined in:
- lib/wiki/server_helpers.rb
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #claimed? ⇒ Boolean
- #cross_origin ⇒ Object
- #identified? ⇒ Boolean
- #oops(status, message) ⇒ Object
- #openid_consumer ⇒ Object
- #resolve_links(string) ⇒ Object
- #serve_page(name, site = request.host) ⇒ Object
- #serve_resources_locally?(site) ⇒ Boolean
- #synopsis(page) ⇒ Object
Instance Method Details
#authenticate! ⇒ Object
36 37 38 39 |
# File 'lib/wiki/server_helpers.rb', line 36 def authenticate! session[:authenticated] = true redirect "/" end |
#authenticated? ⇒ Boolean
24 25 26 |
# File 'lib/wiki/server_helpers.rb', line 24 def authenticated? session[:authenticated] == true end |
#claimed? ⇒ Boolean
32 33 34 |
# File 'lib/wiki/server_helpers.rb', line 32 def claimed? Store.exists? "#{farm_status}/open_id.identity" end |
#cross_origin ⇒ Object
3 4 5 |
# File 'lib/wiki/server_helpers.rb', line 3 def cross_origin headers 'Access-Control-Allow-Origin' => "*" if request.env['HTTP_ORIGIN'] end |
#identified? ⇒ Boolean
28 29 30 |
# File 'lib/wiki/server_helpers.rb', line 28 def identified? Store.exists? "#{farm_status}/open_id.identifier" end |
#oops(status, message) ⇒ Object
41 42 43 |
# File 'lib/wiki/server_helpers.rb', line 41 def oops status, haml :oops, :layout => false, :locals => {:status => status, :message => } end |
#openid_consumer ⇒ Object
20 21 22 |
# File 'lib/wiki/server_helpers.rb', line 20 def openid_consumer @openid_consumer ||= OpenID::Consumer.new(session, OpenID::Store::Filesystem.new("#{farm_status}/tmp/openid")) end |
#resolve_links(string) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wiki/server_helpers.rb', line 7 def resolve_links string string. gsub(/\[\[([^\]]+)\]\]/i) { |name| name.gsub!(/^\[\[(.*)\]\]/, '\1') slug = name.gsub(/\s/, '-') slug = slug.gsub(/[^A-Za-z0-9-]/, '').downcase '<a class="internal" href="/'+slug+'.html" data-page-name="'+slug+'" >'+name+'</a>' }. gsub(/\[(http.*?) (.*?)\]/i, '<a class="external" href="\1" rel="nofollow">\2</a>') end |
#serve_page(name, site = request.host) ⇒ Object
49 50 51 52 53 |
# File 'lib/wiki/server_helpers.rb', line 49 def serve_page(name, site=request.host) cross_origin halt 404 unless farm_page(site).exists?(name) JSON.pretty_generate farm_page(site).get(name) end |
#serve_resources_locally?(site) ⇒ Boolean
45 46 47 |
# File 'lib/wiki/server_helpers.rb', line 45 def serve_resources_locally?(site) !!ENV['FARM_DOMAINS'] && ENV['FARM_DOMAINS'].split(',').any?{|domain| site.end_with?(domain)} end |
#synopsis(page) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/wiki/server_helpers.rb', line 55 def synopsis page text = page['synopsis'] p1 = page['story'] && page['story'][0] p2 = page['story'] && page['story'][1] text ||= p1 && p1['text'] if p1 && p1['type'] == 'paragraph' text ||= p2 && p2['text'] if p2 && p2['type'] == 'paragraph' text ||= p1 && p1['text'] || p2 && p2['text'] || page['story'] && "A page with #{page['story'].length} paragraphs." || "A page with no story." return text end |