module Minimart::Web::TemplateHelper
Various methods to help with template rendering
Public Instance Methods
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
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
# File lib/minimart/web/template_helper.rb, line 53 def compiled_asset_directory File.join(minimart_web_directory, 'assets') end
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
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
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
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
@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
@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
# File lib/minimart/web/template_helper.rb, line 45 def minimart_root_directory Minimart.root_path end
@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
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
# File lib/minimart/web/template_helper.rb, line 49 def raw_asset_directory File.join(minimart_web_directory, '_assets') end
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 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
@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
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
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