Module: Compass::Frameworks

Extended by:
Frameworks
Included in:
Frameworks
Defined in:
lib/compass/frameworks.rb

Defined Under Namespace

Classes: Framework

Constant Summary collapse

ALL =
[]

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



66
67
68
# File 'lib/compass/frameworks.rb', line 66

def [](name)
  ALL.detect{|f| f.name.to_s == name.to_s}
end

#detect_registrationObject



41
42
43
44
45
46
47
# File 'lib/compass/frameworks.rb', line 41

def detect_registration
  @registered = nil
  yield
  @registered
ensure
  @registered = nil
end

#discover(frameworks_directory) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/compass/frameworks.rb', line 79

def discover(frameworks_directory)
  if frameworks_directory == :defaults
    warn("The :defaults argument to Compass::Frameworks.discover is no longer necessary")
    return
  end
  frameworks_directory = Dir.new(frameworks_directory) unless frameworks_directory.is_a?(Dir)
  dirs = frameworks_directory.entries.reject{|e| e =~ /^\./}.sort_by{|n| n =~ /^_/ ? n[1..-1] : n}
  dirs.each do |framework|
    register_directory File.join(frameworks_directory.path, framework)
  end
end

#guess_gem_version(line_reference) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/compass/frameworks.rb', line 70

def guess_gem_version(line_reference)
  if line_reference =~ %r{/gems/([^/]*-[^/]*)/}
    split_at = $1.rindex("-")
    name = $1[1...split_at]
    version = $1[(split_at + 1)..-1]
    version unless name == "compass"
  end
end

#pretty_print(skip_patterns = false) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/compass/frameworks.rb', line 131

def pretty_print(skip_patterns = false)
  result = ""
  max = Compass::Frameworks::ALL.inject(0) do |gm, framework|
    fm = framework.template_directories.inject(0) do |lm,pattern|
      [lm, 7 + framework.name.size + pattern.size].max
    end
    [gm, fm].max
  end
  Compass::Frameworks::ALL.each do |framework|
    next if framework.name =~ /^_/
    result << "  * #{framework.name}\n"
    unless skip_patterns
      framework.template_directories.each do |pattern|
        result << "    - #{framework.name}/#{pattern}".ljust(max)
        if description = framework.manifest(pattern).description
          result << " - #{description}"
        end
        result << "\n"
      end
    end
  end
  result
end

#register(name, *arguments) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/compass/frameworks.rb', line 49

def register(name, *arguments)
  opts = if arguments.last.is_a?(Hash)
           arguments.last
         else
           o = {}
           arguments << o
           o
         end
  opts[:version] ||= guess_gem_version(caller[0])
  @registered = Framework.new(name, *arguments)
  if idx = ALL.index(self[name])
    ALL[idx] = @registered
  else
    ALL << @registered
  end
end

#register_directory(directory) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/compass/frameworks.rb', line 91

def register_directory(directory)
  loaders = [
    File.join(directory, "compass_init.rb"),
    File.join(directory, 'lib', File.basename(directory)+".rb"),
    File.join(directory, File.basename(directory)+".rb")
  ]
  loader = loaders.detect{|l| File.exists?(l)}
  registered_framework = detect_registration do
    require loader if loader
  end
  unless registered_framework
    register File.basename(directory), directory
  end
end

#template_exists?(template) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
110
111
112
113
# File 'lib/compass/frameworks.rb', line 106

def template_exists?(template)
  framework_name, template = template.split(%r{/}, 2)
  template ||= "project"
  if (framework = self[framework_name]) && framework.templates_directory
    return File.directory?(File.join(framework.templates_directory, template))
  end
  false
end

#template_usage(template) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/compass/frameworks.rb', line 115

def template_usage(template)
  framework_name, template = template.split(%r{/}, 2)
  framework = self[framework_name]
  template ||= "project"
  usage_file = File.join(framework.templates_directory, template, "USAGE.markdown")
  if File.exists?(usage_file)
    File.read(usage_file)
  elsif help = framework.manifest(template).help
    help
  else
    <<-END.gsub(/^ {8}/, '')
      No Usage!
    END
  end
end