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
joshbuddy/http_router
https://github.com/joshbuddy/http_router
examples/static/config.ru
Ruby
mit
197
master
783
# static serving example require 'http_router' base = File.expand_path(File.dirname(__FILE__)) run HttpRouter.new { add('/favicon.ico').static("#{base}/favicon.ico") # from a single file add('/images').static("#{base}/images") # or from a directory } # $ curl -I http://localhost:3000/favicon.ico # =...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
benchmarks/generation_bm.rb
Ruby
mit
197
master
2,959
require 'rubygems' require 'rbench' #require 'lib/usher' require 'usher' u = Usher.new(:generator => Usher::Util::Generators::URL.new) u.add_route('/simple') .name(:simple) u.add_route('/simple/:variable') ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
benchmarks/rec2.rb
Ruby
mit
197
master
2,418
require 'rubygems' require 'rbench' $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'http_router' #require 'http_router' u = HttpRouter.new #puts Benchmark.measure { # ('aa'..'nn').each do |first| # ('a'..'n').each do |second| # u.add("/#{first}/#{second}").to {|env| [200, {'Conte...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
benchmarks/rack_mount.rb
Ruby
mit
197
master
1,275
require 'rubygems' require 'rbench' require 'rack' require 'rack/mount' #require '../usher/lib/usher' $: << 'lib' require 'http_router' set = Rack::Mount::RouteSet.new do |set| set.add_route(proc{|env| [200, {'Content-type'=>'text/html'}, []]}, {:path => '/simple'}, {}, :simple) set.add_route(proc{|env| [200, {'Co...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
benchmarks/recognition_bm.rb
Ruby
mit
197
master
865
require 'rubygems' require 'rbench' require 'usher' u = Usher.new(:generator => Usher::Util::Generators::URL.new) u.add_route('/simple') u.add_route('/simple/again') u.add_route('/simple/again/and/again') u.add_route('/dynamic/:variable') u.add_route('/rails/:controller/:action/:id') u.add_route('/greedy/{!greed,.*}')...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
benchmarks/gen2.rb
Ruby
mit
197
master
2,175
require 'rubygems' require 'rbench' #require 'lib/usher' $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'http_router' u = HttpRouter.new u.add('/simple') .name(:simple).to{} u.add('/simple/:variable') ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
benchmarks/rack_recognition_bm.rb
Ruby
mit
197
master
1,654
require 'rubygems' require 'rbench' require '../usher/lib/usher' u = Usher::Interface.for(:rack) u.add('/simple').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]}) u.add('/simple/again').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]}) u.add('/simple/again/and/again').to(proc{|env| [200, {'Content-type'...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/test_recognition.rb
Ruby
mit
197
master
1,232
class TestRecognition < MiniTest::Unit::TestCase if //.respond_to?(:names) eval <<-EOT def test_match_path_with_groups r = router { add(%r{/(?<year>\\d{4})/(?<month>\\d{2})/(?<day>\\d{2})/?}) } assert_route r, "/1234/23/56", {:year => "1234", :month => "23", :day => "56"} end EOT end ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/generation.rb
Ruby
mit
197
master
991
require 'json' require "#{File.dirname(__FILE__)}/generic" class GenerationTest < AbstractTest def run_tests @tests.map(&:case).each do |(expected_result, name, oargs)| oargs = [oargs] unless oargs.is_a?(Array) oargs.compact! oargs.map!{|a| a.is_a?(Hash) ? Hash[a.map{|k,v| [k.to_sym, v]}] : a } ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/test_trailing_slash.rb
Ruby
mit
197
master
670
class TestVariable < MiniTest::Unit::TestCase def test_ignore_trailing_slash assert_route router.add('/test'), '/test/' end def test_ignore_trailing_slash_enabled router(:ignore_trailing_slash => false).add('/test/?') assert_route nil, '/test/' end def test_capture_with_trailing_slash assert...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/recognition.rb
Ruby
mit
197
master
1,873
require "#{File.dirname(__FILE__)}/generic" class RecognitionTest < AbstractTest def run_tests @tests.map(&:case).each do |(name, req, params)| env = case req when String Rack::MockRequest.env_for(req) when Hash e = Rack::MockRequest.env_for(req['path']) e['REQUEST_METHOD...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/generic.rb
Ruby
mit
197
master
3,048
require 'json' class AbstractTest def self.run(file) contents = File.read(file) tests = [] test = nil num = 0 contents.each_line do |line| begin case line when /^#/, /^\s*$/ # skip when /^( |\t)/ test.add_test(line, num) else if...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/test_misc.rb
Ruby
mit
197
master
4,807
class TestMisc < MiniTest::Unit::TestCase def test_cloning r1 = HttpRouter.new { add('/test', :name => :test_route).to(:test) } r2 = r1.clone r2.add('/test2', :name => :test).to(:test2) assert_equal 2, r2.routes.size matches, other_methods = r1.recognize(Rack::Request.new(Rack::MockRequest.env_...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/test_mounting.rb
Ruby
mit
197
master
2,927
class TestMounting < MiniTest::Unit::TestCase def setup @r1 = HttpRouter.new @r2 = HttpRouter.new @r2.add("/bar", :name => :test).to{|env| [200, {}, []]} end def test_url_mount_for_child_route route = @r1.add("/foo").to(@r2) assert_equal "/foo", @r2.url_mount.url assert_equal "/foo/bar", ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/helper.rb
Ruby
mit
197
master
2,595
# encoding: utf-8 require 'minitest/autorun' require 'phocus' class HttpRouter module RouteHelper def default_destination to proc {|env| ::Rack::Response.new("Routing to #{object_id}").finish} self end end end class MiniTest::Unit::TestCase def router(opts = nil, &blk) @router ||= HttpRo...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
test/rack/test_route.rb
Ruby
mit
197
master
1,367
class TestRouteExtensions < MiniTest::Unit::TestCase def test_redirect router.get("/index.html").redirect("/") response = router.call(Rack::MockRequest.env_for("/index.html")) assert_header({'Location' => '/'}, response) assert_status 302, response end def test_redirect_with_params router.ge...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router.rb
Ruby
mit
197
master
12,223
require 'set' require 'rack' require 'uri' require 'cgi' require 'url_mount' require 'http_router/node' require 'http_router/request' require 'http_router/response' require 'http_router/route' require 'http_router/generator' require 'http_router/route_helper' require 'http_router/generation_helper' require 'http_router...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/response.rb
Ruby
mit
197
master
309
class HttpRouter class Response < Struct.new(:request, :path) attr_reader :params def initialize(request, path) super(request, path) @params = path.hashify_params(request.params) end def route path.route end def param_values request.params end end end
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/regex_route_generation.rb
Ruby
mit
197
master
242
class HttpRouter module RegexRouteGeneration def url_with_params(*a) url_args_processing(a) do |args, options| respond_to?(:raw_url) or raise InvalidRouteException raw_url(args, options) end end end end
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node.rb
Ruby
mit
197
master
3,360
class HttpRouter class Node autoload :Root, 'http_router/node/root' autoload :Glob, 'http_router/node/glob' autoload :GlobRegex, 'http_router/node/glob_regex' autoload :Variable, 'http_router/node/variable' autoload :Regex, 'http_rou...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/request.rb
Ruby
mit
197
master
746
class HttpRouter class Request attr_accessor :path, :params, :rack_request, :extra_env, :continue, :passed_with, :called attr_reader :acceptable_methods alias_method :rack, :rack_request alias_method :called?, :called def initialize(path, rack_request) @rack_request = rack_request @pa...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/route_helper.rb
Ruby
mit
197
master
3,066
class HttpRouter module RouteHelper def path @route.path_for_generation end def path=(path) @original_path = path if path.respond_to?(:[]) and path[/[^\\]\*$/] @match_partially = true @path_for_generation = path[0..path.size - 2] else @path_for_generation =...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/generation_helper.rb
Ruby
mit
197
master
481
class HttpRouter module GenerationHelper def max_param_count @generator.max_param_count end def url(*args) @generator.url(*args) rescue InvalidRouteException nil end def url_ns(*args) @generator.url_ns(*args) rescue InvalidRouteException nil end def...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/route.rb
Ruby
mit
197
master
972
require 'set' class HttpRouter class Route # The list of HTTP request methods supported by HttpRouter. VALID_HTTP_VERBS = %w{GET POST PUT DELETE HEAD OPTIONS TRACE PATCH OPTIONS LINK UNLINK} VALID_HTTP_VERBS_WITHOUT_GET = VALID_HTTP_VERBS - %w{GET} attr_reader :default_values, :other_hosts, :paths, ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/generator.rb
Ruby
mit
197
master
5,282
class HttpRouter class Generator SCHEME_PORTS = {'http' => 80, 'https' => 443} class PathGenerator attr_reader :path attr_accessor :param_names def initialize(route, path, validation_regex = nil) @route = route @path = path.dup @param_names = [] if path.is_a?...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/regex.rb
Ruby
mit
197
master
1,615
class HttpRouter class Node class Regex < Node alias_method :node_to_code, :to_code attr_reader :matcher, :splitting_indicies, :capturing_indicies, :ordered_indicies def initialize(router, parent, matcher, capturing_indicies, splitting_indicies = nil) @matcher, @capturing_indicies, @spl...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/path.rb
Ruby
mit
197
master
2,266
class HttpRouter class Node class Path < Node attr_reader :route, :param_names, :dynamic, :path alias_method :dynamic?, :dynamic def initialize(router, parent, route, path, param_names = []) @route, @path, @param_names, @dynamic = route, path, param_names, !param_names.empty? @ro...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/free_regex.rb
Ruby
mit
197
master
1,063
class HttpRouter class Node class FreeRegex < Node attr_reader :matcher def initialize(router, parent, matcher) @matcher = matcher super(router, parent) end def to_code id = root.next_counter "whole_path#{id} = \"/\#{request.joined_path}\" if match ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/glob_regex.rb
Ruby
mit
197
master
801
class HttpRouter class Node class GlobRegex < Glob attr_reader :matcher def initialize(router, parent, matcher) @matcher = matcher super router, parent end def usable?(other) other.class == self.class && other.matcher == matcher end def to_code ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/spanning_regex.rb
Ruby
mit
197
master
784
class HttpRouter class Node class SpanningRegex < Regex def to_code params_count = @ordered_indicies.size whole_path_var = "whole_path#{root.next_counter}" "#{whole_path_var} = request.joined_path if match = #{@matcher.inspect}.match(#{whole_path_var}) and match.begin(0).zero...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/user_agent.rb
Ruby
mit
197
master
205
class HttpRouter class Node class UserAgent < AbstractRequestNode def initialize(router, parent, user_agents) super(router, parent, user_agents, :user_agent) end end end end
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/lookup.rb
Ruby
mit
197
master
926
class HttpRouter class Node class Lookup < Node def initialize(router, parent) @map = {} super(router, parent) end def add(part) Node.new(@router, self, @map[part] ||= []) end def usable?(other) other.class == self.class end def inspect_...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/root.rb
Ruby
mit
197
master
5,196
class HttpRouter class Node class Root < Node attr_reader :methods_module, :compiled alias_method :compiled?, :compiled def initialize(router) super(router, nil) @counter, @methods_module = 0, Module.new end def uncompile instance_eval "undef :call; def call(...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/variable.rb
Ruby
mit
197
master
339
class HttpRouter class Node class Variable < Node def usable?(other) other.class == self.class end def to_code "unless request.path_finished? request.params << request.path.shift #{super} request.path.unshift request.params.pop end" en...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/abstract_request_node.rb
Ruby
mit
197
master
835
class HttpRouter class Node class AbstractRequestNode < Node attr_reader :request_method, :tests def initialize(route, parent, tests, request_method) @request_method = request_method @tests = case tests when Array then tests when Set then tests.to_a else ...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/glob.rb
Ruby
mit
197
master
471
class HttpRouter class Node class Glob < Node alias_method :node_to_code, :to_code def usable?(other) other.class == self.class end def to_code id = root.next_counter "request.params << (globbed_params#{id} = []) until request.path.empty? glob...
github
joshbuddy/http_router
https://github.com/joshbuddy/http_router
lib/http_router/node/request_method.rb
Ruby
mit
197
master
449
class HttpRouter class Node class RequestMethod < AbstractRequestNode def initialize(router, parent, request_methods) super(router, parent, request_methods, :request_method) end def to_code "if #{@tests.map { |test| "#{test.inspect} === request.rack_request.#{request_method}" } ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
gammo.gemspec
Ruby
mit
197
master
1,028
require_relative 'lib/gammo/version' Gem::Specification.new do |spec| spec.name = "gammo" spec.version = Gammo::VERSION spec.authors = ["namusyaka"] spec.email = ["namusyaka@gmail.com"] spec.summary = %q{An HTML parser which implements WHATWG parsing algorithm.} spec.des...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
Rakefile
Ruby
mit
197
master
856
require "bundler/gem_tasks" require "rake/testtask" require 'yaml' require 'erubi' Rake::TestTask.new(:test) do |t| t.libs << "test" t.libs << "lib" t.test_files = FileList["test/**/*_test.rb"] end task default: :test def camelize(str) str.sub(/^[a-z\d]*/) { $&.capitalize }.sub(/\-[a-z]*/) { $&.slice(1..-1)....
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo.rb
Ruby
mit
197
master
388
require "gammo/version" require "gammo/parser" require "gammo/fragment_parser" module Gammo # Constructs a parser based on the input. # # @param [String] input # @param [TrueClass, FalseClass] fragment # @param [Hash] options # @return [Gammo::Parser] def self.new(input, fragment: false, **options) (...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/node.rb
Ruby
mit
197
master
7,481
require 'gammo/css_selector' require 'gammo/xpath' require 'gammo/attributes' module Gammo # Class for representing Node. # https://html.spec.whatwg.org/multipage/parsing.html#tokenization class Node # Raised if uncaught node is given for particular operations. # @!visibility private UncaughtTypeErro...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/fragment_parser.rb
Ruby
mit
197
master
2,270
require 'gammo/parser' module Gammo # Class for parsing a fragment of an HTML input and building an HTML tree. class FragmentParser < ::Gammo::Parser # Constructs a parser instance for fragment parsing algorithm. # @see https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-parsing-algorithm ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/attribute.rb
Ruby
mit
197
master
668
module Gammo # Class for representing an attribute. class Attribute attr_accessor :key, :value, :namespace # @!visibility private attr_accessor :owner_element # Constructs an attribute with the key-value pair. # @param [String] key # @param [String] value # @param [String] namespace ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector.rb
Ruby
mit
197
master
1,002
require 'gammo/css_selector/context' require 'gammo/css_selector/parser' module Gammo module CSSSelector # Class for traversing DOM tree built by Gammo::Parser by a given expresison. # @!visibility private class Traverser # Constructs an instance of Gammo::CSSSelector::Traverser. # @param [St...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath.rb
Ruby
mit
197
master
2,650
require 'gammo/xpath/parser' require 'gammo/xpath/context' module Gammo module XPath # Result types # But features related to snapshot and ordered node are not supported. # TODO: Support official result types. # - ORDERED_NODE_ITERATOR_TYPE # - UNORDERED_NODE_SNAPSHOT_TYPE # - ORDERED_N...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/attributes.rb
Ruby
mit
197
master
2,246
require 'delegate' module Gammo # Class for representing attributes. class Attributes < DelegateClass(Array) attr_accessor :owner_element def initialize(array, owner_element: nil) super(array) array.each { |attr| attr.owner_element = owner_element } @owner_element = owner_element @...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/tokenizer.rb
Ruby
mit
197
master
10,094
require 'forwardable' require 'strscan' require 'gammo/tags' require 'gammo/attribute' require 'gammo/tokenizer/tokens' require 'gammo/tokenizer/script_scanner' require 'gammo/tokenizer/escape' module Gammo # Class for implementing HTML5 tokenization algorithm. class Tokenizer include Escape # Represents ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser.rb
Ruby
mit
197
master
17,491
require 'delegate' require 'gammo/node' require 'gammo/tags' require 'gammo/tokenizer' require 'gammo/parser/node_stack' require 'gammo/parser/foreign' require 'gammo/parser/constants' require 'gammo/parser/insertion_mode_stack' module Gammo # Class for parsing an HTML input and building an HTML tree. class Parser...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/context.rb
Ruby
mit
197
master
681
module Gammo module XPath # Class for representing a context # https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Introduction # @!visibility private class Context # Defines context node, context position and context size. attr_accessor :node, :position, :size # Variables to be ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/parser.rb
Ruby
mit
197
master
32,009
# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.5.0 # from Racc grammar file "". # require 'racc/parser.rb' module Gammo module XPath class Parser < Racc::Parser module_eval(<<'...end parser.y/module_eval...', 'parser.y', 228) # 2.2 Characters (Extensible Markup Language (XML) 1.0 (Fif...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/errors.rb
Ruby
mit
197
master
246
module Gammo module XPath Error = Class.new(StandardError) ParseError = Class.new(Error) NotFoundError = Class.new(Error) UnreachableError = Class.new(Error) TypeError = Class.new(Error) end end
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/node_set.rb
Ruby
mit
197
master
1,065
require 'forwardable' module Gammo module XPath # Class for representing node set # Especially this class will be used for expressing the result of evaluation # of a given XPath expressions. class NodeSet extend Forwardable def_delegators :@nodes, :<<, :each, :each_with_index, :length, :s...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/ast/axis.rb
Ruby
mit
197
master
7,296
require 'gammo/xpath/node_set' require 'gammo/modules/subclassify' require 'gammo/tags' module Gammo module XPath module AST # Class for representing Axes. # https://www.w3.org/TR/1999/REC-xpath-19991116/#axes # @!visibility private class Axis attr_reader :node_test, :predicates ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/ast/function.rb
Ruby
mit
197
master
4,473
require 'gammo/modules/subclassify' require 'gammo/xpath/ast/value' module Gammo module XPath module AST # Class for representing XPath core function library. # https://www.w3.org/TR/1999/REC-xpath-19991116/#corelib class Function extend Subclassify # @!visibility private ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/ast/path.rb
Ruby
mit
197
master
3,105
require 'set' require 'gammo/xpath/node_set' module Gammo module XPath module AST # @!visibility private class Filter attr_reader :expr, :predicates def initialize(expr, predicates: []) @expr = expr @predicates = predicates end def evaluate(contex...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/ast/node_test.rb
Ruby
mit
197
master
2,263
require 'gammo/modules/subclassify' require 'gammo/xpath/errors' module Gammo module XPath module AST # @!visibility private class NodeTest extend Subclassify def match?(node) fail NotImplementedError, "#match must be implemented" end class Name < NodeTest ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/ast/value.rb
Ruby
mit
197
master
2,986
module Gammo module XPath module AST # Class for representing any value in Gammo::XPath internally. # This should not referred from end users, should be converted to # primitive classes or Gammo::XPath::NodeSet. # @!visibility private class Value attr_reader :value d...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/xpath/ast/expression.rb
Ruby
mit
197
master
7,161
require 'set' require 'gammo/xpath/ast/value' module Gammo module XPath module AST # Class for representing a binary expression. # @!visibility private class BinaryExpr # Constructs a binary expression by given "a" and "b". # @param [Gammo::AST::Value, Gammo::AST:NodeSet] a ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode.rb
Ruby
mit
197
master
2,486
require 'gammo/tokenizer/tokens' module Gammo class Parser class InsertionMode attr_reader :parser def initialize(parser) @parser = parser end def process case token = parser.token when Tokenizer::ErrorToken then consume(:error_token) when Token...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/node_stack.rb
Ruby
mit
197
master
439
require 'delegate' module Gammo class Parser # @!visibility private class NodeStack < DelegateClass(Array) def initialize(array) super(array) end def slice(*args) self.class.new(super) end def reverse_each_with_index len = length - 1 self.revers...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/foreign.rb
Ruby
mit
197
master
12,791
require 'gammo/node' require 'gammo/tags' module Gammo class Parser # A set of methods and contants for parsing foreign content. # Section 12.2.6.5. # @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign module Foreign # Element names that are broken out on parsing fo...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/constants.rb
Ruby
mit
197
master
2,935
module Gammo class Parser # Defines constants that do not fall into a particular concept of linguistic analysis. module Constants # The following elements have varying levels of special parsing rules. # Section 12.2.4.2. # @see https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/before_head.rb
Ruby
mit
197
master
1,189
module Gammo class Parser # Section 12.2.6.4.3 class BeforeHead < InsertionMode def character_token(token) token.data = token.data.lstrip halt true if token.data.length.zero? end def start_tag_token(token) case token.tag when Tags::Head parser.add_e...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/after_after_body.rb
Ruby
mit
197
master
762
module Gammo class Parser # Section 12.2.6.4.22. class AfterAfterBody < InsertionMode def error_token(_) # ignore the token halt true end def character_token(token) halt InBody.new(parser).process if token.data.lstrip.length.zero? end def start_tag_token...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_template.rb
Ruby
mit
197
master
2,384
module Gammo class Parser # Section 12.2.6.4.18. class InTemplate < InsertionMode def character_token(token) halt InBody.new(parser).process end def comment_token(token) halt InBody.new(parser).process end def doctype_token(token) halt InBody.new(parser)...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_cell.rb
Ruby
mit
197
master
1,571
module Gammo class Parser # Section 12.2.6.4.15. class InCell < InsertionMode def start_tag_token(token) case token.tag when Tags::Caption, Tags::Col, Tags::Colgroup, Tags::Tbody, Tags::Td, Tags::Tfoot, Tags::Th, Tags::Thead, Tags::Tr halt true unless parser.pop_until(TABLE_SCO...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/after_head.rb
Ruby
mit
197
master
1,959
module Gammo class Parser # Section 12.2.6.4.5. class AfterHead < InsertionMode def character_token(token) s = token.data.lstrip if s.length < token.data.length # add the initial whitespace to the current node. parser.add_text token.data.slice(0, token.data.length - s...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/text.rb
Ruby
mit
197
master
822
module Gammo class Parser # Section 12.2.6.4.7. class Text < InsertionMode def error_token(token) parser.open_elements.pop end def character_token(token) d = token.data n = parser.open_elements.last if n.tag == Tags::Textarea && n.first_child.nil? d...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_table.rb
Ruby
mit
197
master
3,696
module Gammo class Parser # Section 12.2.6.4.9. class InTable < InsertionMode def character_token(token) token.data = token.data.gsub("\x00", "") case parser.open_elements.last.tag when Tags::Table, Tags::Tbody, Tags::Tfoot, Tags::Thead, Tags::Tr if token.data.strip == ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/after_after_frameset.rb
Ruby
mit
197
master
733
module Gammo class Parser # Section 12.2.6.4.23. class AfterAfterFrameset < InsertionMode def comment_token(token) parser.document.append_child Node::Comment.new(data: token.data) end def character_token(token) halt InBody.new(parser).process unless token.data.gsub(/[^\s]/, ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_select_in_table.rb
Ruby
mit
197
master
1,483
module Gammo class Parser # Section 12.2.6.4.17. class InSelectInTable < InsertionMode def start_tag_token(token) case token.tag when Tags::Caption, Tags::Table, Tags::Tbody, Tags::Tfoot, Tags::Thead, Tags::Tr, Tags::Td, Tags::Th if token.instance_of?(Tokenizer::EndTagToken) &&...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/after_body.rb
Ruby
mit
197
master
1,144
require 'gammo/node' module Gammo class Parser # Section 12.2.6.4.19. class AfterBody < InsertionMode def error_token(_) # ignore the token true end def character_token(token) s = token.data.lstrip halt InBody.new(parser).process if s.length.zero? end ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/before_html.rb
Ruby
mit
197
master
1,123
module Gammo class Parser # Section 12.2.6.4.2 class BeforeHTML < InsertionMode # Ignores the token. def doctype_token(_) halt true end def character_token(token) token.data = token.data.lstrip # it's all whitespace so ignore it. halt true if token.data...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/initial.rb
Ruby
mit
197
master
5,539
require 'gammo/attribute' module Gammo class Parser # Section 12.2.6.4.1 class Initial < InsertionMode def character_token(token) token.data = token.data.lstrip # it's all whitespace so ignore it. halt true if token.data.length.zero? end def comment_token(token) ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_select.rb
Ruby
mit
197
master
2,311
module Gammo class Parser # Section 12.2.6.4.16. class InSelect < InsertionMode def character_token(token) parser.add_text token.data.gsub("\x00",'') end def start_tag_token(token) case token.tag when Tags::Html halt InBody.new(parser).process when ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_row.rb
Ruby
mit
197
master
1,683
module Gammo class Parser # Section 12.2.6.4.14. class InRow < InsertionMode def start_tag_token(token) case token.tag when Tags::Td, Tags::Th parser.clear_stack_to_context(TABLE_ROW_SCOPE) parser.add_element parser.active_formatting_elements << Node::DEFAUL...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_body.rb
Ruby
mit
197
master
19,750
module Gammo class Parser # Section 12.2.6.4.6. class InBody < InsertionMode def character_token(token) data = token.data node = parser.open_elements.last case node.tag when Tags::Pre, Tags::Listing unless node.first_child # ignore a newline at the s...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_column_group.rb
Ruby
mit
197
master
1,638
module Gammo class Parser # Section 12.2.6.4.12. class InColumnGroup < InsertionMode def character_token(token) s = token.data.lstrip if s.length < token.data.length # add the initial whitespace to the current node. parser.add_text token.data.slice(0, token.data.lengt...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_caption.rb
Ruby
mit
197
master
1,516
module Gammo class Parser # Section 12.2.6.4.10. class InCaption < InsertionMode def start_tag_token(token) case token.tag when Tags::Caption, Tags::Col, Tags::Colgroup, Tags::Tbody, Tags::Td, Tags::Tfoot, Tags::Thead, Tags::Tr # ignore the token halt true unless pars...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/after_frameset.rb
Ruby
mit
197
master
869
require 'gammo/parser/insertion_mode/after_after_frameset' module Gammo class Parser # Section 12.2.6.4.21. class AfterFrameset < InsertionMode def comment_token(token) parser.add_child Node::Comment.new(data: token.data) end def character_token(token) s = token.data.gsub(/...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_head_noscript.rb
Ruby
mit
197
master
1,292
module Gammo class Parser # 12.2.6.4.5. class InHeadNoscript < InsertionMode def doctype_token(_) # ignore the token. halt true end def comment_token(_) halt InHead.new(parser).process end def start_tag_token(token) case token.tag when Ta...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_head.rb
Ruby
mit
197
master
3,063
module Gammo class Parser # Section 12.2.6.4.4. class InHead < InsertionMode def character_token(token) s = token.data.lstrip if s.length < token.data.length # add the initial whitespace to the current node. parser.add_text token.data.slice(0, token.data.length - s.le...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_frameset.rb
Ruby
mit
197
master
1,242
module Gammo class Parser # Section 12.2.6.4.20. class InFrameset < InsertionMode def comment_token(token) parser.add_child Node::Comment.new(data: token.data) end def character_token(token) text = token.data.each_char.with_object(String.new) { |c, s| s << c if c == ?\s } ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/parser/insertion_mode/in_table_body.rb
Ruby
mit
197
master
1,723
module Gammo class Parser # Section 12.2.6.4.13. class InTableBody < InsertionMode def start_tag_token(token) case token.tag when Tags::Tr parser.clear_stack_to_context(TABLE_BODY_SCOPE) parser.add_element parser.insertion_mode = InRow halt true ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/context.rb
Ruby
mit
197
master
438
module Gammo module CSSSelector # Class for representing a context at traversing DOM. # @!visibility private class Context # Defines context node, context position and context size. attr_accessor :node, :position, :size # @param [Gammo::Node] node # @param [Integer] position ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/node_set.rb
Ruby
mit
197
master
1,128
require 'forwardable' module Gammo module CSSSelector # Class for representing node set # Especially this class will be used for expressing the result of evaluation # of a given CSS selector. class NodeSet extend Forwardable def_delegators :@nodes, :<<, :each, :each_with_object, :each_wit...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/parser.rb
Ruby
mit
197
master
19,810
# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.5.0 # from Racc grammar file "". # require 'racc/parser.rb' module Gammo module CSSSelector class Parser < Racc::Parser module_eval(<<'...end parser.y/module_eval...', 'parser.y', 197) NONASCII = /[^\0-\177]/ UNICODE = /\\[0-9a-f]{1,6}...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/ast/combinator.rb
Ruby
mit
197
master
2,666
require 'set' require 'gammo/css_selector/node_set' require 'gammo/modules/subclassify' module Gammo module CSSSelector module AST # Class for representing combinator defined in the CSS selector specification. # @!visibility private class Combinator extend Subclassify def initi...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/ast/selector.rb
Ruby
mit
197
master
2,878
require 'set' require 'delegate' require 'gammo/modules/subclassify' require 'gammo/css_selector/node_set' require 'gammo/css_selector/ast/selector/id_selector' require 'gammo/css_selector/ast/selector/attrib_selector' require 'gammo/css_selector/ast/selector/class_selector' require 'gammo/css_selector/ast/selector/pse...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/ast/selector/negation.rb
Ruby
mit
197
master
360
module Gammo module CSSSelector module AST module Selector class Negation attr_accessor :value extend Subclassify def initialize(*args) @arguments = args end def match?(context) !@arguments[0].match?(context) end ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/ast/selector/id_selector.rb
Ruby
mit
197
master
362
module Gammo module CSSSelector module AST module Selector class ID def initialize(id) @id = id end def match?(context) return false unless val = context.node.attributes[:id] val == @id || (val.split(/\s/).include?(@id)) en...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/ast/selector/pseudo_class.rb
Ruby
mit
197
master
2,964
module Gammo module CSSSelector module AST module Selector class Pseudo attr_accessor :value extend Subclassify def initialize(*args) @arguments = args end def match?(context) raise NotImplemented, "#match? must be implemen...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/ast/selector/class_selector.rb
Ruby
mit
197
master
452
module Gammo module CSSSelector module AST module Selector class Class def initialize(class_name) @class_name = class_name end def match?(context) # TODO: prefer using class_name return false unless val = context.node.attributes[:cla...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/css_selector/ast/selector/attrib_selector.rb
Ruby
mit
197
master
2,229
module Gammo module CSSSelector module AST module Selector class Attrib attr_accessor :value extend Subclassify def initialize(key:, value:, namespace_prefix: nil) @key = key @value = value @namespace_prefix = namespace_prefix ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/tokenizer/script_scanner.rb
Ruby
mit
197
master
6,233
require 'gammo/tokenizer/debug' module Gammo class Tokenizer class ScriptScanner include Debug attr_reader :scanner, :buffer, :raw_tag alias_method :debug?, :debug def initialize(scanner, raw_tag:, debug: false) @scanner = scanner @buffer = '' @raw_tag = raw_ta...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/tokenizer/entity.rb
Ruby
mit
197
master
122,667
module Gammo class Tokenizer module Entity CODEPOINT = { "AElig;": "\u{C6}", "AMP;": "\u{26}", "Aacute;": "\u{C1}", "Abreve;": "\u{102}", "Acirc;": ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/tokenizer/escape.rb
Ruby
mit
197
master
4,953
require 'gammo/tokenizer/entity' module Gammo class Tokenizer module Escape LONGEST_ENTITY_WITHOUT_SEMICOLON = 6 ESCAPE_REPLACEMENT_TABLE = { ?& => '&amp;', ?' => '&#39;', ?< => '&lt;', ?> => '&gt;', ?" => '&#34;', ?\r => '&#13;', }.freeze ...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/tokenizer/debug.rb
Ruby
mit
197
master
777
module Gammo class Tokenizer module Debug def self.included(base) base.extend ClassMethods end def debug(msg) puts msg if @debug end module ClassMethods def method_added(method) name = method.to_s return if %w[debug _debugged ?].any?(&nam...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/tokenizer/tokens.rb
Ruby
mit
197
master
2,063
require 'gammo/tokenizer/escape' module Gammo class Tokenizer class BaseToken attr_accessor :attributes, :data, :tag def initialize(data = '', attributes: [], tag: nil) @data = data @attributes = attributes @tag = tag end def concat(s) data <...
github
namusyaka/gammo
https://github.com/namusyaka/gammo
lib/gammo/modules/subclassify.rb
Ruby
mit
197
master
631
module Gammo # Class for making subclass declarable/fetchable # @!visibility private module Subclassify NotFoundError = Class.new(ArgumentError) # @!visibility private def map @map ||= {} end # @!visibility private def declare(key) look_for_superclass.map[key] = self end ...