Sha256: bc05828d5a4f232bf1b03efceefe464f5f64537172e666740d4a0fd2fd0669b2

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

module BeautifulScaffoldCommonMethods
  require 'erb'

  private
  
  def namespace_for_class
    str = namespace_alone
    if not str.blank? then
      str = str.camelcase + '::'
    end
    return str
  end
  
  def namespace_for_route
    str = namespace_alone
    if not str.blank? then
      str = str.downcase + '_'
    end
    return str
  end
  
  def namespace_for_url
    str = namespace_alone
    if not str.blank? then
      str = str.downcase + '/'
    end
    return str
  end
  
  def namespace_alone
    return options[:namespace].to_s.downcase
  end

  def render_partial(path)
    source  = File.expand_path(find_in_source_paths(path.to_s))
    result = ERB.new(::File.binread(source), nil, '-').result(binding)
    return result
  end

  def model_camelize
    model.camelize
  end

  def model_pluralize
    model.pluralize
  end

  def model_class
    model.classify
  end
  
  # For the views
  def plural_table_name
    model_pluralize
  end
  def singular_table_name
    model
  end

  def available_views
    %w(index edit show new _form)
  end
  
  def attributes
    # https://raw.github.com/rails/rails/master/railties/lib/rails/generators/generated_attribute.rb
    return myattributes.map{ |a|
      require 'rails/generators/generated_attribute'
      Rails::Generators::GeneratedAttribute.new(*a.split(":"))
    }
  end

  def beautiful_attr_to_rails_attr
    newmyattributes = []
    myattributes.each{ |attr|
      a,t = attr.split(':')
      newt = t
      if t == 'richtext' then
        newt = 'text'
      elsif t == 'price' then
        newt = 'float'
      end

      newmyattributes << [a, newt].join(':')
    }

    return newmyattributes
  end

  def fulltext_attribute
    fulltext_field = []
    myattributes.each{ |attr|
      a,t = attr.split(':')
      if t == 'richtext' then
        fulltext_field << a
      end
    }
    return fulltext_field
  end

  def richtext_type
    return ["bbcode","html","text","wiki","textile","markdown"]
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
beautiful_scaffold-0.0.7 lib/generators/beautiful_scaffold_common_methods.rb
beautiful_scaffold-0.0.6 lib/generators/beautiful_scaffold_common_methods.rb