class Darwinjs::Generators::AssetsGenerator

Public Instance Methods

create_module() click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 8
def create_module
  if is_resource?
    create_resource
  else
    create_action( ( class_path + [ file_name ] ).join( '/' ) )
  end
end

Private Instance Methods

controllers_path() click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 69
def controllers_path
  @controllers_path ||= ::Rails.root.join( 'app', 'assets', 'javascripts', 'controllers' )
end
create_action( action ) click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 28
def create_action( action )
  create_namespaces( action )
  create_controller( action )
  create_view( action )
end
create_controller( action ) click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 53
def create_controller( action )
  @js_path = action.split( '/' ).map( &:camelize ).join( '.' )
  template 'controllers/controller.coffee', controllers_path.join( "#{action}.coffee" )
end
create_namespaces( action ) click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 34
def create_namespaces( action )
  current_path = []

  namespaces_for( action ).each do |namespace|
    current_path << namespace
    namespace_dir  = current_path.join( '/' )
    namespace_file = namespace_dir + '.coffee'
    @namespace = current_path.map( &:camelize ).join( '.' )

    unless File.exists?( controllers_path.join( namespace_file ) )
      template 'controllers/namespace.coffee', controllers_path.join( namespace_file ).to_s
    end

    unless File.exists?( views_path.join( namespace_file ) )
      template 'views/namespace.coffee', views_path.join( namespace_file ).to_s
    end
  end
end
create_resource() click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 22
def create_resource
  %w[index edit show new form].each do |action|
    create_action( ( class_path + [ file_name.pluralize, action ] ).join( '/' ) )
  end
end
create_view( action ) click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 58
def create_view( action )
  @js_path = action.split( '/' ).map( &:camelize ).join( '.' )
  template 'views/view.coffee', views_path.join( "#{action}.coffee" )
end
is_resource?() click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 18
def is_resource?
  name.underscore != name
end
namespaces_for( action ) click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 63
def namespaces_for( action )
  parts = action.split( '/' )
  parts.pop
  parts
end
views_path() click to toggle source
# File lib/generators/darwinjs/assets/assets_generator.rb, line 73
def views_path
  @views_path ||= ::Rails.root.join( 'app', 'assets', 'javascripts', 'views' )
end