class Carte::Server
Constants
- VERSION
Public Instance Methods
config()
click to toggle source
# File lib/carte/server.rb, line 27 def config @config ||= settings.default.update(settings.carte) end
json_data()
click to toggle source
# File lib/carte/server.rb, line 31 def json_data request.body.rewind JSON.parse(request.body.read) end
markdown2html(markdown)
click to toggle source
# File lib/carte/server.rb, line 61 def markdown2html(markdown) renderer = Redcarpet::Render::HTML.new(filter_html:true) html = Redcarpet::Markdown.new(renderer, autolink: true).render(markdown) parse_card_link(html) end
parse_card_link(html)
click to toggle source
# File lib/carte/server.rb, line 67 def parse_card_link(html) html.gsub(/\[\[(.+?)\]\]/) do |match| title = $1.dup if title.match(/<("[^"]*"|'[^']*'|[^'">])*>/) match else %Q(<a href="http://#{request.host}/#/#{URI.escape(title)}">#{title}</a>) end end end
search(params)
click to toggle source
# File lib/carte/server.rb, line 36 def search(params) order = (params[:order] && %w(asc desc random).include?(params[:order])) ? params[:order] : 'desc' sort = (params[:sort] && %w(title created_at updated_at).include?(params[:sort])) ? params[:sort] : 'updated_at' if order == 'random' cards = Card.random else cards = Card.send(order, sort) end conditions = [] if title = params[:title] conditions << {title: /#{title}/i} end if content = params[:content] conditions << {content: /#{content}/i} end if conditions.size > 0 cards = cards.any_of(conditions) end if params[:tags] tags = params[:tags].split(',') cards = cards.tagged_with_all(tags) end cards = cards.paginate(per_page: 9, page: params[:page]) end