code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def validate needs :asset_root end
Implementation of validate hook. Errors should raise exceptions or use an existing validator.
validate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
Apache-2.0
def emoji_image_filter(text) text.gsub(emoji_pattern) do |_match| emoji_image_tag(Regexp.last_match(1)) end end
Replace :emoji: with corresponding images. text - String text to replace :emoji: in. Returns a String with :emoji: replaced with images.
emoji_image_filter
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
Apache-2.0
def asset_path(name) if context[:asset_path] context[:asset_path].gsub(':file_name', emoji_filename(name)) else File.join('emoji', emoji_filename(name)) end end
The url path to link emoji sprites :file_name can be used in the asset_path as a placeholder for the sprite file name. If no asset_path is set in the context "emoji/:file_name" is used. Returns the context's asset_path or the default path if no context asset_path is given.
asset_path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
Apache-2.0
def ignored_ancestor_tags if context[:ignored_ancestor_tags] DEFAULT_IGNORED_ANCESTOR_TAGS | context[:ignored_ancestor_tags] else DEFAULT_IGNORED_ANCESTOR_TAGS end end
Return ancestor tags to stop the emojification. @return [Array<String>] Ancestor tags.
ignored_ancestor_tags
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/emoji_filter.rb
Apache-2.0
def doc @doc ||= parse_html(html) end
The Nokogiri::HTML::DocumentFragment to be manipulated. If the filter was provided a String, parse into a DocumentFragment the first time this method is called.
doc
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
Apache-2.0
def html raise InvalidDocumentException if @html.nil? && @doc.nil? @html || doc.to_html end
The String representation of the document. If a DocumentFragment was provided to the Filter, it is serialized into a String when this method is called.
html
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
Apache-2.0
def call raise NotImplementedError end
The main filter entry point. The doc attribute is guaranteed to be a Nokogiri::HTML::DocumentFragment when invoked. Subclasses should modify this document in place or extract information and add it to the context hash.
call
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
Apache-2.0
def base_url context[:base_url] || '/' end
The site's base URL provided in the context hash, or '/' when no base URL was specified.
base_url
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
Apache-2.0
def has_ancestor?(node, tags) while node = node.parent break true if tags.include?(node.name.downcase) end end
Helper method for filter subclasses used to determine if any of a node's ancestors have one of the tag names specified. node - The Node object to check. tags - An array of tag name strings to check. These should be downcase. Returns true when the node has a matching ancestor.
has_ancestor?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
Apache-2.0
def needs(*keys) missing = keys.reject { |key| context.include? key } if missing.any? raise ArgumentError, "Missing context keys for #{self.class.name}: #{missing.map(&:inspect).join ', '}" end end
Validator for required context. This will check that anything passed in contexts exists in @contexts If any errors are found an ArgumentError will be raised with a message listing all the missing contexts and the filters that require them.
needs
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/filter.rb
Apache-2.0
def http_url context[:http_url] || context[:base_url] end
HTTP url to replace. Falls back to :base_url
http_url
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/https_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/https_filter.rb
Apache-2.0
def call extensions = context.fetch( :commonmarker_extensions, DEFAULT_COMMONMARKER_EXTENSIONS ) html = if (renderer = context[:commonmarker_renderer]) unless renderer < CommonMarker::HtmlRenderer raise ArgumentError, "`commonmark_renderer` must be derived from `CommonMarker::HtmlRenderer`" end parse_options = :DEFAULT parse_options = [:UNSAFE] if context[:unsafe] render_options = [:GITHUB_PRE_LANG] render_options << :HARDBREAKS if context[:gfm] != false render_options << :UNSAFE if context[:unsafe] doc = CommonMarker.render_doc(@text, parse_options, extensions) renderer.new(options: render_options, extensions: extensions).render(doc) else options = [:GITHUB_PRE_LANG] options << :HARDBREAKS if context[:gfm] != false options << :UNSAFE if context[:unsafe] CommonMarker.render_html(@text, options, extensions) end html.rstrip! html end
Convert Markdown to HTML using the best available implementation and convert into a DocumentFragment.
call
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/markdown_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/markdown_filter.rb
Apache-2.0
def call Sanitize.clean_node!(doc, allowlist) end
Sanitize markup using the Sanitize library.
call
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/sanitization_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/sanitization_filter.rb
Apache-2.0
def allowlist allowlist = context[:allowlist] || context[:whitelist] || ALLOWLIST anchor_schemes = context[:anchor_schemes] return allowlist unless anchor_schemes allowlist = allowlist.dup allowlist[:protocols] = (allowlist[:protocols] || {}).dup allowlist[:protocols]['a'] = (allowlist[:protocols]['a'] || {}).merge('href' => anchor_schemes) allowlist end
The allowlist to use when sanitizing. This can be passed in the context hash to the filter but defaults to ALLOWLIST constant value above.
allowlist
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/sanitization_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/sanitization_filter.rb
Apache-2.0
def anchor_icon context[:anchor_icon] || '<span aria-hidden="true" class="octicon octicon-link"></span>' end
The icon that will be placed next to an anchored rendered markdown header
anchor_icon
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/toc_filter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-pipeline-2.14.3/lib/html/pipeline/toc_filter.rb
Apache-2.0
def write File.write(cache_file, @cache_log.to_json) end
TODO: Garbage performance--both the external and internal caches need access to this file. Write a proper versioned schema in the future
write
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/cache.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/cache.rb
Apache-2.0
def remote? %w[http https].include? scheme end
path is to an external server
remote?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/element.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/element.rb
Apache-2.0
def exists? return @checked_paths[absolute_path] if @checked_paths.key?(absolute_path) @checked_paths[absolute_path] = File.exist?(absolute_path) end
checks if a file exists relative to the current pwd
exists?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/element.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/element.rb
Apache-2.0
def debug(message = nil) log(:debug, message) unless message.nil? end
dumb override to play nice with Typhoeus/Ethon
debug
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/log.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/log.rb
Apache-2.0
def check_files process_files.each do |item| @external_urls.merge!(item[:external_urls]) @failures.concat(item[:failures]) end # TODO: lazy. if we're checking only external links, # we'll just trash all the failed tests. really, we should # just not run those other checks at all. if @options[:external_only] @failures = [] validate_external_urls elsif !@options[:disable_external] validate_external_urls validate_internal_urls else validate_internal_urls end end
Collects any external URLs found in a directory of files. Also collectes every failed test from process_files. Sends the external URLs to Typhoeus for batch processing.
check_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/runner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/runner.rb
Apache-2.0
def process_files if @options[:parallel].empty? files.map { |path| check_path(path) } else Parallel.map(files, @options[:parallel]) { |path| check_path(path) } end end
Walks over each implemented check and runs them on the files, in parallel.
process_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/runner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/runner.rb
Apache-2.0
def before_request(&block) @before_request ||= [] @before_request << block if block @before_request end
Set before_request callback. @example Set before_request. request.before_request { |request| p "yay" } @param [ Block ] block The block to execute. @yield [ Typhoeus::Request ] @return [ Array<Block> ] All before_request blocks.
before_request
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/runner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/runner.rb
Apache-2.0
def new_url_query_values?(uri, paths_with_queries) queries = uri.query_values.keys.join('-') domain_path = extract_domain_path(uri) if paths_with_queries[domain_path].nil? paths_with_queries[domain_path] = [queries] true elsif !paths_with_queries[domain_path].include?(queries) paths_with_queries[domain_path] << queries true else false end end
remember queries we've seen, ignore future ones
new_url_query_values?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/url_validator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/url_validator.rb
Apache-2.0
def external_link_checker(external_urls) external_urls = external_urls.sort.to_h count = external_urls.length check_text = pluralize(count, 'external link', 'external links') @logger.log :info, "Checking #{check_text}..." # Route log from Typhoeus/Ethon to our own logger Ethon.logger = @logger establish_queue(external_urls) @hydra.run end
Proofer runs faster if we pull out all the external URLs and run the checks at the end. Otherwise, we're halting the consuming process for every file during `process_files`. In addition, sorting the list lets libcurl keep connections to the same hosts alive. Finally, we'll first make a HEAD request, rather than GETing all the contents. If the HEAD fails, we'll fall back to GET, as some servers are not configured for HEAD. If we've decided to check for hashes, we must do a GET--HEAD is not available as an option.
external_link_checker
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/url_validator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/url_validator.rb
Apache-2.0
def check_hash_in_2xx_response(href, effective_url, response, filenames) return false if @options[:only_4xx] return false unless @options[:check_external_hash] return false unless (hash = hash?(href)) body_doc = create_nokogiri(response.body) unencoded_hash = Addressable::URI.unescape(hash) xpath = [%(//*[@name="#{hash}"]|/*[@name="#{unencoded_hash}"]|//*[@id="#{hash}"]|//*[@id="#{unencoded_hash}"])] # user-content is a special addition by GitHub. if URI.parse(href).host =~ /github\.com/i xpath << [%(//*[@name="user-content-#{hash}"]|//*[@id="user-content-#{hash}"])] # when linking to a file on GitHub, like #L12-L34, only the first "L" portion # will be identified as a linkable portion xpath << [%(//td[@id="#{Regexp.last_match[1]}"])] if hash =~ /\A(L\d)+/ end return unless body_doc.xpath(xpath.join('|')).empty? msg = "External link #{href} failed: #{effective_url} exists, but the hash '#{hash}' does not" add_external_issue(filenames, msg, response.code) @cache.add(href, filenames, response.code, msg) true end
Even though the response was a success, we may have been asked to check if the hash on the URL exists on the page
check_hash_in_2xx_response
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/url_validator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/url_validator.rb
Apache-2.0
def immediate_redirect? @html.xpath("//meta[@http-equiv='refresh']").attribute('content').value.start_with? '0;' rescue StandardError false end
allow any instant-redirect meta tag
immediate_redirect?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/check/favicon.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/html-proofer-3.19.4/lib/html-proofer/check/favicon.rb
Apache-2.0
def reload! config.clear_available_locales_set config.backend.reload! end
Tells the backend to reload translations. Used in situations like the Rails development environment. Backends can implement whatever strategy is useful.
reload!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n.rb
Apache-2.0
def translate!(key, **options) translate(key, **options, raise: true) end
Wrapper for <tt>translate</tt> that adds <tt>:raise => true</tt>. With this option, if no translation is found, it will raise <tt>I18n::MissingTranslationData</tt>
translate!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n.rb
Apache-2.0
def exists?(key, _locale = nil, locale: _locale, **options) locale ||= config.locale raise Disabled.new('exists?') if locale == false raise I18n::ArgumentError if key.is_a?(String) && key.empty? config.backend.exists?(locale, key, options) end
Returns true if a translation exists for a given key, otherwise returns false.
exists?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n.rb
Apache-2.0
def locale defined?(@locale) && @locale != nil ? @locale : default_locale end
The only configuration value that is not global and scoped to thread is :locale. It defaults to the default_locale.
locale
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def backend @@backend ||= Backend::Simple.new end
Returns the current backend. Defaults to +Backend::Simple+.
backend
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def default_locale @@default_locale ||= :en end
Returns the current default locale. Defaults to :'en'
default_locale
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def available_locales @@available_locales ||= nil @@available_locales || backend.available_locales end
Returns an array of locales for which translations are available. Unless you explicitly set these through I18n.available_locales= the call will be delegated to the backend.
available_locales
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def available_locales_set #:nodoc: @@available_locales_set ||= available_locales.inject(Set.new) do |set, locale| set << locale.to_s << locale.to_sym end end
Caches the available locales list as both strings and symbols in a Set, so that we can have faster lookups to do the available locales enforce check.
available_locales_set
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def available_locales_initialized? ( !!defined?(@@available_locales) && !!@@available_locales ) end
Returns true if the available_locales have been initialized
available_locales_initialized?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def clear_available_locales_set #:nodoc: @@available_locales_set = nil end
Clears the available locales set so it can be recomputed again after I18n gets reloaded.
clear_available_locales_set
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def default_separator @@default_separator ||= '.' end
Returns the current default scope separator. Defaults to '.'
default_separator
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def exception_handler @@exception_handler ||= ExceptionHandler.new end
Returns the current exception handler. Defaults to an instance of I18n::ExceptionHandler.
exception_handler
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def missing_interpolation_argument_handler @@missing_interpolation_argument_handler ||= lambda do |missing_key, provided_hash, string| raise MissingInterpolationArgument.new(missing_key, provided_hash, string) end end
Returns the current handler for situations when interpolation argument is missing. MissingInterpolationArgument will be raised by default.
missing_interpolation_argument_handler
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def load_path @@load_path ||= [] end
Allow clients to register paths providing translation data sources. The backend defines acceptable sources. E.g. the provided SimpleBackend accepts a list of paths to translation files which are either named *.rb and contain plain Ruby Hashes or are named *.yml and contain YAML data. So for the SimpleBackend clients may register translation files like this: I18n.load_path << 'path/to/locale/en.yml'
load_path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def interpolation_patterns @@interpolation_patterns ||= I18n::DEFAULT_INTERPOLATION_PATTERNS.dup end
Returns the current interpolation patterns. Defaults to I18n::DEFAULT_INTERPOLATION_PATTERNS.
interpolation_patterns
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/config.rb
Apache-2.0
def plural_keys(*args) args.empty? ? @@plural_keys : @@plural_keys[args.first] || @@plural_keys[:en] end
returns an array of plural keys for the given locale or the whole hash of locale mappings to plural keys so that we can convert from gettext's integer-index based style TODO move this information to the pluralization module
plural_keys
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/gettext.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/gettext.rb
Apache-2.0
def load_translations(*filenames) filenames = I18n.load_path if filenames.empty? filenames.flatten.each do |filename| loaded_translations = load_file(filename) yield filename, loaded_translations if block_given? end end
Accepts a list of paths to translation files. Loads translations from plain Ruby (*.rb), YAML files (*.yml), or JSON files (*.json). See #load_rb, #load_yml, and #load_json for details.
load_translations
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def store_translations(locale, data, options = EMPTY_HASH) raise NotImplementedError end
This method receives a locale, a data hash and options for storing translations. Should be implemented
store_translations
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def localize(locale, object, format = :default, options = EMPTY_HASH) if object.nil? && options.include?(:default) return options[:default] end raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime) if Symbol === format key = format type = object.respond_to?(:sec) ? 'time' : 'date' options = options.merge(:raise => true, :object => object, :locale => locale) format = I18n.t(:"#{type}.formats.#{key}", **options) end format = translate_localization_format(locale, object, format, options) object.strftime(format) end
Acts the same as +strftime+, but uses a localized version of the format string. Takes a key from the date/time formats translations as a format argument (<em>e.g.</em>, <tt>:short</tt> in <tt>:'date.formats'</tt>).
localize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def available_locales raise NotImplementedError end
Returns an array of locales for which translations are available ignoring the reserved translation meta data key :i18n.
available_locales
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def lookup(locale, key, scope = [], options = EMPTY_HASH) raise NotImplementedError end
The method which actually looks up for the translation in the store.
lookup
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def default(locale, object, subject, options = EMPTY_HASH) if options.size == 1 && options.has_key?(:default) options = {} else options = Utils.except(options, :default) end case subject when Array subject.each do |item| result = resolve(locale, object, item, options) return result unless result.nil? end and nil else resolve(locale, object, subject, options) end end
Evaluates defaults. If given subject is an Array, it walks the array and returns the first translation that can be resolved. Otherwise it tries to resolve the translation directly.
default
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def resolve(locale, object, subject, options = EMPTY_HASH) return subject if options[:resolve] == false result = catch(:exception) do case subject when Symbol I18n.translate(subject, **options.merge(:locale => locale, :throw => true)) when Proc date_or_time = options.delete(:object) || object resolve(locale, object, subject.call(date_or_time, **options)) else subject end end result unless result.is_a?(MissingTranslation) end
Resolves a translation. If the given subject is a Symbol, it will be translated with the given options. If it is a Proc then it will be evaluated. All other subjects will be returned directly.
resolve
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def pluralize(locale, entry, count) entry = entry.reject { |k, _v| k == :attributes } if entry.is_a?(Hash) return entry unless entry.is_a?(Hash) && count key = pluralization_key(entry, count) raise InvalidPluralizationData.new(entry, count, key) unless entry.has_key?(key) entry[key] end
Picks a translation from a pluralized mnemonic subkey according to English pluralization rules : - It will pick the :one subkey if count is equal to 1. - It will pick the :other subkey otherwise. - It will pick the :zero subkey in the special case where count is equal to 0 and there is a :zero subkey present. This behaviour is not standard with regards to the CLDR pluralization rules. Other backends can implement more flexible or complex pluralization rules.
pluralize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def interpolate(locale, subject, values = EMPTY_HASH) return subject if values.empty? case subject when ::String then I18n.interpolate(subject, values) when ::Array then subject.map { |element| interpolate(locale, element, values) } else subject end end
Interpolates values into a given subject. if the given subject is a string then: method interpolates "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X' # => "file test.txt opened by %{user}" if the given subject is an array then: each element of the array is recursively interpolated (until it finds a string) method interpolates ["yes, %{user}", ["maybe no, %{user}, "no, %{user}"]], :user => "bartuz" # => "["yes, bartuz",["maybe no, bartuz", "no, bartuz"]]"
interpolate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def deep_interpolate(locale, data, values = EMPTY_HASH) return data if values.empty? case data when ::String I18n.interpolate(data, values) when ::Hash data.each_with_object({}) do |(k, v), result| result[k] = deep_interpolate(locale, v, values) end when ::Array data.map do |v| deep_interpolate(locale, v, values) end else data end end
Deep interpolation deep_interpolate { people: { ann: "Ann is %{ann}", john: "John is %{john}" } }, ann: 'good', john: 'big' #=> { people: { ann: "Ann is good", john: "John is big" } }
deep_interpolate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def load_file(filename) type = File.extname(filename).tr('.', '').downcase raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true) data, keys_symbolized = send(:"load_#{type}", filename) unless data.is_a?(Hash) raise InvalidLocaleData.new(filename, 'expects it to return a hash, but does not') end data.each { |locale, d| store_translations(locale, d || {}, skip_symbolize_keys: keys_symbolized) } data end
Loads a single translations file by delegating to #load_rb or #load_yml depending on the file extension and directly merges the data to the existing translations. Raises I18n::UnknownFileType for all other file extensions.
load_file
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def load_rb(filename) translations = eval(IO.read(filename), binding, filename) [translations, false] end
Loads a plain Ruby translations file. eval'ing the file must yield a Hash containing translation data with locales as toplevel keys.
load_rb
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def load_yml(filename) begin if YAML.respond_to?(:unsafe_load_file) # Psych 4.0 way [YAML.unsafe_load_file(filename, symbolize_names: true, freeze: true), true] else [YAML.load_file(filename), false] end rescue TypeError, ScriptError, StandardError => e raise InvalidLocaleData.new(filename, e.inspect) end end
Loads a YAML translations file. The data must have locales as toplevel keys.
load_yml
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def load_json(filename) begin # Use #load_file as a proxy for a version of JSON where symbolize_names and freeze are supported. if ::JSON.respond_to?(:load_file) [::JSON.load_file(filename, symbolize_names: true, freeze: true), true] else [::JSON.parse(File.read(filename)), false] end rescue TypeError, StandardError => e raise InvalidLocaleData.new(filename, e.inspect) end end
Loads a JSON translations file. The data must have locales as toplevel keys.
load_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/base.rb
Apache-2.0
def load_file(filename) initialized = !respond_to?(:initialized?) || initialized? key = I18n::Backend::Flatten.escape_default_separator(normalized_path(filename)) old_mtime, old_digest = initialized && lookup(:i18n, key, :load_file) return if (mtime = File.mtime(filename).to_i) == old_mtime || (digest = OpenSSL::Digest::SHA256.file(filename).hexdigest) == old_digest super store_translations(:i18n, load_file: { key => [mtime, digest] }) end
Track loaded translation files in the `i18n.load_file` scope, and skip loading the file if its contents are still up-to-date.
load_file
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/cache_file.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/cache_file.rb
Apache-2.0
def normalized_path(file) return file unless path_roots path = path_roots.find(&file.method(:start_with?)) || raise(InvalidLocaleData.new(file, 'outside expected path roots')) file.sub(path, path_roots.index(path).to_s) end
Translate absolute filename to relative path for i18n key.
normalized_path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/cache_file.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/cache_file.rb
Apache-2.0
def _deep_merge(hash, other_hash) copy = hash.dup other_hash.each_pair do |k,v| value_from_other = hash[k] copy[k] = value_from_other.is_a?(Hash) && v.is_a?(Hash) ? _deep_merge(value_from_other, v) : v end copy end
This is approximately what gets used in ActiveSupport. However since we are not guaranteed to run in an ActiveSupport context it is wise to have our own copy. We underscore it to not pollute the namespace of the including class.
_deep_merge
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/chain.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/chain.rb
Apache-2.0
def fallbacks @@fallbacks ||= I18n::Locale::Fallbacks.new Thread.current[:i18n_fallbacks] || @@fallbacks end
Returns the current fallbacks implementation. Defaults to +I18n::Locale::Fallbacks+.
fallbacks
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/fallbacks.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/fallbacks.rb
Apache-2.0
def translate(locale, key, options = EMPTY_HASH) return super unless options.fetch(:fallback, true) return super if options[:fallback_in_progress] default = extract_non_symbol_default!(options) if options[:default] fallback_options = options.merge(:fallback_in_progress => true, fallback_original_locale: locale) I18n.fallbacks[locale].each do |fallback| begin catch(:exception) do result = super(fallback, key, fallback_options) unless result.nil? on_fallback(locale, fallback, key, options) if locale.to_s != fallback.to_s return result end end rescue I18n::InvalidLocale # we do nothing when the locale is invalid, as this is a fallback anyways. end end return if options.key?(:default) && options[:default].nil? return super(locale, nil, options.merge(:default => default)) if default throw(:exception, I18n::MissingTranslation.new(locale, key, options)) end
Overwrites the Base backend translate method so that it will try each locale given by I18n.fallbacks for the given locale. E.g. for the locale :"de-DE" it might try the locales :"de-DE", :de and :en (depends on the fallbacks implementation) until it finds a result with the given options. If it does not find any result for any of the locales it will then throw MissingTranslation as usual. The default option takes precedence over fallback locales only when it's a Symbol. When the default contains a String, Proc or Hash it is evaluated last after all the fallback locales have been tried.
translate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/fallbacks.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/fallbacks.rb
Apache-2.0
def normalize_flat_keys(locale, key, scope, separator) key = I18n::Backend::Flatten.normalize_flat_keys(locale, key, scope, separator) resolve_link(locale, key) end
Shortcut to I18n::Backend::Flatten.normalize_flat_keys and then resolve_links.
normalize_flat_keys
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/flatten.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/flatten.rb
Apache-2.0
def flatten_keys(hash, escape, prev_key=nil, &block) hash.each_pair do |key, value| key = escape_default_separator(key) if escape curr_key = [prev_key, key].compact.join(FLATTEN_SEPARATOR).to_sym yield curr_key, value flatten_keys(value, escape, curr_key, &block) if value.is_a?(Hash) end end
Flatten keys for nested Hashes by chaining up keys: >> { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, "i" => "j"}.wind => { "a.b.c" => "d", "a.b.e" => "f", "a.g" => "h", "i" => "j" }
flatten_keys
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/flatten.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/flatten.rb
Apache-2.0
def flatten_translations(locale, data, escape, subtree) hash = {} flatten_keys(data, escape) do |key, value| if value.is_a?(Hash) hash[key] = value if subtree else store_link(locale, key, value) if value.is_a?(Symbol) hash[key] = value end end hash end
Receives a hash of translations (where the key is a locale and the value is another hash) and return a hash with all translations flattened. Nested hashes are included in the flattened hash just if subtree is true and Symbols are automatically stored as links.
flatten_translations
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/flatten.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/flatten.rb
Apache-2.0
def translations @translations = Utils.deep_symbolize_keys(@store.keys.clone.map do |main_key| main_value = JSON.decode(@store[main_key]) main_key.to_s.split(".").reverse.inject(main_value) do |value, key| {key.to_sym => value} end end.inject{|hash, elem| Utils.deep_merge!(hash, elem)}) end
Queries the translations from the key-value store and converts them into a hash such as the one returned from loading the haml files
translations
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/key_value.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/key_value.rb
Apache-2.0
def initialized? if lazy_load? initialized_locales[I18n.locale] else super end end
Returns whether the current locale is initialized.
initialized?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def reload! if lazy_load? @initialized_locales = nil @translations = nil else super end end
Clean up translations and uninitialize all locales.
reload!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def eager_load! if lazy_load? raise UnsupportedMethod.new(__method__, self.class, "Cannot eager load translations because backend was configured with lazy_load: true.") else super end end
Eager loading is not supported in the lazy context.
eager_load!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def available_locales if lazy_load? I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) } else super end end
Parse the load path and extract all locales.
available_locales
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def init_translations file_errors = if lazy_load? initialized_locales[I18n.locale] = true load_translations_and_collect_file_errors(filenames_for_current_locale) else @initialized = true load_translations_and_collect_file_errors(I18n.load_path) end raise InvalidFilenames.new(file_errors) unless file_errors.empty? end
Load translations from files that belong to the current locale.
init_translations
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def load_translations_and_collect_file_errors(files) errors = [] load_translations(files) do |file, loaded_translations| assert_file_named_correctly!(file, loaded_translations) rescue FilenameIncorrect => e errors << e end errors end
Loads each file supplied and asserts that the file only loads translations as expected by the name. The method returns a list of errors corresponding to offending files.
load_translations_and_collect_file_errors
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def filenames_for_current_locale I18n.load_path.flatten.select do |path| LocaleExtractor.locale_from_path(path) == I18n.locale end end
Select all files from I18n load path that belong to current locale. These files must start with the locale identifier (ie. "en", "pt-BR"), followed by an "_" demarcation to separate proceeding text.
filenames_for_current_locale
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def assert_file_named_correctly!(file, translations) loaded_locales = translations.keys.map(&:to_sym) expected_locale = LocaleExtractor.locale_from_path(file) unexpected_locales = loaded_locales.reject { |locale| locale == expected_locale } raise FilenameIncorrect.new(file, expected_locale, unexpected_locales) unless unexpected_locales.empty? end
Checks if a filename is named in correspondence to the translations it loaded. The locale extracted from the path must be the single locale loaded in the translations.
assert_file_named_correctly!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/lazy_loadable.rb
Apache-2.0
def store_translations(locale, data, options = EMPTY_HASH) if I18n.enforce_available_locales && I18n.available_locales_initialized? && !I18n.locale_available?(locale) return data end locale = locale.to_sym translations[locale] ||= Concurrent::Hash.new data = Utils.deep_symbolize_keys(data) unless options.fetch(:skip_symbolize_keys, false) Utils.deep_merge!(translations[locale], data) end
Stores translations for the given locale in memory. This uses a deep merge for the translations hash, so existing translations will be overwritten by new ones only at the deepest level of the hash.
store_translations
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
Apache-2.0
def available_locales init_translations unless initialized? translations.inject([]) do |locales, (locale, data)| locales << locale unless data.size <= 1 && (data.empty? || data.has_key?(:i18n)) locales end end
Get available locales from the translations hash
available_locales
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
Apache-2.0
def reload! @initialized = false @translations = nil super end
Clean up translations hash and set initialized to false on reload!
reload!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
Apache-2.0
def lookup(locale, key, scope = [], options = EMPTY_HASH) init_translations unless initialized? keys = I18n.normalize_keys(locale, key, scope, options[:separator]) keys.inject(translations) do |result, _key| return nil unless result.is_a?(Hash) unless result.has_key?(_key) _key = _key.to_s.to_sym return nil unless result.has_key?(_key) end result = result[_key] result = resolve_entry(locale, _key, result, Utils.except(options.merge(:scope => nil), :count)) if result.is_a?(Symbol) result end end
Looks up a translation from the translations hash. Returns nil if either key is nil, or locale, scope or key do not exist as a key in the nested translations hash. Splits keys or scopes containing dots into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as <tt>%w(currency format)</tt>.
lookup
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/simple.rb
Apache-2.0
def transliterate(locale, string, replacement = nil) @transliterators ||= {} @transliterators[locale] ||= Transliterator.get I18n.t(:'i18n.transliterate.rule', :locale => locale, :resolve => false, :default => {}) @transliterators[locale].transliterate(string, replacement) end
Given a locale and a UTF-8 string, return the locale's ASCII approximation for the string.
transliterate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/transliterator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/backend/transliterator.rb
Apache-2.0
def nsgettext(msgid, msgid_plural, n = 1, separator = '|') if msgid.is_a?(Array) msgid, msgid_plural, n, separator = msgid[0], msgid[1], msgid_plural, n separator = '|' unless separator.is_a?(::String) end scope, msgid = I18n::Gettext.extract_scope(msgid, separator) default = { :one => msgid, :other => msgid_plural } I18n.t(msgid, :default => default, :count => n, :scope => scope, :separator => separator) end
Method signatures: nsgettext('Fruits|apple', 'apples', 2) nsgettext(['Fruits|apple', 'apples'], 2)
nsgettext
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/gettext/helpers.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/gettext/helpers.rb
Apache-2.0
def npgettext(msgctxt, msgid, msgid_plural, n = 1) separator = I18n::Gettext::CONTEXT_SEPARATOR if msgid.is_a?(Array) msgid_plural, msgid, n = msgid[1], [msgctxt, msgid[0]].join(separator), msgid_plural else msgid = [msgctxt, msgid].join(separator) end nsgettext(msgid, msgid_plural, n, separator) end
Method signatures: npgettext('Fruits', 'apple', 'apples', 2) npgettext('Fruits', ['apple', 'apples'], 2)
npgettext
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/gettext/helpers.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/gettext/helpers.rb
Apache-2.0
def interpolate(string, values) raise ReservedInterpolationKey.new($1.to_sym, string) if string =~ I18n.reserved_keys_pattern raise ArgumentError.new('Interpolation values must be a Hash.') unless values.kind_of?(Hash) interpolate_hash(string, values) end
Return String or raises MissingInterpolationArgument exception. Missing argument's logic is handled by I18n.config.missing_interpolation_argument_handler.
interpolate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/interpolate/ruby.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/interpolate/ruby.rb
Apache-2.0
def implementation @@implementation ||= Simple end
Returns the current locale tag implementation. Defaults to +I18n::Locale::Tag::Simple+.
implementation
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/locale/tag.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/locale/tag.rb
Apache-2.0
def tag(tag) matches = parser.match(tag) new(*matches) if matches end
Parses the given tag and returns a Tag instance if it is valid. Returns false if the given tag is not valid according to RFC 4646.
tag
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/locale/tag/rfc4646.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/i18n-1.13.0/lib/i18n/locale/tag/rfc4646.rb
Apache-2.0
def require_all(path) glob = File.join(__dir__, path, "*.rb") Dir[glob].sort.each do |f| require f end end
Require all of the Ruby files in the given directory. path - The String relative path from here to the directory. Returns nothing.
require_all
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
Apache-2.0
def env ENV["JEKYLL_ENV"] || "development" end
Public: Tells you which Jekyll environment you are building in so you can skip tasks if you need to. This is useful when doing expensive compression tasks on css and images and allows you to skip that when working in development.
env
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
Apache-2.0
def configuration(override = {}) config = Configuration.new override = Configuration[override].stringify_keys unless override.delete("skip_config_files") config = config.read_config_files(config.config_files(override)) end # Merge DEFAULTS < _config.yml < override Configuration.from(Utils.deep_merge_hashes(config, override)).tap do |obj| set_timezone(obj["timezone"]) if obj["timezone"] end end
Public: Generate a Jekyll configuration Hash by merging the default options with anything in _config.yml, and adding the given options on top. override - A Hash of config directives that override any options in both the defaults and the config file. See Jekyll::Configuration::DEFAULTS for a list of option names and their defaults. Returns the final configuration Hash.
configuration
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
Apache-2.0
def set_timezone(timezone) ENV["TZ"] = if Utils::Platforms.really_windows? Utils::WinTZ.calculate(timezone) else timezone end end
Public: Set the TZ environment variable to use the timezone specified timezone - the IANA Time Zone Returns nothing rubocop:disable Naming/AccessorMethodName
set_timezone
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
Apache-2.0
def logger @logger ||= LogAdapter.new(Stevenson.new, (ENV["JEKYLL_LOG_LEVEL"] || :info).to_sym) end
rubocop:enable Naming/AccessorMethodName Public: Fetch the logger instance for this Jekyll process. Returns the LogAdapter instance.
logger
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
Apache-2.0
def sites @sites ||= [] end
Public: An array of sites Returns the Jekyll sites created.
sites
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
Apache-2.0
def sanitized_path(base_directory, questionable_path) return base_directory if base_directory.eql?(questionable_path) clean_path = questionable_path.dup clean_path.insert(0, "/") if clean_path.start_with?("~") clean_path = File.expand_path(clean_path, "/") return clean_path if clean_path.eql?(base_directory) if clean_path.start_with?(base_directory.sub(%r!\z!, "/")) clean_path else clean_path.sub!(%r!\A\w:/!, "/") File.join(base_directory, clean_path) end end
Public: Ensures the questionable path is prefixed with the base directory and prepends the questionable path with the base directory if false. base_directory - the directory with which to prefix the questionable path questionable_path - the path we're unsure about, and want prefixed Returns the sanitized path.
sanitized_path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll.rb
Apache-2.0
def cleanup! FileUtils.rm_rf(obsolete_files) FileUtils.rm_rf(metadata_file) unless @site.incremental? end
Cleans up the site's destination directory
cleanup!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def obsolete_files out = (existing_files - new_files - new_dirs + replaced_files).to_a Jekyll::Hooks.trigger :clean, :on_obsolete, out out end
Private: The list of files and directories to be deleted during cleanup process Returns an Array of the file and directory paths
obsolete_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def existing_files files = Set.new regex = keep_file_regex dirs = keep_dirs Utils.safe_glob(site.in_dest_dir, ["**", "*"], File::FNM_DOTMATCH).each do |file| next if file =~ HIDDEN_FILE_REGEX || file =~ regex || dirs.include?(file) files << file end files end
Private: The list of existing files, apart from those included in keep_files and hidden files. Returns a Set with the file paths
existing_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def new_files @new_files ||= Set.new.tap do |files| site.each_site_file { |item| files << item.destination(site.dest) } end end
Private: The list of files to be created when site is built. Returns a Set with the file paths
new_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def new_dirs @new_dirs ||= new_files.map { |file| parent_dirs(file) }.flatten.to_set end
Private: The list of directories to be created when site is built. These are the parent directories of the files in #new_files. Returns a Set with the directory paths
new_dirs
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def parent_dirs(file) parent_dir = File.dirname(file) if parent_dir == site.dest [] else [parent_dir] + parent_dirs(parent_dir) end end
Private: The list of parent directories of a given file Returns an Array with the directory paths
parent_dirs
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def replaced_files new_dirs.select { |dir| File.file?(dir) }.to_set end
Private: The list of existing files that will be replaced by a directory during build Returns a Set with the file paths
replaced_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def keep_dirs site.keep_files.map { |file| parent_dirs(site.in_dest_dir(file)) }.flatten.to_set end
Private: The list of directories that need to be kept because they are parent directories of files specified in keep_files Returns a Set with the directory paths
keep_dirs
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/cleaner.rb
Apache-2.0
def initialize(site, label) @site = site @label = sanitize_label(label) @metadata = extract_metadata end
Create a new Collection. site - the site to which this collection belongs. label - the name of the collection Returns nothing.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/collection.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/collection.rb
Apache-2.0
def docs @docs ||= [] end
Fetch the Documents in this collection. Defaults to an empty array if no documents have been read in. Returns an array of Jekyll::Document objects.
docs
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/collection.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-3.9.3/lib/jekyll/collection.rb
Apache-2.0