module Minimart::Web::TemplateHelper

Various methods to help with template rendering

Public Instance Methods

asset_path(resource) click to toggle source

Get the path for a web asset (CSS, JS, etc…) @param [String] resource The asset to get a path for. @return [String] The path to the asset within the Minimart web directory

# File lib/minimart/web/template_helper.rb, line 60
def asset_path(resource)
  path_to_assets = base_path_to('assets')
  Utils::Http.concat_url_fragment(path_to_assets, resource)
end
base_path_to(resource = '') click to toggle source

Build a relative path to the given resource @param [String] resource The resource to build a path for. @return [String] The relative path

# File lib/minimart/web/template_helper.rb, line 68
def base_path_to(resource = '')
  result = resource
  level.times { result = "../#{result}" }
  result
end
compiled_asset_directory() click to toggle source
# File lib/minimart/web/template_helper.rb, line 53
def compiled_asset_directory
  File.join(minimart_web_directory, 'assets')
end
cookbook_dir(cookbook) click to toggle source

The path to a cookbook's HTML files @param [Minimart::Cookbook] cookbook The cookbook to get a path for @return [String] The path to the cookbook directory

# File lib/minimart/web/template_helper.rb, line 98
def cookbook_dir(cookbook)
  "cookbooks/#{cookbook.name}"
end
cookbook_download_path(cookbook) click to toggle source

The relative path to download an archived cookbook file. @param [Minimart::Cookbook] cookbook The cookbook to get a download path for @return [String] The path to the archive file

# File lib/minimart/web/template_helper.rb, line 77
def cookbook_download_path(cookbook)
  base_path_to "cookbook_files/#{cookbook.name}/#{cookbook.web_friendly_version}/#{cookbook}.tar.gz"
end
cookbook_file(cookbook) click to toggle source

The path to a cookbook show page from the root of the web directory @param [Minimart::Cookbook] cookbook The cookbook to get a path for @return [String] The path to the cookbook show page

# File lib/minimart/web/template_helper.rb, line 91
def cookbook_file(cookbook)
  "#{cookbook_dir(cookbook)}/#{cookbook.version}.html"
end
cookbook_path(cookbook) click to toggle source

The relative path to a cookbook show page @param [Minimart::Cookbook] cookbook The cookbook to get a path for @return [String] The path to the show page

# File lib/minimart/web/template_helper.rb, line 84
def cookbook_path(cookbook)
  base_path_to(cookbook_file(cookbook))
end
home_path() click to toggle source

@return [String] The relative path to the index.html file

# File lib/minimart/web/template_helper.rb, line 103
def home_path
  base_path_to 'index.html'
end
level() click to toggle source

@return [Integer] The number of directories nested under the web directory.

This is used for building relative paths.
# File lib/minimart/web/template_helper.rb, line 109
def level
  0
end
minimart_root_directory() click to toggle source
# File lib/minimart/web/template_helper.rb, line 45
def minimart_root_directory
  Minimart.root_path
end
minimart_web_directory() click to toggle source

@return [String] The path to the Minimart web directory

# File lib/minimart/web/template_helper.rb, line 41
def minimart_web_directory
  File.join(minimart_root_directory, '..', 'web')
end
platform_icon(platform) click to toggle source

Get an icon name for a given platform (amazon, centos, etc…) @param [String] platform The platform to get an icon for @return [String] The icon name

# File lib/minimart/web/template_helper.rb, line 121
def platform_icon(platform)
  case platform.downcase
  when /amazon/i     then 'aws'
  when /centos/i     then 'centos'
  when /debian/i     then 'debian'
  when /fedora/i     then 'fedora'
  when /freebsd/i    then 'freebsd'
  when /linuxmint/i  then 'linux-mint'
  when /mac_os_x/i   then 'apple'
  when /oracle/i     then 'oracle'
  when /raspbian/i   then 'raspberrypi'
  when /redhat/i     then 'redhat'
  when /solaris/i    then 'solaris'
  when /suse/i       then 'suse'
  when /ubuntu/i     then 'ubuntu'
  when /windows/i    then 'windows'
  else
    'laptop'
  end
end
raw_asset_directory() click to toggle source
# File lib/minimart/web/template_helper.rb, line 49
def raw_asset_directory
  File.join(minimart_web_directory, '_assets')
end
render_in_base_layout(&block) click to toggle source

Render a template within the base layout (layout.erb) @yield

# File lib/minimart/web/template_helper.rb, line 22
def render_in_base_layout(&block)
  template('layout.erb').render self, {}, &block
end
render_template(template_name, context = self, locals = {}) click to toggle source

Render a template @param [String] template_name The name of the template to render @param [Binding] context The context to use while rendering the template @param [Hash] locals Any local variables to use while rendering the template @return [String] The rendered template content

# File lib/minimart/web/template_helper.rb, line 16
def render_template(template_name, context = self, locals = {})
  template(template_name).render(context, locals)
end
search_path() click to toggle source

@return [String] The relative path to the cookbook search route

# File lib/minimart/web/template_helper.rb, line 114
def search_path
  "#{home_path}#search/"
end
template(template_name) click to toggle source

Build a template from the provided template name @param [String] template_name The name of the template to build @return [Tilt::ERBTemplate]

# File lib/minimart/web/template_helper.rb, line 29
def template(template_name)
  Tilt::ERBTemplate.new(template_file(template_name), :default_encoding => 'utf-8')
end
template_file(template_name) click to toggle source

The path to a given template file @param [String] template_name The template to build a path for @return [String] The path to the template file

# File lib/minimart/web/template_helper.rb, line 36
def template_file(template_name)
  File.join(minimart_web_directory, 'templates', template_name)
end