Skip to content

Hi! I cleaned up your code for you! #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ See tutorial http://www.extjs.com/blog/2009/09/30/ext-js-on-rails-a-comprehensiv
% sudo gem install extjs-mvc

<b>Rails Installation:</b>
In <tt>environment.rb</tt>,
In <tt>environment.rb</tt>,

Rails::Initializer.run do |config|
config.gem "extjs-mvc"
end

<b>Merb installation:</b>
In <tt>config/dependencies.rb</tt>, Add extjs-mvc as a new dependency

dependency "extjs-mvc"

=== An ORM Model mixin: ExtJS::Model
Expand All @@ -31,22 +31,22 @@ fields with will be used to render the <tt>Ext.data.Record.create</tt> field-def
include ExtJS::Model

extjs_fields :exclude => [:password, :password_confirmation]
# OR

# OR
extjs_fields :name, :description

# OR
extjs_fields :only => [:name, :description] # actually the same as above

# OR
extjs_fields :additional => [:computed] # includes all database columns and an additional computed field

# OR define a column as a Hash
extjs_fields :description, :name => {"sortDir" => "ASC"}, :created_at => {"dateFormat" => "c"}

# OR render associations, association-fields will have their "mapping" property set automatically
extjs_fields :name, :description, :company => [:name, :description]

def computed
name.blank? ? login : name
end
Expand All @@ -73,7 +73,7 @@ E.g. with the following definition:

extjs_fieldset :grid, fields => [:name, :description, :company => [:name, :description]]
extjs_fieldset :combo, [:full_name]

def full_name
"#{first_name} #{name}"
end
Expand All @@ -83,7 +83,7 @@ You can get store configs for both representations with
User.extjs_record(:grid)
or
User.extjs_record(:combo)

And the corresponding data for the representations with
User.first.to_record(:grid)
or
Expand All @@ -97,7 +97,7 @@ The <tt>extjs-mvc</tt> Gem includes a framework agnostic Controller mixin which
class UsersController < ActionController::Base
include ExtJS::Controller
end

=== View Helper: ExtJS::Helpers::Component

<b>usage:</b>
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ begin
gem.add_development_dependency "shoulda"
gem.add_development_dependency "mocha"
gem.add_development_dependency "extlib"

gem.test_files = []
gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']

Expand Down
4 changes: 2 additions & 2 deletions lib/extjs-mvc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class MVC
cattr_accessor :success_property
cattr_accessor :message_property
cattr_accessor :root

require 'model/base'

# Detect orm, include appropriate mixin.
if defined?(ActiveRecord)
require 'model/active_record'
Expand Down
24 changes: 12 additions & 12 deletions lib/extjs/data/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ class Store

def initialize(*params)
options = params.extract_options!

@config = options[:config] || {}
@format = options[:format] || 'json'
@fieldset = options[:fieldset] || :default
@schema = options[:schema]
@proxy = options[:proxy] || 'http'
@writer = options[:writer]
@type = (options[:type].nil?) ? @proxy === 'direct' ? 'Ext.data.DirectStore' : "Ext.data.#{@format.capitalize}Store" : options[:type]
@type = (options[:type].nil?) ? @proxy === 'direct' ? 'Ext.data.DirectStore' : "Ext.data.#{@format.capitalize}Store" : options[:type]

@controller = self.class.get_controller(options[:controller])
@model = self.class.get_model(options[:controller], options[:model])

# Merge Reader/Proxy config
@config.merge!(reader)
@config.merge!(proxy)

@config["baseParams"] = {} if @config["baseParams"].nil?
@config["baseParams"].update("fieldset" => @fieldset)

@config["format"] = @format

# Set storeId implicitly based upon Model name if not set explicitly
Expand Down Expand Up @@ -69,7 +69,7 @@ def render(script_tag = true)
"<script>new #{@type}(#{@config.to_json});#{script}</script>"
end
end

private

def self.get_controller(name)
Expand All @@ -83,7 +83,7 @@ def self.get_controller(name)
throw NameError.new("ExtJS::Store failed with an unknown controller named '#{name.to_s}'")
end
end

def self.get_model(controller, model)
unless model.class == Class
begin
Expand All @@ -98,7 +98,7 @@ def self.get_model(controller, model)
end
model
end

def proxy
proxy = {}
if @proxy === 'direct'
Expand All @@ -117,15 +117,15 @@ def proxy
end
proxy
end
def reader

def reader
{
"successProperty" => @controller.extjs_success_property,
"root" => @controller.extjs_root,
"messageProperty" => @controller.extjs_message_property
}.merge(@schema || @model.extjs_record(@fieldset))
end


end
end
20 changes: 10 additions & 10 deletions lib/model/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
module ExtJS
module Model
module ClassMethods

def extjs_primary_key
self.primary_key.to_sym
end

def extjs_column_names
self.column_names.map(&:to_sym)
end

def extjs_columns_hash
self.columns_hash.symbolize_keys
end

##
# determine if supplied Column object is nullable
# @param {ActiveRecord::ConnectionAdapters::Column}
Expand All @@ -28,7 +28,7 @@ def extjs_allow_blank(col)
# new records have no id and thus cannot be valid
col.name == self.primary_key || col.null
end

##
# returns the default value
# @param {ActiveRecord::ConnectionAdapters::Column}
Expand All @@ -37,15 +37,15 @@ def extjs_allow_blank(col)
def extjs_default(col)
col.default
end

##
# returns the corresponding column name of the type column for a polymorphic association
# @param {String/Symbol} the id column name for this association
# @return {Symbol}
def extjs_polymorphic_type(id_column_name)
id_column_name.to_s.gsub(/_id\Z/, '_type').to_sym
end

##
# determine datatype of supplied Column object
# @param {ActiveRecord::ConnectionAdapters::Column}
Expand All @@ -65,7 +65,7 @@ def extjs_type(col)
end
type
end

##
# return a simple, normalized list of AR associations having the :name, :type and association class
# @return {Array}
Expand All @@ -74,8 +74,8 @@ def extjs_associations
@extjs_associations ||= self.reflections.inject({}) do |memo, (key, assn)|
type = (assn.macro === :has_many || assn.macro === :has_and_belongs_to_many) ? :many : assn.macro
memo[key.to_sym] = {
:name => key.to_sym,
:type => type,
:name => key.to_sym,
:type => type,
:class => assn.options[:polymorphic] ? nil : assn.class_name.constantize,
:foreign_key => assn.association_foreign_key.to_sym,
:is_polymorphic => !!assn.options[:polymorphic]
Expand Down
Loading