Sha256: 279a48806fe3124d21e197b071180544a5e6462c6d6b51e002dfbb85c3e5d161

Contents?: true

Size: 1.56 KB

Versions: 18

Compression:

Stored size: 1.56 KB

Contents

module Perus::Server
    module Helpers
        def load_site_information
            @site_name = Server.options.site_name
            @groups = Group.all
        end

        def nav_item(path, name, li = true)
            # when hosted behind a fronting server such as nginx, path_info
            # will start with '/' not url_prefix
            adjusted_path = path
            if path.index(url_prefix) == 0
                adjusted_path = path.sub(url_prefix, '/')
            end

            # admin links are highlighted for sub pages as well as their own
            # top level page. e.g 'groups' matches '/groups/1'
            if adjusted_path.start_with?('/admin/')
                klass = request.path_info.start_with?(adjusted_path) ? 'selected' : ''
            else
                klass = request.path_info == adjusted_path ? 'selected' : ''
            end

            anchor = "<a class=\"#{klass}\" href=\"#{path}\">#{name}</a>"
            li ? "<li>#{anchor}</li>" : anchor
        end

        def command_actions
            commands = Perus::Pinger::Command.subclasses.reject(&:metric?)
            commands.reject(&:abstract?)
        end

        def command_metrics
            metrics = Perus::Pinger::Command.subclasses.select(&:metric?)
            metrics.reject(&:abstract?)
        end

        def clean_arrows(text)
            text.gsub('<', '&lt;').gsub('>', '&gt;')
        end

        def escape_quotes(text)
            text.to_s.gsub('"', '&quot;')
        end

        def url_prefix
            Server.options.url_prefix
        end
    end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
perus-0.1.20 lib/perus/server/helpers.rb
perus-0.1.19 lib/perus/server/helpers.rb
perus-0.1.18 lib/perus/server/helpers.rb
perus-0.1.17 lib/perus/server/helpers.rb
perus-0.1.16 lib/perus/server/helpers.rb
perus-0.1.15 lib/perus/server/helpers.rb
perus-0.1.14 lib/perus/server/helpers.rb
perus-0.1.13 lib/perus/server/helpers.rb
perus-0.1.12 lib/perus/server/helpers.rb
perus-0.1.11 lib/perus/server/helpers.rb
perus-0.1.10 lib/perus/server/helpers.rb
perus-0.1.9 lib/perus/server/helpers.rb
perus-0.1.8 lib/perus/server/helpers.rb
perus-0.1.7 lib/perus/server/helpers.rb
perus-0.1.6 lib/perus/server/helpers.rb
perus-0.1.5 lib/perus/server/helpers.rb
perus-0.1.4 lib/perus/server/helpers.rb
perus-0.1.3 lib/perus/server/helpers.rb