File: default.rb

package info (click to toggle)
ruby-compass 0.12.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,308 kB
  • sloc: ruby: 10,474; makefile: 42; xml: 14
file content (153 lines) | stat: -rw-r--r-- 3,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# All files in the 'lib' directory will be loaded
# before nanoc starts compiling.
require 'erb'
require 'active_support/inflector'
include Nanoc3::Helpers::LinkTo
include Nanoc3::Helpers::Capturing
include Nanoc3::Helpers::Rendering
include Nanoc3::Helpers::Breadcrumbs
include Nanoc3::Helpers::XMLSitemap

def body_class(item)
  classes = [""]
  classes += item[:classnames] || []
  classes << "demo" if item.identifier =~ /^\/examples/
  classes.join(" ")
end

def body_id(item)
  if item[:body_id]
    item[:body_id]
  elsif id = item.identifier.chop[1..-1]
    id.gsub(/\/|_/, "-")
  end
end

def body_attributes(item)
  {
    :id => body_id(item),
    :class => body_class(item)
  }
end

module Enumerable
  def sorted_and_grouped_by_name
    sort_by{|i| yield(i)}.group_by{|i| yield(i).sub(/^[^\w]/,"")[0..0].upcase}
  end
end

class Recycler
  attr_accessor :values
  attr_accessor :index
  def initialize *values
    self.values = values
    self.index = 0
  end
  def next
    values[index]
  ensure
    self.index += 1
    self.index = 0 if self.index >= self.values.size
  end
  def reset!
    self.index = 0
  end
end

def cycle(*args)
  yield Recycler.new *args
end

def default_path(item)
  item.reps.find{|r| r.name == :default}.path
end

def find(identifier)
  @items.find{|i| i.identifier == identifier}
end

def get_var(instance_var)
  instance_variable_defined?("@#{instance_var}") ? instance_variable_get("@#{instance_var}") : yield
end

def sidebar_item(item)
  if item.nil?
    nil
  elsif item[:sidebar]
    item
  else
    sidebar_item(item.parent)
  end
end

def sidebar_stylesheet(item)
  i = sidebar_item(item)
  i[:stylesheet] if i
end
  

def item_tree(item, options = {})
  crumb = item[:crumb] || item[:title]
  options[:heading_level] ||= 1 if options.fetch(:headings, true)
  child_html = ""
  if options.fetch(:depth,1) > 0
    child_opts = options.dup
    child_opts[:depth] -= 1 if child_opts.has_key?(:depth)
    child_opts[:heading_depth] -= 1 if child_opts.has_key?(:heading_depth)
    child_opts[:heading_level] += 1 if child_opts[:heading_level]
    child_opts.delete(:omit_self)
    item.children.sort_by{|c| c[:crumb] || c[:title]}.each do |child|
      next if child[:navigable] == false
      child_html << item_tree(child, child_opts)
    end
  else
    options.delete(:heading_level)
  end
  child_html = render("partials/sidebar/container", :contents => child_html) unless child_html.size == 0
  css_class = nil
  contents = unless options[:omit_self]
    item_opts = {
      :current_item => item,
      :selected => !!@item.identifier[item.identifier],
      :crumb => item[:crumb] || item[:title]
    }
    if options[:heading_level] && (options.fetch(:heading_depth, 1) > 0)
      render("partials/sidebar/heading",
        item_opts.merge(:heading => "h#{options[:heading_level]}")
      )
    else
      render("partials/sidebar/item", item_opts)
    end
  end
  %Q{#{contents}#{child_html}}
end

def tutorial_item(path)
  path = "" if path == :root
  @items.detect do |i|
    i.identifier == "/help/tutorials/#{path}"
  end
end

def compass_version
  v = Compass.version
  "#{v[:major]}.#{v[:minor]}#{"."+v[:state] if v[:state]}.#{v[:build] || v[:patch]}"
end

def long_compass_version
  require 'compass/commands'
  Compass::Commands::PrintVersion.long_output_string
end


def sprite_tutorial_links(index=false)
  string = <<-ERB
<% unless index %>
  * [Sprite Tutorial Index](/help/tutorials/spriting/)
<% end %>
<% Dir["./content/help/tutorials/spriting/**/*.markdown"].sort.each do |file| %>
  * [<%= File.basename(file, '.markdown').gsub('-', ' ').titleize %>](/help/tutorials/spriting/<%= File.basename(file, '.markdown') %>)
<% end %>
  ERB
  ::ERB.new(string).result(binding)
end