Class: Docs::Filter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/docs/core/filter.rb

Direct Known Subclasses

Angular::CleanHtmlFilter, Angular::CleanUrlsFilter, AttributionFilter, Backbone::CleanHtmlFilter, Bower::CleanHtmlFilter, C::CleanHtmlFilter, C::FixCodeFilter, C::FixUrlsFilter, Chai::CleanHtmlFilter, CleanHtmlFilter, CleanLocalUrlsFilter, CleanTextFilter, Clojure::CleanHtmlFilter, Coffeescript::CleanHtmlFilter, ContainerFilter, Cordova::CleanHtmlFilter, Cpp::FixUrlsFilter, Css::CleanHtmlFilter, D3::CleanHtmlFilter, Django::CleanHtmlFilter, Django::FixUrlsFilter, Dom::CleanHtmlFilter, DomEvents::CleanHtmlFilter, Ember::CleanHtmlFilter, EntriesFilter, Express::CleanHtmlFilter, Git::CleanHtmlFilter, Go::CleanHtmlFilter, Grunt::CleanHtmlFilter, Haskell::CleanHtmlFilter, Html::CleanHtmlFilter, Http::CleanHtmlFilter, InnerHtmlFilter, InternalUrlsFilter, Javascript::CleanHtmlFilter, Jquery::CleanHtmlFilter, Jquery::CleanUrlsFilter, Knockout::CleanHtmlFilter, Laravel::CleanHtmlFilter, Less::CleanHtmlFilter, Lodash::CleanHtmlFilter, Lua::CleanHtmlFilter, Marionette::CleanHtmlFilter, Markdown::CleanHtmlFilter, Maxcdn::CleanHtmlFilter, Mdn::CleanHtmlFilter, Mdn::ContributeLinkFilter, Modernizr::CleanHtmlFilter, Moment::CleanHtmlFilter, Mongoose::CleanHtmlFilter, Nginx::CleanHtmlFilter, Node::CleanHtmlFilter, NormalizePathsFilter, NormalizeUrlsFilter, Php::CleanHtmlFilter, Php::FixUrlsFilter, Php::InternalUrlsFilter, Phpunit::CleanHtmlFilter, Postgresql::CleanHtmlFilter, Postgresql::ExtractMetadataFilter, Python::CleanHtmlFilter, Rdoc::CleanHtmlFilter, Rdoc::ContainerFilter, React::CleanHtmlFilter, Redis::CleanHtmlFilter, Requirejs::CleanHtmlFilter, Rethinkdb::CleanHtmlFilter, Sass::CleanHtmlFilter, Sinon::CleanHtmlFilter, Socketio::CleanHtmlFilter, Svg::CleanHtmlFilter, Symfony::CleanHtmlFilter, TitleFilter, Underscore::CleanHtmlFilter, Xpath::CleanHtmlFilter, Yii1::CleanHtmlFilter, Yii::CleanHtmlFilter

Constant Summary collapse

SCHEME_RGX =
/\A[^:\/?#]+:/

Instance Method Summary collapse

Instance Method Details

#absolute_url_string?(str) ⇒ Boolean

Returns:

  • (Boolean)

65
66
67
# File 'lib/docs/core/filter.rb', line 65

def absolute_url_string?(str)
  str =~ SCHEME_RGX
end

#at_css(*args) ⇒ Object


7
8
9
# File 'lib/docs/core/filter.rb', line 7

def at_css(*args)
  doc.at_css(*args)
end

#at_xpath(*args) ⇒ Object


15
16
17
# File 'lib/docs/core/filter.rb', line 15

def at_xpath(*args)
  doc.at_xpath(*args)
end

#base_urlObject


19
20
21
# File 'lib/docs/core/filter.rb', line 19

def base_url
  context[:base_url]
end

#css(*args) ⇒ Object


3
4
5
# File 'lib/docs/core/filter.rb', line 3

def css(*args)
  doc.css(*args)
end

#current_urlObject


23
24
25
# File 'lib/docs/core/filter.rb', line 23

def current_url
  context[:url]
end

#fragment_url_string?(str) ⇒ Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/docs/core/filter.rb', line 57

def fragment_url_string?(str)
  str[0] == '#'
end

#initial_page?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/docs/core/filter.rb', line 51

def initial_page?
  root_page? || context[:initial_paths].include?(subpath)
end

#parse_html(html) ⇒ Object


69
70
71
72
# File 'lib/docs/core/filter.rb', line 69

def parse_html(html)
  warn "#{self.class.name} is re-parsing the document" unless ENV['RACK_ENV'] == 'test'
  super
end

#relative_url_string?(str) ⇒ Boolean

Returns:

  • (Boolean)

61
62
63
# File 'lib/docs/core/filter.rb', line 61

def relative_url_string?(str)
  !fragment_url_string?(str) && str !~ SCHEME_RGX
end

#root_page?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/docs/core/filter.rb', line 47

def root_page?
  subpath.blank? || subpath == '/' || subpath == root_path
end

#root_pathObject


31
32
33
# File 'lib/docs/core/filter.rb', line 31

def root_path
  context[:root_path]
end

#root_urlObject


27
28
29
# File 'lib/docs/core/filter.rb', line 27

def root_url
  context[:root_url]
end

#slugObject


43
44
45
# File 'lib/docs/core/filter.rb', line 43

def slug
  @slug ||= subpath.sub(/\A\//, '').remove(/\.html\z/)
end

#subpathObject


35
36
37
# File 'lib/docs/core/filter.rb', line 35

def subpath
  @subpath ||= subpath_to(current_url)
end

#subpath_to(url) ⇒ Object


39
40
41
# File 'lib/docs/core/filter.rb', line 39

def subpath_to(url)
  base_url.subpath_to url, ignore_case: true
end

#xpath(*args) ⇒ Object


11
12
13
# File 'lib/docs/core/filter.rb', line 11

def xpath(*args)
  doc.xpath(*args)
end