Module: SproutCore

Defined in:
lib/sproutcore/deprecated/view_helper.rb,
lib/sproutcore.rb,
lib/sproutcore/version.rb,
lib/sproutcore/buildfile.rb,
lib/buildtasks/helpers/file_rule.rb,
lib/buildtasks/helpers/file_rule_list.rb

Overview

Project: Abbot - SproutCore Build Tools Copyright: ©2009 Apple Inc.

portions copyright @2006-2011 Strobe Inc.
and contributors

Defined Under Namespace

Modules: PageHelper, RakeConstants, ViewHelperSupport, ViewHelpers Classes: FileRule, FileRuleList

Constant Summary collapse

LIBPATH =

:stopdoc:

::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
VERSION_PATH =
File.join(PATH, '..', 'VERSION.yml')
VERSION_INFO =
YAML.load_file(VERSION_PATH)
VERSION =
[VERSION_INFO[:major], VERSION_INFO[:minor], VERSION_INFO[:patch]].join('.')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#logger=(value) ⇒ Object (writeonly)

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



81
82
83
# File 'lib/sproutcore.rb', line 81

def logger=(value)
  @logger = value
end

Class Method Details

.attach_prefix(url) ⇒ Object



165
166
167
# File 'lib/sproutcore.rb', line 165

def self.attach_prefix(url)
  $script_name ? "#{$script_name}#{url}" : url
end

.build_modeObject

Returns the current build mode. The build mode is determined based on the current environment build_mode settings. Note that for backwards compatibility reasons, :development and :debug are treated as being identical.



87
88
89
90
91
92
# File 'lib/sproutcore.rb', line 87

def self.build_mode
  ret = env[:build_mode] || :production
  ret = ret.to_sym unless ret.nil?
  ret = :debug if ret == :development # backwards compatibility
  ret
end

.build_mode=(new_mode) ⇒ Object



94
95
96
97
98
99
# File 'lib/sproutcore.rb', line 94

def self.build_mode=(new_mode)
  new_mode = new_mode.to_sym
  new_mode = :debug if new_mode == :development
  env[:build_mode] = new_mode
  self.build_mode
end

.builtin_projectObject

Returns a project instance representing the builtin library



102
103
104
# File 'lib/sproutcore.rb', line 102

def self.builtin_project
  @builtin_project ||= SC::Project.new(PATH)
end

.envObject

Global variable that can store specific environmental settings. This is where you will find the build mode among other things set by sc-build.



49
50
51
52
53
54
55
56
# File 'lib/sproutcore.rb', line 49

def self.env
  @env ||= HashStruct.new(
    :build_mode => :debug,
    :buildfile_names => %w(Buildfile sc-config sc-config.rb),
    :whitelist_name => "Whitelist",
    :blacklist_name => "Blacklist"
  )
end

.env=(hash) ⇒ Object



57
# File 'lib/sproutcore.rb', line 57

def self.env=(hash); @env = HashStruct.new(hash); end

.html_jarObject



137
138
139
140
141
142
# File 'lib/sproutcore.rb', line 137

def self.html_jar
  @html_jar ||= begin
    yui_root = File.expand_path("../../vendor/sproutcore", __FILE__)
    File.join(yui_root, 'SCCompiler.jar')
  end
end

.include_target(target_name, target_path) ⇒ Object

Adds a target to be included in the project SproutCore builds.

This is useful to make additional frameworks available to SproutCore apps.



133
134
135
# File 'lib/sproutcore.rb', line 133

def self.include_target(target_name, target_path)
  include_targets << { :name => target_name, :path => target_path }
end

.include_targetsObject

Additional targets to be included in the project. Each item is a hash with :path and :name attributes



126
127
128
# File 'lib/sproutcore.rb', line 126

def self.include_targets
  @include_targets ||= []
end

.js_jarObject



144
145
146
147
148
149
# File 'lib/sproutcore.rb', line 144

def self.js_jar
  @js_jar ||= begin
    yui_root = File.expand_path("../../vendor/sproutcore", __FILE__)
    File.join(yui_root, 'lib/yuicompressor-2.4.8.jar')
  end
end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



34
35
36
# File 'lib/sproutcore.rb', line 34

def self.libpath( *args )
  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end

.load_project(path = nil, opts = {}) ⇒ Object

Attempts to load a project for the current working directory or from the passed directory location. Returns nil if no project could be detected. This is just a shorthand for creating a Project object. It is useful when using the build tools as a Ruby library



115
116
117
118
119
120
121
122
# File 'lib/sproutcore.rb', line 115

def self.load_project(path = nil, opts = {})
  path = File.expand_path(path.nil? ? Dir.pwd : path)
  if FalseClass === opts[:discover]
    SC::Project.load path, :parent => SC.builtin_project
  else # attempt to autodiscover unless disabled
    SC::Project.load_nearest_project path, :parent => SC.builtin_project
  end
end

.loggerObject

Returns a standard logger object. You can replace this with your own logger to redirect all SproutCore log output if needed. Otherwise, a logger will bre created based on your env.log_level and env.logfile options.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sproutcore.rb', line 63

def self.logger
  return @logger unless @logger.nil?

  if env[:logfile]
    @logger = Logger.new env[:logfile], 10, 1024000
  else
    @logger = Logger.new $stderr

    # if we are logging to the screen, no reason to use a std loggin fmt
    @logger.formatter = lambda do |severity, time, progname, msg|
      [severity, time.strftime("%H:%M:%S.") + "%.3d" % (time.usec / 100000), '~', msg.to_s, "\n"].join(' ')
    end
  end

  @logger.level = (env[:log_level] == :debug) ? Logger::DEBUG : ((env[:log_level] == :info) ? Logger::INFO : Logger::WARN)

  return @logger
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



42
43
44
# File 'lib/sproutcore.rb', line 42

def self.path( *args )
  args.empty? ? PATH : ::File.join(PATH, args.flatten)
end

.profile(env) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/sproutcore.rb', line 151

def self.profile(env)
  if ENV[env]
    require "ruby-prof"
    RubyProf.start
    yield
    result = RubyProf.stop
    printer = RubyProf::CallStackPrinter.new(result)
    printer.print(File.open("output.html", "w"), :min_percent => 0)
    exit!
  else
    yield
  end
end

.projectObject

Returns the current project, if defined. This is normally only set when you start sc-server in interactive mode.



108
# File 'lib/sproutcore.rb', line 108

def self.project; @project; end

.project=(project) ⇒ Object



109
# File 'lib/sproutcore.rb', line 109

def self.project=(project); @project = project; end

.versionObject

Returns the version string for the library.



26
27
28
# File 'lib/sproutcore.rb', line 26

def self.version
  VERSION
end