Class: Jax::Generators::MaterialGenerator

Inherits:
NamedBase
  • Object
show all
Defined in:
lib/generators/jax/material/material_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SourceRoot

#source_root

Methods included from CoffeeGenerator

included

Constructor Details

#initialize(args = [], options = [], config = {}) ⇒ MaterialGenerator

Returns a new instance of MaterialGenerator.



37
38
39
40
41
42
43
44
45
# File 'lib/generators/jax/material/material_generator.rb', line 37

def initialize(args = [], options = [], config = {})
  if args.length > 1
    super([args.shift], options, config)
    @shaders = args
  else
    super
    @shaders = []
  end
end

Class Method Details

.all_shadersObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/jax/material/material_generator.rb', line 24

def self.all_shaders
  shaders = []
  ::Rails.application.assets.each_logical_path do |path|
    if path =~ /shaders\/(.*)\/manifest.yml/
      info = (YAML.load(StringIO.new ::Rails.application.assets[path].to_s) || {}).with_indifferent_access
      info[:name] ||= $1
      info[:description] ||= ""
      shaders << info
    end
  end
  shaders.sort { |a,b| a['name'] <=> b['name'] }
end

.desc(description = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/jax/material/material_generator.rb', line 11

def self.desc(description = nil)
  # TODO This can be removed under future versions of Rails, which use ERB for Usage out of the box.
  # TODO it would help if one could configure the location of USAGE
  return super if description
  usage = source_root && File.expand_path("USAGE", File.dirname(__FILE__))

  @desc ||= if usage && File.exist?(usage)
    ERB.new(File.read(usage)).result(binding)
  else
    super
  end
end

Instance Method Details

#append_shadersObject



57
58
59
60
61
# File 'lib/generators/jax/material/material_generator.rb', line 57

def append_shaders
  # first line of array is just array header stuff, we can do without it
  options = shader_options.to_yaml.lines.to_a[1..-1].collect { |line| "  "+line }.join
  append_file relative_path, options
end

#create_resource_fileObject



53
54
55
# File 'lib/generators/jax/material/material_generator.rb', line 53

def create_resource_file
  template 'material.resource.erb', relative_path unless options[:append] and File.file?(absolute_path)
end

#prepend_lighting_shaderObject



47
48
49
50
51
# File 'lib/generators/jax/material/material_generator.rb', line 47

def prepend_lighting_shader
  unless options[:skip_lighting] or shader_selected?('lighting') or File.file?(relative_path)
    @shaders.unshift 'lighting'
  end
end