Module: Middleman::Features::DefaultHelpers::Helpers

Defined in:
lib/middleman/features/default_helpers.rb

Instance Method Summary collapse

Instance Method Details

#asset_path(kind, source) ⇒ Object

Padrino’s asset handling needs to pass through ours



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/middleman/features/default_helpers.rb', line 44

def asset_path(kind, source)
  return source if source =~ /^http/
  asset_folder  = case kind
    when :css    then settings.css_dir
    when :js     then settings.js_dir
    when :images then settings.images_dir
    else kind.to_s
  end
  source = source.to_s.gsub(/\s/, '')
  ignore_extension = (asset_folder.to_s == kind.to_s) # don't append extension
  source << ".#{kind}" unless ignore_extension or source =~ /\.#{kind}/
  result_path   = source if source =~ %r{^/} # absolute path
  result_path ||= asset_url(source, asset_folder)
  timestamp = asset_timestamp(result_path)
  "#{result_path}#{timestamp}"
end

#asset_url(path, prefix = "") ⇒ Object



39
40
41
# File 'lib/middleman/features/default_helpers.rb', line 39

def asset_url(path, prefix="")
  Middleman::Assets.get_url(path, prefix, request)
end


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/middleman/features/default_helpers.rb', line 10

def auto_stylesheet_link_tag(separator="/")
  path = request.path_info.dup
  path << self.class.index_file if path.match(%r{/$})
  path = path.gsub(%r{^/}, '')
  path = path.gsub(File.extname(path), '')
  path = path.gsub("/", separator)

  css_file = File.join(self.class.public, self.class.css_dir, "#{path}.css")
  sass_file = File.join(self.class.views, self.class.css_dir, "#{path}.css.sass")
  scss_file = File.join(self.class.views, self.class.css_dir, "#{path}.css.scss")
  less_file = File.join(self.class.views, self.class.css_dir, "#{path}.css.less")

  if File.exists?(css_file) || File.exists?(sass_file) || File.exists?(scss_file) || File.exists?(less_file)
    stylesheet_link_tag "#{path}.css"
  end
end

#page_classesObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/middleman/features/default_helpers.rb', line 27

def page_classes
  path = request.path_info.dup
  path << settings.index_file if path.match(%r{/$})
  path = path.gsub(%r{^/}, '')
  
  classes = []
  parts = path.split('.')[0].split('/')
  parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
  
  classes.join(' ')
end