source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/file.rb | Ruby | mit | 179 | master | 6,725 | # ~*~ encoding: utf-8 ~*~
module Gollum
class File
# Does the filesystem support reading symlinks?
FS_SUPPORT_SYMLINKS = !Gem.win_platform?
class << self
# Get a canonical path to a file.
# Ensures that the result is always under page_file_dir (prevents path traversal), if set.
# Removes l... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/sanitization.rb | Ruby | mit | 179 | master | 1,603 | ::Loofah::HTML5::SafeList::ACCEPTABLE_PROTOCOLS.add('apt')
::Loofah::HTML5::SafeList::ALLOWED_ATTRIBUTES.merge(%w[controls loop muted playsinline autoplay])
module Gollum
class Sanitization
@@accepted_protocols = ::Loofah::HTML5::SafeList::ACCEPTABLE_PROTOCOLS.to_a.freeze
# This class method is used in the... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter.rb | Ruby | mit | 179 | master | 3,219 | # A "filter", in Gollum-speak, is an object which extracts tokens from an
# input stream of an arbitrary markup language, then replaces them with a
# final form in a rendered form of the same document. Filters are composed
# into a "filter chain", which forms the order in which filters are applied
# in both the extrac... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/blob_entry.rb | Ruby | mit | 179 | master | 2,693 | # ~*~ encoding: utf-8 ~*~
module Gollum
class BlobEntry
# Gets the String SHA for this blob.
attr_reader :sha
# Gets the full path String for this blob.
attr_reader :path
# Gets the Fixnum size of this blob.
attr_reader :size
# Gets the Fixnum mode of this blob.
attr_reader :mode
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro.rb | Ruby | mit | 179 | master | 1,185 | module Gollum
class Macro
# Find the macro named, create an instance of that, and return it
def self.instance(macro_name, wiki, page)
begin
self.const_get(macro_name).new(wiki, page)
rescue NameError
Unknown_Macro.new(macro_name)
end
end
def initialize(wiki, page)
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro/video.rb | Ruby | mit | 179 | master | 414 | module Gollum
class Macro
class Video < Gollum::Macro
def render(fname, auto=false)
escaped_fname = CGI.escapeHTML(fname)
properties = auto ? "autoplay='true' playsinline='true' muted='true' loop='true'" : "controls='true'"
"<video width='100%' height='100%' src='#{escaped_fname}' #{... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro/audio.rb | Ruby | mit | 179 | master | 267 | module Gollum
class Macro
class Audio < Gollum::Macro
def render (fname)
"<audio width=\"100%\" height=\"100%\" src=\"#{CGI::escapeHTML(fname)}\" controls=\"true\"> HTML5 audio is not supported on this Browser.</audio>"
end
end
end
end |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro/navigation.rb | Ruby | mit | 179 | master | 887 | module Gollum
class Macro
class Navigation < Gollum::Macro
def render(title = "Navigate this directory", toc_root_path = ::File.dirname(@page.url_path), full_path = false)
pages = @wiki.pages
if pages.size > 0
prepath=@wiki.base_path.sub(/\/$/, '')
list_items = pages.map... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro/flash.rb | Ruby | mit | 179 | master | 372 | module Gollum
class Macro
class Flash < Gollum::Macro
def render(message, icon='', type='')
flash_type = ['warn', 'error', 'success'].include?(type) ? "flash-#{type}" : ''
flash_icon = icon.empty? ? '' : %Q(data-gollum-icon="#{icon}")
%Q(<div class="flash #{flash_type} my-2" #{flash... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro/series.rb | Ruby | mit | 179 | master | 1,993 | module Gollum
class Macro
class Series < Gollum::Macro
def render(series_prefix = "")
raise "This page's name does not match the prefix '#{series_prefix}'" unless active_page.name =~ /^#{series_prefix}/
render_links(*find_series(series_prefix))
end
def render_links(previous_page,... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro/global_toc.rb | Ruby | mit | 179 | master | 505 | module Gollum
class Macro
class GlobalTOC < Gollum::Macro
def render(title = "Global Table of Contents")
if @wiki.pages.size > 0
prepath = @wiki.base_path.sub(/\/$/, '')
result = '<ul>' + @wiki.pages.map { |p| "<li><a href=\"#{CGI::escapeHTML(prepath + "/" + p.escaped_url_path)}... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/macro/all_pages.rb | Ruby | mit | 179 | master | 259 | module Gollum
class Macro
class AllPages < Gollum::Macro
def render
if @wiki.pages.size > 0
'<ul id="pages">' + @wiki.pages.map { |p| "<li>#{CGI::escapeHTML(p.name)}</li>" }.join + '</ul>'
end
end
end
end
end |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/tags.rb | Ruby | mit | 179 | master | 12,696 | # ~*~ encoding: utf-8 ~*~
# Render all tags (things in double-square-brackets). This one's a biggie.
class Gollum::Filter::Tags < Gollum::Filter
# Extract all tags into the tagmap and replace with placeholders.
def extract(data)
data.gsub!(/(.?)\[\[(.+?)\]\]([^\[]?)/) do
if Regexp.last_match[1] == "'" &... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/critic_markup.rb | Ruby | mit | 179 | master | 3,215 | # ~*~ encoding: utf-8 ~*~
# CriticMarkup
#
# Render CriticMarkup
class Gollum::Filter::CriticMarkup < Gollum::Filter
# Patterns inspired by https://github.com/DivineDominion/criticmarkup.tmbundle/blob/master/Syntaxes/criticmarkup.tmLanguage
# All patterns use multiline matching (m flag)
# Logic inspired by htt... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/yaml.rb | Ruby | mit | 179 | master | 1,147 | require 'yaml'
# Extract YAML frontmatter from data and build metadata table.
class Gollum::Filter::YAML < Gollum::Filter
# Regexp thanks to jekyll
YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m
def extract(data)
data.gsub!(YAML_FRONT_MATTER_REGEXP) do
@markup.metadata ||... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/plain_text.rb | Ruby | mit | 179 | master | 369 | # ~*~ encoding: utf-8 ~*~
# Plain Text
#
# Render plain text documents in a <pre> block without any special markup.
class Gollum::Filter::PlainText < Gollum::Filter
def do_process(_d)
skip? ? _d : process(_d)
end
def extract(data)
@markup.format == :txt ? "<pre>#{CGI.escapeHTML(data)}</pre>" : d... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/toc.rb | Ruby | mit | 179 | master | 4,848 | # Inserts header anchors and creates TOC
class Gollum::Filter::TOC < Gollum::Filter
HEADERS = (1..6).to_a
def extract(data)
data
end
def process(data)
@doc = Nokogiri::HTML::DocumentFragment.parse(data)
@toc_doc = nil
@anchor_names = {}
@current_ancestors = [... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/remote_code.rb | Ruby | mit | 179 | master | 1,989 | # ~*~ encoding: utf-8 ~*~
require 'net/http'
require 'net/https' # ruby 1.8.7 fix, remove at upgrade
require 'uri'
require 'open-uri'
# Remote code - fetch code from url and replace the contents to a
# code-block that gets run the next parse.
# Acceptable formats:
# ```language:loc... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/emoji.rb | Ruby | mit | 179 | master | 1,113 | # ~*~ encoding: utf-8 ~*~
# Emoji
#
# Render an emoji tag such as ":smile:". In some rare situations, you have
# to escape emoji tags e.g. when your content contains something like
# "hh:mm:ss" or "rake app:shell:install". Prefix the leading colon with a
# backslash to disable this emoji tag e.g. "hh\:mm:ss".
class Go... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/code.rb | Ruby | mit | 179 | master | 5,579 | # ~*~ encoding: utf-8 ~*~
# Code
#
# Handle code blocks:
# - in the extractstep, extract them so they don't get rendered by the Render filter
# - in the process step, apply highlighting and wrapping and reinsert them into the document
class Gollum::Filter::Code < Gollum::Filter
# The @language_handlers Hash can ... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/macro.rb | Ruby | mit | 179 | master | 1,829 | # ~*~ encoding: utf-8 ~*~
# Replace specified tokens with dynamically generated content.
class Gollum::Filter::Macro < Gollum::Filter
def extract(data)
quoted_arg = %r{".*?(?<!\\)"} # use a negative lookbehind to not terminate on a " preceeded by \
unquoted_arg = %r{[^,)]+}
named_arg = %r{[a-z0-9_]... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/pandoc_bib.rb | Ruby | mit | 179 | master | 1,558 | require 'yaml'
require 'pathname'
# When using pandoc, put relevant bibliography metadata extracted in the YAML filter back in the document so it gets passed on to pandoc.
class Gollum::Filter::PandocBib < Gollum::Filter
BIB_PATH_KEYS = ['bibliography', 'csl']
BIB_KEYS = ['link-citations', 'nocite']
ALL_BIB_KEY... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/render.rb | Ruby | mit | 179 | master | 1,256 | # ~*~ encoding: utf-8 ~*~
class Gollum::Filter::Render < Gollum::Filter
def extract(data)
begin
working_dir = Pathname.new(@markup.wiki.path).join(@markup.dir)
working_dir = working_dir.exist? ? working_dir.to_s : '.'
Dir.chdir(working_dir) do
if block = @markup.custom_renderer
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/bibtex.rb | Ruby | mit | 179 | master | 1,574 | begin
require 'bibtex'
require 'citeproc'
require 'csl'
require 'csl/styles'
rescue LoadError => error
end
# Render BibTeX files.
class Gollum::Filter::BibTeX < Gollum::Filter
def extract(data)
return data unless supported_format? && gems_available? && bib = ::BibTeX.parse(data).convert(:latex)
styl... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/filter/plantuml.rb | Ruby | mit | 179 | master | 4,852 | # ~*~ encoding: utf-8 ~*~
require 'net/http'
require 'uri'
require 'open-uri'
require 'zlib'
# PlantUML Diagrams
#
# This filter replaces PlantUML blocks with HTML img tags. These img tags
# point to a PlantUML web service that converts the UML text blocks into nice
# diagrams.
#
# For this to work you must have your ... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_markup.rb | Ruby | mit | 179 | master | 52,762 | # ~*~ encoding: utf-8 ~*~
require File.expand_path("../helper", __FILE__)
require File.expand_path("../wiki_factory", __FILE__)
context "Markup" do
setup do
@wiki, @path, @teardown = WikiFactory.create 'examples/test.git'
end
teardown do
@teardown.call
end
test "formats page from Wiki#pages" do
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_git_access.rb | Ruby | mit | 179 | master | 2,206 | # ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "GitAccess" do
setup do
@access = Gollum::GitAccess.new(testpath("examples/lotr.git"))
end
test "#commit fills commit_map cache" do
assert @access.commit_map.empty?
actual = @access.repo.commits... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/helper.rb | Ruby | mit | 179 | master | 3,106 | # ~*~ encoding: utf-8 ~*~
# stdlib
require 'test/unit'
require 'fileutils'
# external
require 'rubygems'
require 'shoulda'
require 'minitest/reporters'
require 'mocha/test_unit'
require 'twitter_cldr'
require 'tempfile'
# markup
begin
require 'asciidoctor'
rescue Exception
end
# internal
require File.expand_path('... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_search.rb | Ruby | mit | 179 | master | 4,826 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), 'helper')
require File.expand_path(path)
context 'Wiki search' do
SEARCH_TEST_PAGE = <<EOF
Hobbits are small. Hobbits live in Hobbiton.
One thing Hobbits do not like is Orcs.
Something a hobbit does like is pastry.
ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ
EOF
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_hook.rb | Ruby | mit | 179 | master | 3,165 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), 'helper')
require File.expand_path(path)
context 'Hook' do
test 'registering a hook' do
begin
hook = Proc.new {}
Gollum::Hook.register(:test, :hook, &hook)
assert_same hook, Gollum::Hook.get(:test, :hook)
ensure
Gollu... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_committer.rb | Ruby | mit | 179 | master | 4,941 | # ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Wiki" do
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
end
test "normalizes commit hash" do
commit = { :message => 'abc' }
name = @wiki.default_committer_name
email... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_page.rb | Ruby | mit | 179 | master | 11,772 | # ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
bilbo_page = "<h1 class=\"editable\"><a class=\"anchor\" id=\"bilbo-baggins\" href=\"#bilbo-baggins\"></a>Bilbo Baggins</h1>\n\n<p>Bilbo Baggins is the protagonist of The <a class=\"internal present\" href=\"/Hobbit.md\">Ho... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_unicode.rb | Ruby | mit | 179 | master | 2,740 | # ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
def utf8(str)
str.respond_to?(:force_encoding) ? str.force_encoding('utf-8') : str
end
context "Unicode Support" do
setup do
@path = cloned_testpath("examples/revert.git")
@wiki = Gollum::Wiki.new(@path)
end
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_wiki.rb | Ruby | mit | 179 | master | 36,202 | # ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context "Wiki initialize" do
test "post_wiki_initialize hooks called after initializing" do
yielded = nil
begin
Gollum::Hook.register(:post_wiki_initialize, :hook) do |wiki|
yielded = wiki
end
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_file.rb | Ruby | mit | 179 | master | 2,413 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), "helper")
require File.expand_path(path)
context "File" do
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
end
test 'canonical_path method does not allow path traversal exploit' do
page_file_dir = nil
dir = 'pages'
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_macros.rb | Ruby | mit | 179 | master | 11,523 | # ~*~ encoding: utf-8 ~*~
require File.expand_path('../helper', __FILE__)
require File.expand_path('../wiki_factory', __FILE__)
class Gollum::Macro::ListArgs < Gollum::Macro
def render(*args)
args.map { |a| "@#{a}@" }.join("\n")
end
end
class Gollum::Macro::ListNamedArgs < Gollum::Macro
def render(opts)
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/assertions.rb | Ruby | mit | 179 | master | 1,197 | # ~*~ encoding: utf-8 ~*~
require 'nokogiri'
require 'nokogiri/diff'
def normalize_html(text)
text.strip!
text.gsub!(/\s\s+/,' ')
text.gsub!("\r","\n") # Windows line endings
text.gsub!(/\p{Pi}|\p{Pf}|&quot;/u,'"')
text.gsub!("\u2026",'...')
text
end
def assert_html_equal(expected, actual, msg = nil)
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/test_page_revert.rb | Ruby | mit | 179 | master | 2,116 | # ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
context 'Page Reverting' do
setup do
@path = cloned_testpath("examples/revert.git")
@wiki = Gollum::Wiki.new(@path)
end
teardown do
FileUtils.rm_rf(@path)
end
test 'reverts single commit' do
page... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/wiki_factory.rb | Ruby | mit | 179 | master | 547 | # ~*~ encoding: utf-8 ~*~
class WikiFactory
# set 'wiki-' prefix on ids for tests
class Gollum::Sanitization
def id_prefix
'wiki-'
end
end
def self.create(p, opt = {})
path = testpath(p)
Gollum::Git::Repo.init_bare(path)
Gollum::Wiki.default_options = { :universal_toc => false }.merge... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_code.rb | Ruby | mit | 179 | master | 1,285 | path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
context "Gollum::Filter::Code" do
setup do
@filter = Gollum::Filter::Code.new(Gollum::Markup.new(mock_page))
end
def filter(content)
@filter.process(@filter.extract(content))
end
end
context "Gollum::Filter::Co... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_pandoc_bib.rb | Ruby | mit | 179 | master | 1,714 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
context "Gollum::Wiki determines whether or not to use PandocBib filter" do
test "when pandoc enabled" do
wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
assert_equal false, wiki.instance_... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_yaml.rb | Ruby | mit | 179 | master | 1,587 | path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
context "Gollum::Filter::YAML" do
setup do
@page = mock_page
@markup = Gollum::Markup.new(@page)
@filter = Gollum::Filter::YAML.new(@markup)
end
def filter(content)
@filter.process(@filter.extract(content))
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_plantuml.rb | Ruby | mit | 179 | master | 1,913 | # ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))
context "Page" do
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
end
test "generate platuml img tags" do
server_url = "http://localhost:8080/png"
Gollum::Filter::PlantUML.config... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_tags.rb | Ruby | mit | 179 | master | 1,167 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
context "Gollum::Filter::Tags" do
setup do
@path = cloned_testpath('examples/page_file_dir')
@page_file_dir = 'docs'
@wiki = Gollum::Wiki.new(@path, :page_file_dir => @page_... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_critic_markup.rb | Ruby | mit | 179 | master | 4,996 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
context "Gollum::Filter::CriticMarkup" do
setup do
@filter = Gollum::Filter::CriticMarkup.new(Gollum::Markup.new(mock_page))
end
def filter(content)
@filter.process(@filter.extract(content))... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_bibtex.rb | Ruby | mit | 179 | master | 3,163 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
context "Gollum::Filter::BibTeX" do
setup do
@content = "@book{tolkien2012lord,\n title={The Lord of the Rings: One Volume},\n author={Tolkien, John Ronald Reuel},\n year={2012},\n publisher={Hou... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_emoji.rb | Ruby | mit | 179 | master | 1,057 | # Encoding: utf-8
path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
context "Gollum::Filter::Emoji" do
setup do
@filter = Gollum::Filter::Emoji.new(Gollum::Markup.new(mock_page))
page = mock_page(base_path: '/base_path')
@filter_base_path = Gollum::Filter::Emoji.new(... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | test/filter/test_toc.rb | Ruby | mit | 179 | master | 2,147 | # ~*~ encoding: utf-8 ~*~
path = File.join(File.dirname(__FILE__), "..", "helper")
require File.expand_path(path)
require 'nokogiri'
def get_toc_html(page)
string = Nokogiri::HTML::DocumentFragment.parse(page.formatted_data).at_css('div.toc > ul').to_s
string.gsub!(/(?<=\>|\A)[\n\s]+?(?=<|\Z)/, '')
string
end
c... |
github | afeld/magickly | https://github.com/afeld/magickly | magickly.gemspec | Ruby | mit | 179 | master | 978 | lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'magickly/version'
Gem::Specification.new do |s|
s.name = 'magickly'
s.version = Magickly::VERSION
s.authors = ['Aidan Feldman']
s.date = '2013-02-27'
s.description = "A service for image manipulation ... |
github | afeld/magickly | https://github.com/afeld/magickly | Rakefile | Ruby | mit | 179 | master | 965 | require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
desc "Runs tests"
task default: :spec
desc "Runs a performance test of different sigma values to tilt_shift"
task :blur_test do
file = File.join(File.dirname(__FILE__), 'spec', 'support', 'imagemagick.png')
dir = File.join(File.dirname(__FILE__), 't... |
github | afeld/magickly | https://github.com/afeld/magickly | config.ru | Ruby | mit | 179 | master | 298 | require 'rubygems'
require 'bundler'
require 'dotenv'
Bundler.require
Dotenv.load
require File.join(File.dirname(__FILE__), 'lib', 'magickly')
use Rack::Cache,
:verbose => true,
:metastore => 'file:tmp/cache/rack/meta',
:entitystore => 'file:tmp/cache/rack/body'
run Magickly::App |
github | afeld/magickly | https://github.com/afeld/magickly | Gemfile | Ruby | mit | 179 | master | 284 | source 'https://rubygems.org'
gemspec
gem 'dotenv'
gem 'rake'
gem 'rack-cache', :require => 'rack/cache'
group :development, :test do
gem 'rack-test'
gem 'rspec'
gem 'webmock'
gem 'fastimage'
end
group :production, :staging do
gem 'newrelic_rpm', :require => false
end |
github | afeld/magickly | https://github.com/afeld/magickly | lib/shortcuts.rb | Ruby | mit | 179 | master | 3,860 | Magickly.dragonfly.configure do |c|
c.job :brightness_contrast do |val|
raise ArgumentError, "argument must be of the format '<int>[%]x<int>[%]'" unless val =~ /^-?\d+%?(x-?\d+%?)?$/
process :convert, "-brightness-contrast #{val}"
end
c.job :saturation do |percentage|
raise ArgumentError, "percentage... |
github | afeld/magickly | https://github.com/afeld/magickly | lib/magickly.rb | Ruby | mit | 179 | master | 1,667 | require 'active_support/json'
require 'active_support/core_ext/object/blank'
require 'active_support/ordered_hash'
require 'sinatra/base'
require 'addressable/uri'
require 'dragonfly'
Dir["#{File.dirname(__FILE__)}/dragonfly/**/*.rb"].each {|file| require file }
Dir["#{File.dirname(__FILE__)}/magickly/*.rb"].each {|fi... |
github | afeld/magickly | https://github.com/afeld/magickly | lib/dragonfly/data_storage/remote_data_store.rb | Ruby | mit | 179 | master | 879 | require 'httparty'
require 'uri'
module Dragonfly
module DataStorage
#class Forbidden < StandardError; end
class RemoteDataStore
include Configurable
configurable_attr :url_host
def store(temp_object, opts={})
raise "Sorry friend, this datastore is read-only."
end
def... |
github | afeld/magickly | https://github.com/afeld/magickly | lib/magickly/app.rb | Ruby | mit | 179 | master | 3,461 | module Magickly
class App < Sinatra::Base
RESERVED_PARAMS = ['src']
DEMO_IMAGE = 'http://farm4.static.flickr.com/3351/3450592233_c29fde01ef_z.jpg'
enable :logging
set :root, File.join(File.dirname(__FILE__), '..')
set :homepage, "http://github.com/afeld/magickly"
set :protection, :except => :... |
github | afeld/magickly | https://github.com/afeld/magickly | spec/spec_helper.rb | Ruby | mit | 179 | master | 680 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'magickly'
require 'rack/test'
require 'sinatra'
require 'webmock/rspec'
require 'fastimage'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
# ... |
github | afeld/magickly | https://github.com/afeld/magickly | spec/requests/magickly_app_spec.rb | Ruby | mit | 179 | master | 5,854 | require 'spec_helper'
require 'uri'
describe Magickly::App do
include Rack::Test::Methods
def app
Magickly::App
end
def setup_image(host='http://www.foo.com')
@image_filename = 'imagemagick.png'
@image_url = "#{host}/#{@image_filename}"
@escaped_image_url = URI.escape @image_url, URI::REGEXP:... |
github | afeld/magickly | https://github.com/afeld/magickly | spec/unit/remote_data_store_spec.rb | Ruby | mit | 179 | master | 1,238 | require 'spec_helper'
describe Dragonfly::DataStorage::RemoteDataStore do
describe '#retrieve' do
it "should successfully make requests" do
url = "http://www.foo.com/iamgemagick.png"
stub_request(:get, url)
datastore = Dragonfly::DataStorage::RemoteDataStore.new
datastore.retrieve url
... |
github | afeld/magickly | https://github.com/afeld/magickly | spec/unit/magickly_spec.rb | Ruby | mit | 179 | master | 692 | require 'spec_helper'
describe Magickly do
describe ".process_src" do
it "retrieves an image with no options" do
image_url = "http://www.foo.com/imagemagick.png"
image_path = File.join(File.dirname(__FILE__), '..', 'support', 'imagemagick.png')
stub_request(:get, image_url).to_return(:body => F... |
github | afeld/magickly | https://github.com/afeld/magickly | spec/unit/shortcut_spec.rb | Ruby | mit | 179 | master | 2,246 | require 'spec_helper'
describe "Dragonfly shortcuts" do
before do
@image_path = File.join(File.dirname(__FILE__), '..', 'support', 'imagemagick.png')
@image = Magickly.dragonfly.fetch_file(@image_path)
end
describe :brightness_contrast do
it "should throw an error for no arguments" do
expect {... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | Gemfile | Ruby | mit | 179 | main | 1,019 | source "https://rubygems.org"
ruby "~> 3.4.0"
gem "rails", "8.1.3"
gem "ast"
gem "bootsnap", require: false
gem "content_block_tools"
gem "dartsass-rails"
gem "erb_lint"
gem "gds-api-adapters"
gem "govspeak"
gem "govuk_app_config", "~> 9.24.0"
gem "govuk_publishing_components"
gem "govuk_web_banners"
gem "htmlentiti... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | Rakefile | Ruby | mit | 179 | main | 479 | # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path("config/application", __dir__)
Rails.application.load_tasks
# Delete the current "default" rake task and redefine it. This allow us to... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/routes.rb | Ruby | mit | 179 | main | 1,122 | Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to: "smart_answers#index"
get "/healthcheck/live", to: proc { [200, {}, %w[OK]] }
get "/healthcheck/ready", to: GovukHealthcheck.rack_response(
GovukHealthcheck::Emerge... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/application.rb | Ruby | mit | 179 | main | 3,527 | require_relative "boot"
# Don't include all of rails, we don't need activerecord or action_mailer
require "action_controller/railtie"
require "active_model/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
require "govuk_publishing_components/middleware/ga4_optimise"
# Require the gems listed in ... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/ci.rb | Ruby | mit | 179 | main | 765 | # Run using bin/ci
CI.run do
step "Setup", "bin/setup --skip-server"
step "Style: Ruby", "bin/rubocop"
step "Security: Importmap vulnerability audit", "bin/importmap audit"
step "Security: Brakeman code analysis", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error"
step "Tests: Rails", "bin/ra... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/initializers/http_cache_control.rb | Ruby | mit | 179 | main | 342 | SmartAnswers::Application.configure do
config.set_http_cache_control_expiry_time = if Rails.env.development? || Rails.env.test?
false
else
true
... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/initializers/preload_working_days.rb | Ruby | mit | 179 | main | 260 | require "working_days"
# Don't preload the bank_holidays in test, so that we can stub out the calls in test setup methods.
unless Rails.env.test?
# This loads the bank holiday dates from https://www.gov.uk/bank-holidays.json
WorkingDays.bank_holidays
end |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/initializers/zeitwerk.rb | Ruby | mit | 179 | main | 348 | Rails.autoloaders.each do |autoloader|
# Flows in the shared directory use the same namespace as other Flows.
autoloader.collapse("app/flows/shared")
# These directories contain template files and may not have Zeitwerk naming
# conventions
autoloader.ignore("app/flows/**/outcomes/*")
autoloader.ignore("app... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/initializers/mime_types.rb | Ruby | mit | 179 | main | 303 | # Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register_alias "text/vnd.graphviz", :gv
Mime::Type.register "text/markdown", :govspeak |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/initializers/time_formats.rb | Ruby | mit | 179 | main | 670 | # Time Formats
# ============
#
# Adds named date and time formats for time.to_s and date.to_s
#
# To display the current date and time in all the formats in your current environment:
#
# Date::DATE_FORMATS.keys.push(:default).each{|k| puts "#{k}: #{Date.today.to_s(k)}"}
# Time::DATE_FORMATS.keys.push(:default).eac... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/initializers/dartsass.rb | Ruby | mit | 179 | main | 423 | APP_STYLESHEETS = {
"application.scss" => "application.css",
"visualise.scss" => "visualise.css",
}.freeze
all_stylesheets = APP_STYLESHEETS.merge(GovukPublishingComponents::Config.component_guide_stylesheet)
Rails.application.config.dartsass.builds = all_stylesheets
Rails.application.config.dartsass.build_options... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/environments/test.rb | Ruby | mit | 179 | main | 2,480 | require "active_support/core_ext/integer/time"
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data the... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/environments/production.rb | Ruby | mit | 179 | main | 4,398 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot for better performance and memory savings (ignor... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | config/environments/development.rb | Ruby | mit | 179 | main | 2,383 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Make code changes take effect immediately without server restart.
config.enable_reloading = true
# Do not eager load code on boot.
config.eager... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/helpers/flow_helper.rb | Ruby | mit | 179 | main | 751 | module FlowHelper
def flow
@flow ||= SmartAnswer::FlowRegistry.instance.find(params[:id])
end
def response_store
@response_store ||= begin
keys = {
user_response_keys: flow.questions.map { |node| node.name.to_s },
additional_keys: flow.additional_parameters,
}
if flow.r... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/helpers/content_item_helper.rb | Ruby | mit | 179 | main | 1,898 | module ContentItemHelper
module MethodMissingHelper
OVERRIDES = {
"calculator.services_payment_partial_name" => "pay_by_cash_only",
"calculator.holiday_entitlement_days" => 10,
"calculator.path_to_outcome" => %w[italy ceremony_country opposite_sex],
"calculator.ceremony_country" => "italy"... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/helpers/index_helper.rb | Ruby | mit | 179 | main | 718 | module IndexHelper
def title_and_url(flow_name, title)
sanitize(title) + tag.br + link_to("/#{flow_name}", flow_landing_path(flow_name), class: "govuk-link")
end
def live_link(flow_name, status)
if status == :draft
"https://draft-origin.publishing.service.gov.uk/#{flow_name}"
else
"https:... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/helpers/current_question_helper.rb | Ruby | mit | 179 | main | 556 | module CurrentQuestionHelper
def current_question_path(presenter)
if presenter.response_store
update_flow_path(id: presenter.name, node_slug: presenter.node_slug)
else
attrs = params.permit(:id).to_h.symbolize_keys
attrs[:responses] = presenter.accepted_responses.values if presenter.accepted... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/models/world_location.rb | Ruby | mit | 179 | main | 2,172 | class WorldLocation
attr_reader :title, :details, :slug
def self.cache
@cache ||= {
day: ActiveSupport::Cache::MemoryStore.new(expires_in: 24.hours),
week: ActiveSupport::Cache::MemoryStore.new(expires_in: 1.week),
}
end
def self.reset_cache
cache[:day].clear
cache[:week].clear
e... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/models/worldwide_organisation.rb | Ruby | mit | 179 | main | 1,214 | class WorldwideOrganisation
attr_reader :title, :web_url, :offices, :sponsors, :main_office, :other_offices
def self.for_location(location_slug)
organisations = GdsApi.worldwide.organisations_for_world_location(location_slug).map do |response|
new(response.to_hash) if response.present?
end
organi... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/graph_presenter.rb | Ruby | mit | 179 | main | 2,312 | class GraphPresenter
delegate :title, to: :start_node_presenter
def initialize(flow)
@flow = flow
end
def labels
Hash[@flow.nodes.map { |node| [node.name, graph_label_text(node)] }]
end
def adjacency_list
@adjacency_list ||= begin
adjacency_list = {}
@flow.questions.each do |node|... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/node_presenter.rb | Ruby | mit | 179 | main | 395 | class NodePresenter
delegate :outcome?, to: :@node
def initialize(node, flow_presenter, state = nil, _options = {})
@node = node
@flow_presenter = flow_presenter
@state = state || SmartAnswer::State.new(nil)
end
def node_name
@node.name
end
def node_slug
@node.slug
end
delegate :... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/content_item_presenter.rb | Ruby | mit | 179 | main | 1,069 | class ContentItemPresenter
include ContentItemHelper
attr_reader :flow
def initialize(flow)
@flow = flow
end
def payload
{
base_path:,
title: start_node_presenter.title,
description: start_node_presenter.meta_description,
update_type: "minor",
details: {
hidden... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/start_node_presenter.rb | Ruby | mit | 179 | main | 954 | class StartNodePresenter < NodePresenter
def initialize(node, flow_presenter, state = nil, options = {})
super(node, flow_presenter, state)
@renderer = options[:renderer] || SmartAnswer::ErbRenderer.new(
template_directory: @node.template_directory,
template_name: "start",
helpers: [SmartAns... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/checkbox_question_presenter.rb | Ruby | mit | 179 | main | 929 | class CheckboxQuestionPresenter < QuestionWithOptionsPresenter
def response_labels(values)
values.split(",").map do |value|
if value == SmartAnswer::Question::Checkbox::NONE_OPTION
"None"
else
option_attributes(value)[:label]
end
end
end
def multiple_responses?
true
... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/money_question_presenter.rb | Ruby | mit | 179 | main | 220 | class MoneyQuestionPresenter < QuestionPresenter
include SmartAnswer::FormattingHelper
def response_label(value)
format_money(SmartAnswer::Money.new(value))
end
def prefix_label
super || "£"
end
end |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/flow_presenter.rb | Ruby | mit | 179 | main | 1,559 | require "node_presenter"
class FlowPresenter
include Rails.application.routes.url_helpers
attr_reader :flow, :state
delegate :name,
:response_store,
:questions,
to: :flow
delegate :title, :meta_description, to: :start_node
delegate :node_slug, to: :current_node
delegate ... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/outcome_presenter.rb | Ruby | mit | 179 | main | 961 | class OutcomePresenter < NodePresenter
def initialize(node, flow_presenter, state = nil, options = {})
super(node, flow_presenter, state)
helpers = options[:helpers] || []
@renderer = options[:renderer] || SmartAnswer::ErbRenderer.new(
template_directory: @node.template_directory.join("outcomes"),
... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/graphviz_presenter.rb | Ruby | mit | 179 | main | 1,591 | class GraphvizPresenter < GraphPresenter
def to_gv
[
"digraph MyFlow {",
"",
"## LABELS",
"",
label_lines,
"",
"## EDGES",
"",
edge_lines,
metadata_lines,
"}",
].flatten.join("\n")
end
def label_lines
labels.map do |name, label|
... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/date_question_presenter.rb | Ruby | mit | 179 | main | 691 | class DateQuestionPresenter < QuestionPresenter
delegate :default_day,
:default_month,
:default_year,
to: :@node
def response_label(value)
if only_display_day_and_month?(value)
value.strftime("%e %B")
else
value.strftime("%e %B %Y")
end
end
def parsed_r... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/country_select_question_presenter.rb | Ruby | mit | 179 | main | 563 | class CountrySelectQuestionPresenter < QuestionPresenter
def select_options
@node.options.map do |option|
if option.slug == "usa"
{
text: "United States of America",
value: option.slug,
selected: option.slug == current_response,
}
else
{
... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/question_with_options_presenter.rb | Ruby | mit | 179 | main | 340 | class QuestionWithOptionsPresenter < QuestionPresenter
def options
@node.option_keys.map { |option_key| option_attributes(option_key) }
end
def option_attributes(key)
option = @renderer.option(key)
if option.is_a?(String)
{ label: option, value: key }
else
option.merge({ value: key }... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/salary_question_presenter.rb | Ruby | mit | 179 | main | 474 | class SalaryQuestionPresenter < QuestionPresenter
include SmartAnswer::FormattingHelper
def response_label(value)
format_salary(SmartAnswer::Salary.new(value))
end
def parsed_response
return {} if current_response.blank?
return current_response if current_response.is_a?(Hash)
salary = @node.p... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/year_question_presenter.rb | Ruby | mit | 179 | main | 284 | class YearQuestionPresenter < QuestionPresenter
def response_label(value)
value
end
def parsed_response
return {} if current_response.blank?
year = @node.parse_input(current_response)
{
year:,
}
rescue SmartAnswer::InvalidResponse
{}
end
end |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/radio_question_presenter.rb | Ruby | mit | 179 | main | 392 | class RadioQuestionPresenter < QuestionWithOptionsPresenter
def response_label(value)
options.find { |option| option[:value] == value }[:label]
end
def radio_buttons
options.map do |option|
{
text: option[:label],
value: option[:value],
hint_text: option[:hint_text],
... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/presenters/question_presenter.rb | Ruby | mit | 179 | main | 2,070 | class QuestionPresenter < NodePresenter
delegate :current_response, to: :@flow_presenter
attr_reader :params
def initialize(node, flow_presenter, state = nil, options = {})
super(node, flow_presenter, state)
@renderer = options[:renderer]
helpers = options[:helpers] || []
@renderer ||= SmartAnsw... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/services/content_item_retriever.rb | Ruby | mit | 179 | main | 394 | class ContentItemRetriever
def self.fetch(slug)
item_hash = Rails.cache.fetch("ContentItemRetriever/#{slug}", expires_in: 30.minutes) do
res = GdsApi.content_store.content_item("/#{slug}")
h = res.to_h
h["cache_control"] = res.cache_control
h
end
item_hash.with_indifferent_access
... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/services/content_block_detector.rb | Ruby | mit | 179 | main | 3,322 | # Detects and extracts content blocks from Smart Answer flows and their associated files.
#
# This class analyzes a flow's Ruby source files, calculator files, and ERB templates
# to find embedded content block references and returns the corresponding ContentBlock objects.
class ContentBlockDetector
# Regular express... |
github | alphagov/smart-answers | https://github.com/alphagov/smart-answers | app/services/content_item_syncer.rb | Ruby | mit | 179 | main | 298 | class ContentItemSyncer
def sync(flows)
flows.each do |flow|
content_item = ContentItemPresenter.new(flow)
GdsApi.publishing_api.put_content(flow.content_id, content_item.payload)
GdsApi.publishing_api.publish(flow.content_id) if flow.status == :published
end
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.