Skip to content
Browse files

Improved documentation now is online here http://api.lipsiasoft.com

Refactored text_field, text_area, password_field helpers
Refactored country_select helper
Refactored ext_date_select, ext_datetime_select helpers
  • Loading branch information...
1 parent 053e263 commit 56ef3d85d9652cee95266421c4f4103c9d8f5602 Davide D'Agostino committed Feb 25, 2009
View
3 .gitignore
@@ -1,2 +1,3 @@
.DS_Store
-pkg/*
+pkg/*
+doc/*
View
8 CHANGELOG
@@ -1,3 +1,9 @@
+2008-02-25
+ * Improved documentation now is online here http://api.lipsiasoft.com
+ * Refactored text_field, text_area, password_field helpers
+ * Refactored country_select helper
+ * Refactored ext_date_select, ext_datetime_select helpers
+
2008-02-24
* Rename Js app from Lipsiadmin.app to Backend.app
* Added the possibility to reuse pages/froms/grids in windows.
@@ -19,7 +25,7 @@
* Added a pdf builder for actionmailer
* Added method missing in ActiveRecord to intercept calls to non-localized methods (eg. name instead of name_cz)
* Added utility scopes for paginate, include, search
- * Added a new literal method for prevent json to "strignify" javascripts funtctions (eg. "function() { alert('me')}".to_lt)
+ * Added a new literal method for prevent json to "strignify" javascripts funtctions (eg. "function() { alert('me')}".to_l)
* Added a new module for escape utf8 chars for servers that don't have java with utf8 fonts (it's used by pdf builder)
2008-05-21
View
45 README
@@ -1,11 +1,5 @@
-Created by Davide D'Agostino on 2008-01-11.
-Copyright 2009 Lipsiasoft s.r.l. All rights reserved.
-
-Released under the MIT license
-
==Lipsiadmin
-
Lipsiadmin is a new revolutionary admin for your projects.
Is developped by http://www.lipsiasoft.com that use it from 2 years in production enviroments.
@@ -17,34 +11,49 @@ because the aim of developper wose build in a agile way web/site apps so we use
intelligent way a mixin of <tt>old</tt> html and new ajax functions,
for example ext manage the layout of page, grids, tree and errors, but form are in html code.
+Author:: Davide D'Agostino
+Copyright:: Copyright (c) 2009 Lipsiasoft s.r.l. (http://www.lipsiasoft.com)
+License:: MIT License (http://www.opensource.org/licenses/mit-license.php)
+Api Documentation:: http://api.lipsiasoft.com
+
==Requirements
Rails 2.0
Haml 2.0
==Installation
-script/plugin install git://github.com/Lipsiasoft/lipsiadmin.git
+ script/plugin install git://github.com/Lipsiasoft/lipsiadmin.git
The version 2.9 version is an alpha relase and the gem will be aviable from 3.0
+In future you can simply do:
+
+ in config/environments.rb
+ config.gem "lipsiadmin"
+
+then (if you don't have it already)
+
+ $ rake gems:install
+
==Examples
now run script/generate and you can see some like:
-Installed Generators
- Builtin: controller, integration_test, mailer, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
- Lipsiadmin: attachment, backend, backend_page, pdf
-
-script/generate backend # Generate the base admin
-script/generate backend_page yourmodel # Generate a "scaffold" for your model
-script/generate attachment # Generate the an attachments
-script/generate pdf PdfName # Generate a new pdf document
+ Installed Generators
+ Builtin: controller, integration_test, mailer, migration, model, etc..
+ Lipsiadmin: attachment, backend, backend_page, pdf
-==Remember
+So you can do:
-That now Lipsiadmin use your current locale of environment for generate localized pages
+ $ script/generate backend # Generate the base admin
+ $ script/generate backend_page yourmodel # Generate a "scaffold" for your model
+ $ script/generate attachment # Generate the an attachments
+ $ script/generate pdf PdfName # Generate a new pdf document
==Contribute
-Please contribute in coding, patch, and submitting translation.
+Please contribute in coding, patch, and submitting translation api documentation etc...
+
+* Community can be found here:: http://groups.google.com/group/lipsiadmin
+* Api documentation can be found here:: http://api.lipsiasoft.com
View
11 Rakefile
@@ -19,8 +19,10 @@ desc 'Generate documentation for the lipsiadmin plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = 'Lipsiadmin'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README*')
+ rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object'
+ rdoc.options << '--charset' << 'utf-8'
+ rdoc.template = 'resources/rdoc/horo'
+ rdoc.rdoc_files.include('README', 'CHANGELOG')
rdoc.rdoc_files.include('lib/**/*.rb')
end
@@ -69,6 +71,11 @@ task :gemspec do
end
end
+desc "Publish the API documentation"
+task :pdoc => [:rdoc] do
+ Rake::SshDirPublisher.new("root@server1.lipsiasoft.com", "/var/www/apps/lipsiadmin/rdoc", "doc").upload
+end
+
desc "Publish the release files to RubyForge."
task :release => [ :package ] do
require 'rubyforge'
View
50 lib/access_control/authentication.rb
@@ -3,23 +3,42 @@ module AccessControl
# This provide a simple login for backend and frontend.
# Use backend_login_required in backend and
# frontend_login_requirded in frontend.
+ #
+ # Examples:
+ #
+ # class FrontendController < ApplicationController
+ # before_filter :login_frontend_required, :except => [:login]
+ # end
+ #
module Authentication
protected
+
+ # Returns true if <tt>current_account</tt> is logged and active.
def logged_in?
current_account != :false && current_account.active?
end
-
+
+ # Returns the current_account, it's an instance of <tt>Account</tt> model
def current_account
@current_account ||= (login_from_session || :false)
end
-
+
+ # Ovverride the current_account, you must provide an instance of Account Model
+ #
+ # Examples:
+ #
+ # current_account = Account.last
+ #
def current_account=(new_account)
session[:account] = (new_account.nil? || new_account.is_a?(Symbol)) ? nil : new_account.id
@current_account = new_account
end
+ # Returns true if the <tt>current_account</tt> is allowed to see the requested
+ # controller/action.
+ #
+ # For configure this role please refer to: <tt>Lipsiadmin::AccessControl::Base</tt>
def allowed?
-
allowed = current_account.maps.collect(&:allowed)[0]
denied = current_account.maps.collect(&:denied)[0]
@@ -36,36 +55,49 @@ def allowed?
return allow && !deny
end
+ # Returns a helper to pass in a <tt>before_filter</tt> for check if
+ # an account are: <tt>logged_in?</tt> and <tt>allowed?</tt>
+ #
+ # By default this method is used in BackendController so is not necessary
def backend_login_required
logged_in? && allowed? || access_denied(:backend)
end
-
+
+ # Returns a helper to pass in a <tt>before_filter</tt> for check if
+ # an account are: <tt>logged_in?</tt> and <tt>allowed?</tt>
+ #
+ # Examples:
+ #
+ # before_filter :login_frontend_required, :except => [:login]
+ #
def fronted_login_required
logged_in? && allowed? || access_denied(:backend)
end
- def access_denied(where)
+ def access_denied(where)#:nodoc:
respond_to do |format|
format.html { redirect_to :controller => "#{where}/sessions", :action => :new }
format.js { render(:update) { |page| page.alert "You don't allowed to access to this javascript" } }
end
false
end
- def store_location
+ def store_location#:nodoc:
session[:return_to] = request.request_uri
end
-
+
+ # Redirect the account to the page that requested an authentication or
+ # if the account is not allowed/logged return it to a default page
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
- def self.included(base)
+ def self.included(base)#:nodoc:
base.send :helper_method, :current_account, :logged_in?
end
- def login_from_session
+ def login_from_session#:nodoc:
self.current_account = Account.find_by_id(session[:account]) if session[:account]
end
end # Module Authentication
View
12 lib/access_control/base.rb
@@ -95,22 +95,22 @@ def project_module(name, controller=nil, &block)
@project_modules << ProjectModule.new(name, controller, &block)
end
- # Globally but for current role allow an action
+ # Globally allow an action of a controller for the current role
def allow_action(path)
@allowed << recognize_path(path)
end
- # Globally but for current role deny an action
+ # Globally deny an action of a controllerfor the current role
def deny_action(path)
@denied << recognize_path(path)
end
- # Globally but for current role allow an action
+ # Globally allow all actions from a controller for the current role
def allow_all_actions(path)
@allowed << { :controller => recognize_path(path)[:controller] }
end
- # Globally but for current role deny an action
+ # Globally denty all actions from a controller for the current role
def deny_all_actions(path)
@denied << { :controller => recognize_path(path)[:controller] }
end
@@ -144,6 +144,7 @@ def initialize(name, path=nil, options={}, &block)#:nodoc:
yield self
end
+ # Build a new menu and automaitcally add the action on the allowed actions.
def menu(name, path=nil, options={}, &block)
@menus << Menu.new(name, path, options, &block)
end
@@ -220,6 +221,7 @@ def config
end
end
- class AccessControlError < StandardError; end;
+ class AccessControlError < StandardError#:nodoc:
+ end
end
end
View
8 lib/controller/lipsiadmin_controller.rb
@@ -1,10 +1,10 @@
module Lipsiadmin#:nodoc:
module Controller#:nodoc:
- # Base Backend Controller that defined:
+ # Base Backend Controller that define:
#
- # layout false
- # before_filter :backend_login_required
- # helper Lipsiadmin::View::Helpers::BackendHelper
+ # layout false
+ # before_filter :backend_login_required
+ # helper Lipsiadmin::View::Helpers::BackendHelper
#
class Base < ActionController::Base
def self.inherited(subclass)#:nodoc:
View
18 lib/controller/pdf_builder.rb
@@ -1,6 +1,19 @@
module Lipsiadmin
module Controller
- # This module convert a string/controller to
+ # This module convert a string/controller to a pdf through Pd4ml java library (included in this plugin)
+ #
+ # For generate a pdf you can simply do
+ #
+ # script/generate pdf invoice
+ #
+ # then edit your template /app/views/pdf/invoice.html.haml
+ #
+ # Then in any of your controllers add some like this:
+ #
+ # def generate_pdf_invoice
+ # render_pdf :invoice, 'invoice_file.pdf'
+ # end
+ #
module PdfBuilder
include Lipsiadmin::Utils::HtmlEntities
@@ -34,7 +47,8 @@ def render_pdf(template, filename, landescape = false)
end
# Errors For PDF
- class PdfError < StandardError; end
+ class PdfError < StandardError#:nodoc:
+ end
end
end
end
View
9 lib/controller/rescue.rb
@@ -1,8 +1,11 @@
module Lipsiadmin
module Controller
# This module are raised when an exception fire up in controllers.
- # Now you can personalize exception and simplify the layout using templates
- # in app/views/exception
+ #
+ # Now you can personalize exception and simplify the layout using templates in:
+ #
+ # app/views/exception
+ #
# when an exception is raised it try to send an email, and for send an email
# you need to configure in enviroment or in an initializer some like this:
#
@@ -14,7 +17,7 @@ module Controller
#
module Rescue
- def self.included(base)
+ def self.included(base)#:nodoc:
base.class_eval do
alias_method_chain :rescue_action_in_public, :notifier
end
View
1 lib/controller/responds_to_parent.rb
@@ -1,6 +1,7 @@
module Lipsiadmin
module Controller
# Executes the response body as JavaScript in the context of the parent window.
+ #
# Use this method of you are posting a form to a hidden IFRAME or if you would like
# to use IFRAME base RPC.
module RespondsToParent
View
56 lib/data_base/attachment.rb
@@ -1,24 +1,3 @@
-# Attachment allows file attachments that are stored in the filesystem. All graphical
-# transformations are done using the Graphics/ImageMagick command line utilities and
-# are stored in Tempfiles until the record is saved. Attachment does not require a
-# separate model for storing the attachment's information, instead adding a few simple
-# columns to your table.
-#
-# Author:: Jon Yurek
-# Copyright:: Copyright (c) 2008 thoughtbot, inc.
-# License:: MIT License (http://www.opensource.org/licenses/mit-license.php)
-#
-# Attachment defines an attachment as any file, though it makes special considerations
-# for image files. You can declare that a model has an attached file with the
-# +has_one_attachment+ method:
-#
-# class User < ActiveRecord::Base
-# has_one_attachment
-# or
-# has_many_attachments
-# end
-#
-# See the +has_one_attachment+ or +has_many_attachments+ documentation for more details.
require 'tempfile'
require 'data_base/attachment/upfile'
require 'data_base/attachment/iostream'
@@ -36,18 +15,30 @@
module Lipsiadmin
module DataBase
- # The base module that gets included in ActiveRecord::Base. See the
- # documentation for Attachment::ClassMethods for more useful information.
module Attachment
- class << self
+ class << self#:nodoc:
def included(base) #:nodoc:
base.extend(ClassMethods)
end
end
module ClassMethods
-
+
+ # Attach a single file/image to your model.
+ #
+ # Examples:
+ #
+ # has_one_attachment :image
+ # attachment_styles_for :image, :normal, "128x128!"
+ # validates_attachment_presence_for :image
+ # validates_attachment_size_for :image, :greater_than => 10.megabytes
+ # validates_attachment_content_type_for :image, "image/png"
+ #
+ # Then in your form (with multipart) you can simply add:
+ #
+ # =file_field :mymodel, :image_attributes
+ #
def has_one_attachment(name, options={})
options[:as] ||= :attacher
options[:class_name] ||= "Attachment"
@@ -88,6 +79,21 @@ def has_one_attachment(name, options={})
end
end
+ # Attach a many files/images to your model.
+ #
+ # Examples:
+ #
+ # has_one_attachment :images
+ # attachment_styles_for :images, :normal, "128x128!"
+ # validates_attachment_presence_for :images
+ # validates_attachment_size_for :images, :greater_than => 10.megabytes
+ # validates_attachment_content_type_for :images, "image/png"
+ #
+ # Then in your form (with multipart) you can simply add:
+ #
+ # =fields_for "yourmodel[attachments_attributes][]", @yourmodel.images.build do |image|
+ # =image.file_field :file
+ #
def has_many_attachments(name, options = {})
options[:as] ||= :attacher
options[:class_name] ||= "Attachment"
View
35 lib/data_base/attachment/attach.rb
@@ -1,4 +1,33 @@
module Lipsiadmin
+ # Attachment allows file attachments that are stored in the filesystem. All graphical
+ # transformations are done using the Graphics/ImageMagick command line utilities and
+ # are stored in Tempfiles until the record is saved. Attachment does not require a
+ # separate model for storing the attachment's information, instead adding a few simple
+ # columns to your table.
+ #
+ # Author:: Jon Yurek
+ # Copyright:: Copyright (c) 2008 thoughtbot, inc.
+ # License:: MIT License (http://www.opensource.org/licenses/mit-license.php)
+ #
+ # Attachment defines an attachment as any file, though it makes special considerations
+ # for image files. You can declare that a model has an attached file with the
+ # +has_one_attachment+ method:
+ #
+ # From your console:
+ # script/generate attachment
+ #
+ # Then in any model you can do:
+ #
+ # class User < ActiveRecord::Base
+ # has_many_attachments :attachments, :dependent => :destroy
+ # has_one_attachment :image
+ # attachment_styles_for :attachments, :normal, "128x128!"
+ # validates_attachment_presence_for :attachments
+ # validates_attachment_size_for :attachments, :greater_than => 10.megabytes
+ # validates_attachment_content_type_for :attachments, "image/png"
+ # end
+ #
+ # See the <tt>Lipsiadmin::DataBase::Attachment::ClassMethods</tt> documentation for more details.
module Attachment
class << self
@@ -30,7 +59,7 @@ def processor(name) #:nodoc:
processor
end
- def interpolates(key, &block)
+ def interpolates(key, &block) #:nodoc:
Lipsiadmin::Attachment.interpolations[key] = block
end
@@ -418,12 +447,12 @@ def post_process #:nodoc:
end
end
- def fire_events(which)
+ def fire_events(which) #:nodoc:
return true if callback(:"#{which}_post_process") == false
return true if callback(:"#{which}_#{name}_post_process") == false
end
- def post_process_styles
+ def post_process_styles #:nodoc:
log("Post-processing #{name}")
@styles.each do |name, args|
begin
View
62 lib/data_base/attachment/iostream.rb
@@ -1,50 +1,54 @@
-# Provides method that can be included on File-type objects (IO, StringIO, Tempfile, etc) to allow stream copying
-# and Tempfile conversion.
-module IOStream
+module Lipsiadmin
+ module Attachment
+ # Provides method that can be included on File-type objects (IO, StringIO, Tempfile, etc) to allow stream copying
+ # and Tempfile conversion.
+ module IOStream
- # Returns a Tempfile containing the contents of the readable object.
- def to_tempfile
- tempfile = Tempfile.new("stream")
- tempfile.binmode
- self.stream_to(tempfile)
- end
+ # Returns a Tempfile containing the contents of the readable object.
+ def to_tempfile
+ tempfile = Tempfile.new("stream")
+ tempfile.binmode
+ self.stream_to(tempfile)
+ end
- # Copies one read-able object from one place to another in blocks, obviating the need to load
- # the whole thing into memory. Defaults to 8k blocks. If this module is included in both
- # StringIO and Tempfile, then either can have its data copied anywhere else without typing
- # worries or memory overhead worries. Returns a File if a String is passed in as the destination
- # and returns the IO or Tempfile as passed in if one is sent as the destination.
- def stream_to(path_or_file, in_blocks_of = 8192)
- dstio = case path_or_file
- when String then File.new(path_or_file, "wb+")
- when IO then path_or_file
- when Tempfile then path_or_file
- end
- buffer = ""
- self.rewind
- while self.read(in_blocks_of, buffer) do
- dstio.write(buffer)
+ # Copies one read-able object from one place to another in blocks, obviating the need to load
+ # the whole thing into memory. Defaults to 8k blocks. If this module is included in both
+ # StringIO and Tempfile, then either can have its data copied anywhere else without typing
+ # worries or memory overhead worries. Returns a File if a String is passed in as the destination
+ # and returns the IO or Tempfile as passed in if one is sent as the destination.
+ def stream_to(path_or_file, in_blocks_of = 8192)
+ dstio = case path_or_file
+ when String then File.new(path_or_file, "wb+")
+ when IO then path_or_file
+ when Tempfile then path_or_file
+ end
+ buffer = ""
+ self.rewind
+ while self.read(in_blocks_of, buffer) do
+ dstio.write(buffer)
+ end
+ dstio.rewind
+ dstio
+ end
end
- dstio.rewind
- dstio
end
end
class IO #:nodoc:
- include IOStream
+ include Lipsiadmin::Attachment::IOStream
end
%w( Tempfile StringIO ).each do |klass|
if Object.const_defined? klass
Object.const_get(klass).class_eval do
- include IOStream
+ include Lipsiadmin::Attachment::IOStream
end
end
end
# Corrects a bug in Windows when asking for Tempfile size.
if defined? Tempfile
- class Tempfile
+ class Tempfile#:nodoc:
def size
if @tmpfile
@tmpfile.fsync
View
2 lib/data_base/attachment/upfile.rb
@@ -32,7 +32,7 @@ def size
end
if defined? StringIO
- class StringIO
+ class StringIO#:nodoc:
attr_accessor :original_filename, :content_type
def original_filename
@original_filename ||= "stringio.txt"
View
36 lib/data_base/attachment_table.rb
@@ -1,8 +1,19 @@
module Lipsiadmin
module DataBase
+ # This is the table that handle the attachments.
+ # You can define some global info like:
+ #
+ # attachment_styles :thumb, "128x128"
+ #
+ # In this way all models that use <tt>has_one_attachment</tt> or
+ # <tt>has_many_attachments</tt> handle a default style called *thumb*
+ #
+ # Remember that any model that use <tt>has_one_attachment</tt> or
+ # <tt>has_many_attachments</tt> can override/add styles/validations etc...
+ #
class AttachmentTable < ActiveRecord::Base
- def self.inherited(subclass)
+ def self.inherited(subclass)#:nodoc:
super
subclass.write_inheritable_attribute(:attachment_definitions, {}) if subclass.attachment_definitions.nil?
subclass.attachment_definitions[subclass.name] = {:validations => {}}.merge(Lipsiadmin::Attachment.options)
@@ -19,28 +30,32 @@ def self.inherited(subclass)
#validates_presence_of :filename
+ # Returns the url of the attachment, optionally you can pass the style like url(:thumb)
def url(style=nil)
file.to_s(style)
end
-
+
+ # Returns a <tt>Lipsiadmin::Attachment::Attach</tt> instance
def file
@_file ||= Lipsiadmin::Attachment::Attach.new(:attached, self, attachment_definitions)
end
-
+
+ # Assign a <tt>Lipsiadmin::Attachment::Attach</tt> instance to the current file
def file=(tempfile)
file.assign(tempfile)
end
-
+
+ # Returns true if the file exist
def file?
file.exist?
end
- def attachment_definitions=(options)
+ def attachment_definitions=(options)#:nodoc:
attachment_definitions.merge!(options.symbolize_keys)
end
# This is the custom instance attachment_definition
- def attachment_definitions
+ def attachment_definitions#:nodoc:
@instance_attachment_definitions ||= self.class.attachment_definitions[self.class.name].clone
return @instance_attachment_definitions
end
@@ -49,20 +64,22 @@ def attachment_definitions
attachment = record.file
attachment.send(:flush_errors) unless attachment.valid?
end
-
+
+ # Perform <tt>file</tt>.save
def save_attached_files
logger.info("[Attachment] Saving attachments.")
file.save
end
-
+
+ # Perform <tt>file</tt>.destroy
def destroy_attached_files
logger.info("[Attachment] Deleting attachments.")
file.queue_existing_for_delete
file.flush_deletes
end
end
- module ClassMethods
+ module ClassMethods#:nodoc:
def attachment_url(url)
attachment_attachment_url_for(self.name, url)
@@ -112,7 +129,6 @@ def validates_attachment_thumbnails(options = {})
validates_attachment_thumbnails_for(self.name, options)
end
- # Places ActiveRecord-style validations on the presence of a file.
def validates_attachment_presence(options = {})
validates_attachment_presence_for(self.name, options)
end
View
18 lib/data_base/translate_attributes.rb
@@ -1,5 +1,23 @@
module Lipsiadmin
module DataBase
+ # With this method we can translate define and automatically translate columns for
+ # the current rails locale.
+ #
+ # Defining some columns like these:
+ #
+ # m.col :string, :name_it, :name_en, :name_cz
+ # m.col :text, :description_it, :description_en, :description_cz
+ #
+ # we can call
+ #
+ # myinstance.name
+ #
+ # or
+ #
+ # puts myinstance.description
+ #
+ # Lipsiadmin look for name_#{I18n.locale}
+ #
module TranslateAttributes
# Define <tt>method missing</tt> to intercept calls to non-localized methods (eg. +name+ instead of +name_cz+)
def method_missing(method_name, *arguments)
View
37 lib/data_base/without_table.rb
@@ -1,27 +1,56 @@
module Lipsiadmin
module DataBase
+ # This class create a *fake* table that can be usefull if you need for example
+ # perform validations. Take a look to this test case:
+ #
+ # Examples:
+ #
+ # class Contact < Lipsiadmin::DataBase::WithoutTable
+ # column :name, :string
+ # column :company, :string
+ # column :telephone, :string
+ # column :email, :string
+ # column :message, :text
+ #
+ # validates_presence_of :name, :message
+ # validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
+ # end
+ #
+ # Now we need to validate a contact, and if the validations is okey send an email or if not raise errors
+ #
+ # @contact = Contact.new(params[:contact])
+ # if @contact.valid?
+ # Notifier.deliver_support_request(@contact)
+ # else
+ # flash[:notice] = "There are some problems"
+ # render :action => :support_request
+ # end
+ #
class WithoutTable < ActiveRecord::Base
self.abstract_class = true
- def create_or_update
+ def create_or_update#:nodoc:
errors.empty?
end
class << self
- def inherited(klass)
+ def inherited(klass)#:nodoc:
columns_hash.each do |name, column|
klass.columns << column unless klass.column_names.include(name)
end
end
-
+
+ # Returns columns for this *fake* table
def columns()
@columns ||= []
end
-
+
+ # Define columns for a this *fake* table
def column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
reset_column_information
end
+
# Resets all the cached information about columns, which will cause them to be reloaded on the next request.
def reset_column_information
generated_methods.each { |name| undef_method(name) }
View
11 lib/lipsiadmin.rb
@@ -6,10 +6,8 @@
require 'mailer/exception_notifier'
require 'view/helpers/active_record_helper'
require 'view/helpers/backend_helper'
-require 'view/helpers/country_select_helper'
-require 'view/helpers/date_helper'
+require 'view/helpers/view_helper'
require 'view/helpers/ext_helper'
-require 'view/helpers/tag_helper'
require 'controller/ext'
require 'controller/pdf_builder'
require 'controller/responds_to_parent'
@@ -37,9 +35,14 @@
end
ActionView::Base.class_eval do
- include Lipsiadmin::View::Helpers::TagHelper
+ include Lipsiadmin::View::Helpers::FormHelper
+ include Lipsiadmin::View::Helpers::FormTagHelper
+ include Lipsiadmin::View::Helpers::DateHelper
+ include Lipsiadmin::View::Helpers::CountrySelectHelper
end
+ActionView::Helpers::FormBuilder.send(:include, Lipsiadmin::View::Helpers::FormBuilder)
+
ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods.class_eval do
include Lipsiadmin::View::Helpers::ExtHelper
end
View
9 lib/mailer/exception_notifier.rb
@@ -1,5 +1,7 @@
module Lipsiadmin
module Mailer
+ # This class send notification through mail if an exception
+ # occour in a controller.
class ExceptionNotifier < ActionMailer::Base
@@sender_address = %("Exception Notifier" <exception.notifier@default.com>)
@@ -17,8 +19,11 @@ class ExceptionNotifier < ActionMailer::Base
self.mailer_name = "exception"
self.template_root = "#{File.dirname(__FILE__)}"
- def self.reloadable?() false end
-
+ def self.reloadable?#:nodoc:
+ false
+ end
+
+ # This method deliver the exception for the given controller and request
def exception(exception, controller, request)
content_type "text/plain"
View
28 lib/mailer/pdf_builder.rb
@@ -1,11 +1,36 @@
module Lipsiadmin
module Mailer
+ # This module convert a string/controller to a pdf through Pd4ml java library (included in this plugin)
+ #
+ # For generate a pdf you can simply do
+ #
+ # script/generate pdf invoice
+ #
+ # then edit your template /app/views/pdf/invoice.html.haml
+ #
+ # Then in any of your mailers add some like this:
+ #
+ # def order_invoiced(order)
+ # recipients my@mail.com
+ # from my@server.com
+ # subject Your Invoice
+ #
+ # attachment "application/pdf" do |a|
+ # a.body = render_pdf(:invoice, :invoice => order.invoice, :other => order.invoice.other)
+ # end
+ #
+ # part "text/plain" do |a|
+ # a.body = render_message("order_invoiced", :order => order, :body_template => @body_template)
+ # end
+ # end
+ #
module PdfBuilder
include Lipsiadmin::Utils::HtmlEntities
# Path to the pd4ml jarfile
JARPATH = "../../resources"
+ # Convert a stream to pdf, the template must be located in app/view/pdf/yourtemplate.pdf.erb
def render_pdf(template, body)
# set the landescape
landescape = (body[:landescape].delete || false)
@@ -35,6 +60,7 @@ def render_pdf(template, body)
end
# Errors For PDF
- class PdfError < StandardError; end
+ class PdfError < StandardError#:nodoc:
+ end
end
end
View
7 lib/utils/literal.rb
@@ -1,5 +1,12 @@
module Lipsiadmin
module Utils
+ # Returns an object whose to_json evaluates to code.
+ # Use this to pass a literal JavaScript expression as an argument to another JavaScriptGenerator method.
+ #
+ # Examples:
+ #
+ # "function() { alert('test') }".to_l
+ #
module Literal
# Returns an object whose <tt>to_json</tt> evaluates to +code+. Use this to pass a literal JavaScript
# expression as an argument to another JavaScriptGenerator method.
View
40 lib/view/helpers/backend_helper.rb
@@ -2,6 +2,7 @@ module Lipsiadmin
module View
module Helpers
module BackendHelper
+ # This method work like builtin Rails error_message_for but use an Ext.Message.
def simple_error_messages_for(*params)
options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
@@ -18,38 +19,71 @@ def simple_error_messages_for(*params)
''
end
end
-
+
+ # This method add tab for in your view
def tab(name, padding=true, options={}, &block)
options[:style] = "padding:10px;#{options[:style]}" if padding
options[:id] ||= name.to_s.downcase.gsub(/[^a-z0-9]+/, '_').gsub(/-+$/, '').gsub(/^-+$/, '')
concat content_tag(:div, capture(&block), { :id => options[:id], :class => "x-hide-display", :style => options[:style], :tabbed => true, :title => name })
end
+ # Set the title of the page
def title(title)
content_tag(:script, "Backend.app.setTitle(#{title.to_json})", :type => Mime::JS)
end
+ # Store the location to come back from for example an extjs grid
def back_to(location)
content_tag(:script, "Backend.app.backTo(#{url_for(location)})", :type => Mime::JS)
end
+ # Generate the menu from the Lispiadmin::AccessControl
def backend_menu
config = current_account.maps.collect(&:project_modules)[0].collect(&:config)
config << { :text => "Backend.locale.buttons.help".to_l, :handler => "function() { Backend.app.openHelp() }".to_l }
return config.to_json
end
+
+ # Open a new windows that can contain a form that you can reuse
+ #
+ # Example:
+ #
+ # # in app/views/dossiers/_form.html.haml
+ # %tr
+ # %td{:style=>"width:100px"}
+ # %b Customer:
+ # %td
+ # %span{:id => :account_name}=@dossier.account ? @dossier.account.full_name : "None"
+ # =hidden_field :dossier, :account_id
+ # =open_window "/backend/accounts.js", :id, :name, :dossier_account_id, :account_name
+ #
def open_window(url, value, display, render_value_to, render_display_to)
link_to_function(image_tag("backend/new.gif", :style=>"vertical-align:bottom"),
"Backend.window.open({url:'#{url}', display:'#{display}', value:'#{value}', displayField:'#{render_display_to}', valueField:'#{render_value_to}'})")
end
-
+
+ # This method call a remote_function and in the same time do a
+ #
+ # Backend.app.mask()
+ #
+ # and when the function is complete
+ #
+ # Backend.app.unmask()
+ #
def link_to_remote_with_wait(name, options={}, html_options={})
options[:complete] = "Backend.app.unmask();"
options[:before] = "Backend.app.mask('#{I18n.t('backend.messages.wait.message')}')";
link_to_function(name, remote_function(options), html_options || options.delete(:html))
end
-
+
+ # This method generates a new ExtJs BoxComponent.
+ #
+ # Examples:
+ #
+ # =box "My Title", "My Subtitle", :submit => true, :collapsible => true do
+ # my content
+ #
def box(title=nil, subtitle=nil, options={}, &block)
return <<-HTML
<div class="x-box" style="width:99%">
View
91 lib/view/helpers/country_select_helper.rb
@@ -1,91 +0,0 @@
-# We extend ActionViews Helpers with the old country select, that now for some
-# problems with law is not included in Rails 2+
-#
-# We do a big rewritten of old date_select, datimeselect for force the using of
-# ExtJs DateTimeField
-#
-# For use it try ext_date_select ext_datetime_select
-#
-module ActionView
- module Helpers#:nodoc:
- module FormOptionsHelper#:nodoc:
- # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
- def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
- InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
- end
- # Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
- # have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
- # that they will be listed above the rest of the (long) list.
- #
- # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
- def country_options_for_select(selected = nil, priority_countries = nil)
- country_options = ""
-
- if priority_countries
- country_options += options_for_select(priority_countries, selected)
- country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
- end
-
- return country_options + options_for_select(COUNTRIES, selected)
- end
- # All the countries included in the country_options output.
- COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
- "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
- "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
- "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil",
- "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
- "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
- "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
- "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
- "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)",
- "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
- "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea",
- "Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)",
- "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
- "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
- "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
- "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya",
- "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
- "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
- "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
- "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
- "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
- "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
- "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
- "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
- "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
- "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
- "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
- "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
- "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname",
- "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
- "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
- "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
- "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
- "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela",
- "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara",
- "Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
- end
-
- class InstanceTag#:nodoc:
- def to_country_select_tag(priority_countries, options, html_options)
- html_options = html_options.stringify_keys
- add_default_name_and_id(html_options)
- value = value(object)
- content_tag("select",
- add_options(
- country_options_for_select(value, priority_countries),
- options, value
- ), html_options
- )
- end
- end
-
- class FormBuilder#:nodoc:
- def country_select(method, priority_countries = nil, options = {}, html_options = {})
- @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
- end
- end
- end
-end
View
44 lib/view/helpers/date_helper.rb
@@ -1,44 +0,0 @@
-require "date"
-require 'action_view/helpers/tag_helper'
-module ActionView
- module Helpers#:nodoc:
- module DateHelper#:nodoc:
- def ext_date_select(object_name, method, options = {}, html_options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_ext_date_select_tag(options, html_options)
- end
-
- def ext_datetime_select(object_name, method, options = {}, html_options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_ext_datetime_select_tag(options, html_options)
- end
- end
-
-
- class InstanceTag #:nodoc:
- def to_ext_date_select_tag(options = {}, html_options = {})
- to_datetime_select_tag({ :hideTime => true.to_l }.merge(options), html_options)
- end
-
- def to_ext_datetime_select_tag(options = {}, html_options = {})
- html_options = html_options.stringify_keys
- html_options = DEFAULT_FIELD_OPTIONS.merge(html_options)
- html_options["type"] = "hidden"
- html_options["value"] ||= value_before_type_cast(object)
- html_options["value"] &&= html_escape(html_options["value"])
- add_default_name_and_id(html_options)
- options = { :applyTo => html_options["id"], :dateFormat => I18n.t("extjs.dateFormat") }.merge(options)
- tag("input", html_options) +
- content_tag(:script, "new Ext.form.DateTimeField(#{options.to_json});", :type => Mime::JS)
- end
- end
-
- class FormBuilder#:nodoc:
- def ext_date_select(method, options = {}, html_options = {})
- @template.ext_date_select(@object_name, method, options.merge(:object => @object), html_options)
- end
-
- def ext_datetime_select(method, options = {}, html_options = {})
- @template.ext_datetime_select(@object_name, method, options.merge(:object => @object), html_options)
- end
- end
- end
-end
View
16 lib/view/helpers/ext/component.rb
@@ -6,7 +6,7 @@ class ComponentError < StandardError; end#:nodoc:
# This is the base class of ext components
class Component
- def initialize(options={}, &block)
+ def initialize(options={}, &block)#:nodoc:
@config = Configuration.new(options)
@before, @after = [], []
if block_given?
@@ -58,26 +58,26 @@ def method_missing(method, arg=nil)#:nodoc:
end
end
- # Return the array JavaScript to add before component.
+ # Returns an array of javascripts to add before component is rendered.
#
def before
@before
end
- # Return the raw JavaScript to add before component.
- #
+ # Returns the javascript to add before component is rendered.
+ #
def before_js
@before.uniq.compact.join("\n\n") + "\n\n"
end
- # Return the array JavaScript to add after component.
- #
+ # Returns an array of javascripts to add afters component is rendered.
+ #
def after
@after
end
- # Return the raw JavaScript to add after component.
- #
+ # Returns the javascript to add after component is rendered.
+ #
def after_js
"\n\n" + @after.uniq.compact.join("\n\n")
end
View
6 lib/view/helpers/ext/configuration.rb
@@ -1,15 +1,17 @@
module Lipsiadmin
module Ext
- # Ext configuration of used by components
+ # Ext configuration used by components
#
# Generates: { name: 'name', handler: function(){ alert('Hello World') } }
#
class Configuration < Hash
- def initialize(hash)
+ def initialize(hash)#:nodoc:
hash.each { |k,v| self[k] = v }
end
+ # Returns the configuration as a string.
+ # Optionally you can specify the indentation spaces.
def to_s(indent=1)
i = (" "*indent)
s = self.size > 0 ? "\n" : " "
View
39 lib/view/helpers/ext/grid.rb
@@ -1,7 +1,26 @@
module Lipsiadmin
module Ext
-
- # Generate a new Ext.grid.GridPanel
+ # Generate a full customizable Ext.GridPanel
+ #
+ # Examples:
+ #
+ # page.grid do |grid|
+ # grid.id "grid-posts"
+ # grid.title "List all Post"
+ # grid.base_path "/backend/posts"
+ # grid.forgery_protection_token request_forgery_protection_token
+ # grid.authenticity_token form_authenticity_token
+ # grid.tbar :default
+ # grid.store do |store|
+ # store.url "/backend/posts.json"
+ # store.fields @column_store.store_fields
+ # end
+ # grid.columns do |columns|
+ # columns.fields @column_store.column_fields
+ # end
+ # grid.bbar :store => grid.get_store, :pageSize => params[:limit]
+ # end
+ #
class Grid < Component
def initialize(options={}, &block)#:nodoc:
# Call Super Class for initialize configuration
@@ -18,6 +37,17 @@ def initialize(options={}, &block)#:nodoc:
view :default if config[:view].blank?
end
+ # Define the selection model of this grid.
+ # You can pass:
+ #
+ # * :checkbox
+ # * :default (alias for checkbox)
+ # * :row
+ #
+ # It generate some like:
+ #
+ # new Ext.grid.CheckboxSelectionModel()
+ #
def sm(value)
case value
when :checkbox || :default
@@ -29,14 +59,17 @@ def sm(value)
end
end
+ # Define the title of the grid
def title(title)
before << "Backend.app.setTitle(#{title.to_json});"
end
+ # Assign plugins for the current grid
def plugins(plugins)
config[:plugins] = plugins
end
-
+
+ # Add a single plugin to the grid plugins
def add_plugin(plugins)
config[:plugins] << plugins
end
View
88 lib/view/helpers/ext_helper.rb
@@ -13,7 +13,7 @@ module Helpers
# Module containing the methods useful for ext/prototype
module ExtHelper
- def self.included(base)
+ def self.included(base)#:nodoc:
base.class_eval do
alias_method_chain :to_s, :refactoring
end
@@ -104,85 +104,27 @@ def fn(function=nil, &block)
end
end
- # Generate a full customizable Ext.Grid
+ # Generate a full customizable Ext.GridPanel
#
# Examples:
#
# page.grid do |grid|
- #
- # #Some standard config
- # grid.title "List of all Account"
- # grid.selection :checkbox
- #
- # # TopBar & Buttons
- # grid.ttbar do |bar|
- # bar.add "Add", :handler => grid.l("Backend.app.loadHtml('/backend/accounts/new')"), :icon => "...", :other => "..."
- # bar.add "Edit", :handler => grid.l("Backend.app.loadHtml('/backend/accounts/'+accounts_grid.getSelected().id+'/edit')"), :other => "..."
- # bar.add "Print" do |submenu|
- # submenu.add "Print Invoice", :foo => "..."
- # submenu.add "Print Account", :bar => "..."
- # end
- # end
- #
- # or simply:
- #
- # grid.ttbar :default do |ttbar|
- # ttbar.path "/backend/accounts"
- # ttbar.forgery_protection_token request_forgery_protection_token
- # ttbar.authenticity_token form_authenticity_token
- # end
- #
- # # Columns
- # grid.columns do |col|
- # col.add "Name", "accounts.name", :searchable => false, :sortable => true
- # col.add "Category Name", "accounts.category.name", :sortable => :false
- # col.add "Created At", "accounts.created_at", :type => "date", :format => "c", :renderer => Ext.call("Ext.Util.DateRenderer", "m/d/y")
+ # grid.id "grid-posts"
+ # grid.title "List all Post"
+ # grid.base_path "/backend/posts"
+ # grid.forgery_protection_token request_forgery_protection_token
+ # grid.authenticity_token form_authenticity_token
+ # grid.tbar :default
+ # grid.store do |store|
+ # store.url "/backend/posts.json"
+ # store.fields @column_store.store_fields
# end
- #
- # # alternative you can simply do
- # #
- # # grid.columns :defaults, Account
- # # and they add all columns of Account Model.
- # #
- # # or
- # #
- # # grid.coumns :default do |col|
- # # col.add "Projects", "accounts.projects.collect(&:name).join(", ")", :searchable => false, :sortable => true
- # # col.add "Category Name", "accounts.category.name", :sortable => :false
- # # ...
- # # end
- # # In this way add other than accounts columns "Projects" and "Category Name"!
- #
- # # Extra Examples
- # #
- # # Render:
- # #
- # # grid.on('dblclick', function(){
- # # Ext.Msg.alert('Title', 'Content');
- # # });
- # #
- #
- # grid.on "dblclick" do
- # Ext.call("Ext.Msg.alert", "Title", "Content")
- # end
- #
- # grid.on "dblclick" do
- # Ext.call "Ext.Msg.alert", "Selected the row", "with name: #{Ext.grid.selected.name}"
- # end
- #
- # grid.columns.first.on("dblclick") do
- # Ext.call("Ext.Msg.alert", "Some", "One")
+ # grid.columns do |columns|
+ # columns.fields @column_store.column_fields
# end
- #
- # button = grid.buttons.get_by(:title, "Add")
- # button = grid.buttons.get_by(:id, "add")
- # col = grid.columns.get_by(:id, "category_name")
- #
- # button.on("dblclick", Ext.fn("Ext.Msg.alert", "Hello World"))
- #
- # grid.append "/backend/accounts/grid_fn.js" # or :controller => :accounts, :action => :grid_fn, :format => :js
+ # grid.bbar :store => grid.get_store, :pageSize => params[:limit]
# end
- #
+ #
def grid(&block)
self << Lipsiadmin::Ext::Grid.new(&block)
end
View
52 lib/view/helpers/tag_helper.rb
@@ -1,52 +0,0 @@
-module Lipsiadmin
- module View
- module Helpers
- module TagHelper
- include ActionView::Helpers::FormHelper
- include ActionView::Helpers::FormTagHelper
-
- def text_area_with_style(name, value = nil, options = {})
- options[:class] ||= "x-form-field"
- options[:style] ||= "width:100%;height:80px"
- text_area_without_style(name, value, options)
- end
- alias_method_chain :text_area, :style
-
- def text_area_tag_with_style(name, value = nil, options = {})
- options[:class] ||= "x-form-field"
- options[:style] ||= "width:100%;height:80px"
- text_area_tag_without_style(name, value, options)
- end
- alias_method_chain :text_area_tag, :style
-
- def text_field_with_style(name, method, options = {})
- options[:class] ||= "x-form-text"
- options[:style] ||= "width:100%"
- text_field_without_style(name, method, options)
- end
- alias_method_chain :text_field, :style
-
- def text_field_tag_with_style(name, value = nil, options = {})
- options[:class] ||= "x-form-text"
- options[:style] ||= "width:100%"
- text_field_tag_without_style(name, value, options)
- end
- alias_method_chain :text_field_tag, :style
-
- def password_field_with_style(name, method, options = {})
- options[:class] ||= "x-form-text"
- options[:style] ||= "width:100%"
- password_field_without_style(name, method, options)
- end
- alias_method_chain :password_field, :style
-
- def password_field_tag_with_style(name, value = nil, options = {})
- options[:class] ||= "x-form-text"
- options[:style] ||= "width:100%"
- password_field_tag_without_style(name, value, options)
- end
- alias_method_chain :password_field_tag, :style
- end
- end
- end
-end
View
222 lib/view/helpers/view_helper.rb
@@ -0,0 +1,222 @@
+require "date"
+require 'action_view/helpers/tag_helper'
+module Lipsiadmin
+ module View
+ module Helpers#:nodoc:
+ # Returns text_area, text_field, password_field with
+ # a default extjs css style.
+ #
+ module FormHelper
+ def self.included(base)#:nodoc:
+ base.alias_method_chain :text_area, :style
+ base.alias_method_chain :text_field, :style
+ base.alias_method_chain :password_field, :style
+ end
+
+ # Returns text_area with extjs style
+ # alias for text_area, for use the original tag use:
+ #
+ # text_area_without_style
+ #
+ def text_area_with_style(name, value = nil, options = {})
+ options[:class] ||= "x-form-field"
+ options[:style] ||= "width:100%;height:80px"
+ text_area_without_style(name, value, options)
+ end
+
+ # Returns text_field with extjs style
+ # alias for text_field, for use the original tag use:
+ #
+ # text_field_without_style
+ #
+ def text_field_with_style(name, method, options = {})
+ options[:class] ||= "x-form-text"
+ options[:style] ||= "width:100%"
+ text_field_without_style(name, method, options)
+ end
+
+ # Returns password_field with extjs style
+ # alias for password_field, for use the original tag use:
+ #
+ # password_field_without_style
+ #
+ def password_field_with_style(name, method, options = {})
+ options[:class] ||= "x-form-text"
+ options[:style] ||= "width:100%"
+ password_field_without_style(name, method, options)
+ end
+ end
+
+ # Returns text_area_tag, text_field_tag, password_field_tag with
+ # a default extjs css style.
+ #
+ module FormTagHelper
+
+ def self.included(base)#:nodoc:
+ base.alias_method_chain :text_field_tag, :style
+ base.alias_method_chain :text_area_tag, :style
+ base.alias_method_chain :password_field_tag, :style
+ end
+
+ # Returns text_area_tag with extjs style
+ # alias for text_area_tag, for use the original tag use:
+ #
+ # text_area_tag_without_style
+ #
+ def text_area_tag_with_style(name, value = nil, options = {})
+ options[:class] ||= "x-form-field"
+ options[:style] ||= "width:100%;height:80px"
+ text_area_tag_without_style(name, value, options)
+ end
+
+ # Returns text_field_tag with extjs style
+ # alias for text_field_tag, for use the original tag use:
+ #
+ # text_field_tag_without_style
+ #
+ def text_field_tag_with_style(name, value = nil, options = {})
+ options[:class] ||= "x-form-text"
+ options[:style] ||= "width:100%"
+ text_field_tag_without_style(name, value, options)
+ end
+
+ # Returns password_field_tag with extjs style
+ # alias for password_field_tag, for use the original tag use:
+ #
+ # password_field_tag_style
+ #
+ def password_field_tag_with_style(name, value = nil, options = {})
+ options[:class] ||= "x-form-text"
+ options[:style] ||= "width:100%"
+ password_field_tag_without_style(name, value, options)
+ end
+ end
+
+ module DateHelper
+ # Returns an ExtJs Calendar
+ #
+ # Examples:
+ # =ext_date_select :post, :created_at
+ #
+ def ext_date_select(object_name, method, options = {}, html_options = {})
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_ext_date_select_tag(options, html_options)
+ end
+
+ # Returns an ExtJs Calendar and a Time selector
+ #
+ # Examples:
+ # =ext_datetime_select :post, :updated_at
+ #
+ def ext_datetime_select(object_name, method, options = {}, html_options = {})
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_ext_datetime_select_tag(options, html_options)
+ end
+ end
+
+ module CountrySelectHelper
+ # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
+ def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
+ InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
+ end
+ # Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
+ # have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
+ # that they will be listed above the rest of the (long) list.
+ #
+ # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
+ def country_options_for_select(selected = nil, priority_countries = nil)
+ country_options = ""
+
+ if priority_countries
+ country_options += options_for_select(priority_countries, selected)
+ country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
+ end
+
+ return country_options + options_for_select(COUNTRIES, selected)
+ end
+ # All the countries included in the country_options output.
+ COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
+ "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
+ "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
+ "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil",
+ "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
+ "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
+ "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
+ "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
+ "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
+ "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)",
+ "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
+ "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea",
+ "Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)",
+ "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
+ "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
+ "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
+ "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya",
+ "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
+ "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
+ "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
+ "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
+ "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
+ "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
+ "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
+ "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
+ "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
+ "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
+ "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
+ "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
+ "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname",
+ "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
+ "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
+ "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
+ "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
+ "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela",
+ "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara",
+ "Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
+ end
+
+ class InstanceTag < ActionView::Helpers::InstanceTag#:nodoc:
+ include CountrySelectHelper
+
+ def to_ext_date_select_tag(options = {}, html_options = {})
+ to_datetime_select_tag({ :hideTime => true.to_l }.merge(options), html_options)
+ end
+
+ def to_ext_datetime_select_tag(options = {}, html_options = {})
+ html_options = html_options.stringify_keys
+ html_options = DEFAULT_FIELD_OPTIONS.merge(html_options)
+ html_options["type"] = "hidden"
+ html_options["value"] ||= value_before_type_cast(object)
+ html_options["value"] &&= html_escape(html_options["value"])
+ add_default_name_and_id(html_options)
+ options = { :applyTo => html_options["id"], :dateFormat => I18n.t("extjs.dateFormat") }.merge(options)
+ tag("input", html_options) +
+ content_tag(:script, "new Ext.form.DateTimeField(#{options.to_json});", :type => Mime::JS)
+ end
+
+ def to_country_select_tag(priority_countries, options, html_options)
+ html_options = html_options.stringify_keys
+ add_default_name_and_id(html_options)
+ value = value(object)
+ content_tag("select",
+ add_options(
+ country_options_for_select(value, priority_countries),
+ options, value
+ ), html_options
+ )
+ end
+ end
+
+ module FormBuilder#:nodoc:
+ def ext_date_select(method, options = {}, html_options = {})
+ @template.ext_date_select(@object_name, method, options.merge(:object => @object), html_options)
+ end
+
+ def ext_datetime_select(method, options = {}, html_options = {})
+ @template.ext_datetime_select(@object_name, method, options.merge(:object => @object), html_options)
+ end
+
+ def country_select(method, priority_countries = nil, options = {}, html_options = {})
+ @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
+ end
+ end
+ end
+ end
+end
View
1 lipsiadmin_generators/backend/templates/views/backend/accounts/index.rjs
@@ -1,6 +1,5 @@
page.grid do |grid|
grid.id "grid-accounts"
- grid.var :finocchio
grid.title "Elenco Accounts"
grid.base_path "/backend/accounts"
grid.forgery_protection_token request_forgery_protection_token
View
1 lipsiadmin_generators/backend_page/templates/view_index.rjs.erb
@@ -1,6 +1,5 @@
page.grid do |grid|
grid.id "grid-<%= plural_name %>"
- grid.var :finocchio
grid.title "List all <%= model_instance.class.human_name %>"
grid.base_path "/backend/<%= plural_name %>"
grid.forgery_protection_token request_forgery_protection_token
View
613 resources/rdoc/horo.rb
@@ -0,0 +1,613 @@
+# Horo RDoc template
+# Author: Hongli Lai - http://izumi.plan99.net/blog/
+#
+# Based on the Jamis template:
+# http://weblog.jamisbuck.org/2005/4/8/rdoc-template
+
+if defined?(RDoc::Diagram)
+ RDoc::Diagram.class_eval do
+ remove_const(:FONT)
+ const_set(:FONT, "\"Bitstream Vera Sans\"")
+ end
+end
+
+module RDoc
+module Page
+
+FONTS = "\"Bitstream Vera Sans\", Verdana, Arial, Helvetica, sans-serif"
+
+STYLE = <<CSS
+a {
+ color: #00F;
+ text-decoration: none;
+}
+
+a:hover {
+ color: #77F;
+ text-decoration: underline;
+}
+
+body, td, p {
+ font-family: %fonts%;
+ background: #FFF;
+ color: #000;
+ margin: 0px;
+ font-size: small;
+}
+
+p {
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+}
+
+#content {
+ margin: 2em;
+ margin-left: 3.5em;
+ margin-right: 3.5em;
+}
+
+#description p {
+ margin-bottom: 0.5em;
+}
+
+.sectiontitle {
+ margin-top: 1em;
+ margin-bottom: 1em;
+ padding: 0.5em;
+ padding-left: 2em;
+ background: #005;
+ color: #FFF;
+ font-weight: bold;
+}
+
+.attr-rw {
+ padding-left: 1em;
+ padding-right: 1em;
+ text-align: center;
+ color: #055;
+}
+
+.attr-name {
+ font-weight: bold;
+}
+
+.attr-desc {
+}
+
+.attr-value {
+ font-family: monospace;
+}
+
+.file-title-prefix {
+ font-size: large;
+}
+
+.file-title {
+ font-size: large;
+ font-weight: bold;
+ background: #005;
+ color: #FFF;
+}
+
+.banner {
+ background: #005;
+ color: #FFF;
+ border: 1px solid black;
+ padding: 1em;
+}
+
+.banner td {
+ background: transparent;
+ color: #FFF;
+}
+
+h1 a, h2 a, .sectiontitle a, .banner a {
+ color: #FF0;
+}
+
+h1 a:hover, h2 a:hover, .sectiontitle a:hover, .banner a:hover {
+ color: #FF7;
+}
+
+.dyn-source {
+ display: none;
+ background: #fffde8;
+ color: #000;
+ border: #ffe0bb dotted 1px;
+ margin: 0.5em 2em 0.5em 2em;
+ padding: 0.5em;
+}
+
+.dyn-source .cmt {
+ color: #00F;
+ font-style: italic;
+}
+
+.dyn-source .kw {
+ color: #070;
+ font-weight: bold;
+}
+
+.method {
+ margin-left: 1em;
+ margin-right: 1em;
+ margin-bottom: 1em;
+}
+
+.description pre {
+ padding: 0.5em;
+ border: #ffe0bb dotted 1px;
+ background: #fffde8;
+}
+
+.method .title {
+ font-family: monospace;
+ font-size: large;
+ border-bottom: 1px dashed black;
+ margin-bottom: 0.3em;
+ padding-bottom: 0.1em;
+}
+
+.method .description, .method .sourcecode {
+ margin-left: 1em;
+}
+
+.description p, .sourcecode p {
+ margin-bottom: 0.5em;
+}
+
+.method .sourcecode p.source-link {
+ text-indent: 0em;
+ margin-top: 0.5em;
+}
+
+.method .aka {
+ margin-top: 0.3em;
+ margin-left: 1em;
+ font-style: italic;
+ text-indent: 2em;
+}
+
+h1 {
+ padding: 1em;
+ margin-left: -1.5em;
+ font-size: x-large;
+ font-weight: bold;
+ color: #FFF;
+ background: #007;
+}
+
+h2 {
+ padding: 0.5em 1em 0.5em 1em;
+ margin-left: -1.5em;
+ font-size: large;
+ font-weight: bold;
+ color: #FFF;
+ background: #009;
+}
+
+h3, h4, h5, h6 {
+ color: #220088;
+ border-bottom: #5522bb solid 1px;
+}
+
+.sourcecode > pre {
+ padding: 0.5em;
+ border: 1px dotted black;
+ background: #FFE;
+}
+
+dt {
+ font-weight: bold
+}
+
+dd {
+ margin-bottom: 0.7em;
+}
+CSS
+
+XHTML_PREAMBLE = %{<?xml version="1.0" encoding="%charset%"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+}
+
+XHTML_FRAMESET_PREAMBLE = %{
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
+}
+
+HEADER = XHTML_PREAMBLE + <<ENDHEADER
+<html>
+ <head>
+ <title>%title%</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
+ <link rel="stylesheet" href="%style_url%" type="text/css" media="screen" />
+
+ <script language="JavaScript" type="text/javascript">
+ // <![CDATA[
+
+ function toggleSource( id )
+ {
+ var elem
+ var link
+
+ if( document.getElementById )
+ {
+ elem = document.getElementById( id )
+ link = document.getElementById( "l_" + id )
+ }
+ else if ( document.all )
+ {
+ elem = eval( "document.all." + id )
+ link = eval( "document.all.l_" + id )
+ }
+ else
+ return false;
+
+ if( elem.style.display == "block" )
+ {
+ elem.style.display = "none"
+ link.innerHTML = "show source"
+ }
+ else
+ {
+ elem.style.display = "block"
+ link.innerHTML = "hide source"
+ }
+ }
+
+ function openCode( url )
+ {
+ window.open( url, "SOURCE_CODE", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=480,width=750" ).focus();
+ }
+ // ]]>
+ </script>
+ </head>
+
+ <body>
+ENDHEADER
+
+FILE_PAGE = <<HTML
+<table border='0' cellpadding='0' cellspacing='0' width="100%" class='banner'>
+ <tr><td>
+ <table width="100%" border='0' cellpadding='0' cellspacing='0'><tr>
+ <td class="file-title" colspan="2"><span class="file-title-prefix">File</span><br />%short_name%</td>
+ <td align="right">
+ <table border='0' cellspacing="0" cellpadding="2">
+ <tr>
+ <td>Path:</td>
+ <td>%full_path%
+IF:cvsurl
+ &nbsp;(<a href="%cvsurl%">CVS</a>)
+ENDIF:cvsurl
+ </td>
+ </tr>
+ <tr>
+ <td>Modified:</td>
+ <td>%dtm_modified%</td>
+ </tr>
+ </table>
+ </td></tr>
+ </table>
+ </td></tr>
+</table><br />
+HTML
+
+###################################################################
+
+CLASS_PAGE = <<HTML
+<table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
+ <td class="file-title"><span class="file-title-prefix">%classmod%</span><br />%full_name%</td>
+ <td align="right">
+ <table cellspacing="0" cellpadding="2">
+ <tr valign="top">
+ <td>In:</td>
+ <td>
+START:infiles
+HREF:full_path_url:full_path:
+IF:cvsurl
+&nbsp;(<a href="%cvsurl%">CVS</a>)
+ENDIF:cvsurl
+END:infiles
+ </td>
+ </tr>
+IF:parent
+ <tr>
+ <td>Parent:</td>
+ <td>
+IF:par_url
+ <a href="%par_url%">
+ENDIF:par_url
+%parent%
+IF:par_url
+ </a>
+ENDIF:par_url
+ </td>
+ </tr>
+ENDIF:parent
+ </table>
+ </td>
+ </tr>
+ </table>
+HTML
+
+###################################################################
+
+METHOD_LIST = <<HTML
+ <div id="content">
+IF:diagram
+ <table cellpadding='0' cellspacing='0' border='0' width="100%"><tr><td align="center">
+ %diagram%
+ </td></tr></table>
+ENDIF:diagram
+
+IF:description
+ <div class="description">%description%</div>
+ENDIF:description
+
+IF:requires
+ <div class="sectiontitle">Required Files</div>
+ <ul>
+START:requires
+ <li>HREF:aref:name:</li>