Permalink
Browse files

Removed in place editing stuff - not part of Rails core, therefore no…

…t in the scope of demo app.
  • Loading branch information...
1 parent 84fe576 commit 4e07c995f8aa432092454e8d94ecdf0ae6564e49 @clemens committed Aug 28, 2008
@@ -1,22 +0,0 @@
-<%= javascript_include_tag :defaults %>
-<h2>InPlaceEditing</h2>
-<div>
- <table>
- <tr>
- <th scope="row">in_place_editor('id1', :url => {:action => 'update_value'}, :locale => 'en-US')</th>
- <td>
- <div id="id1"><%= I18n.t 'txt.ipe.click' %></div>
- <%= in_place_editor('id1', :url => {:action => 'update_value'}, :locale => 'en-US') %>
- </td>
- </tr>
- <tr>
- <th scope="row">in_place_editor('some_input', :url => {:action => 'update_value'})</th>
- <td>
- <div id="id2"><%= I18n.t 'txt.ipe.click' %></div>
- <%= in_place_editor('id2', :url => {:action => 'update_value'}) %>
- </td>
- </tr>
- </table>
-</div>
-
-<p style="text-align:right;"><%= link_to "&raquo; #{I18n.t('txt.menu.about')}", :action => 'about' %></p>
@@ -1,14 +0,0 @@
-InPlaceEditing
-==============
-
-Example:
-
- # Controller
- class BlogController < ApplicationController
- in_place_edit_for :post, :title
- end
-
- # View
- <%= in_place_editor_field :post, 'title' %>
-
-Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license
@@ -1,22 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Test in_place_editing plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc 'Generate documentation for in_place_editing plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'InPlaceEditing'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
@@ -1,2 +0,0 @@
-ActionController::Base.send :include, InPlaceEditing
-ActionController::Base.helper InPlaceMacrosHelper
@@ -1,25 +0,0 @@
-module InPlaceEditing
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- # Example:
- #
- # # Controller
- # class BlogController < ApplicationController
- # in_place_edit_for :post, :title
- # end
- #
- # # View
- # <%= in_place_editor_field :post, 'title' %>
- #
- module ClassMethods
- def in_place_edit_for(object, attribute, options = {})
- define_method("set_#{object}_#{attribute}") do
- @item = object.to_s.camelize.constantize.find(params[:id])
- @item.update_attribute(attribute, params[:value])
- render :text => @item.send(attribute).to_s
- end
- end
- end
-end
@@ -1,87 +0,0 @@
-module InPlaceMacrosHelper
- # Makes an HTML element specified by the DOM ID +field_id+ become an in-place
- # editor of a property.
- #
- # A form is automatically created and displayed when the user clicks the element,
- # something like this:
- # <form id="myElement-in-place-edit-form" target="specified url">
- # <input name="value" text="The content of myElement"/>
- # <input type="submit" value="ok"/>
- # <a onclick="javascript to cancel the editing">cancel</a>
- # </form>
- #
- # The form is serialized and sent to the server using an AJAX call, the action on
- # the server should process the value and return the updated value in the body of
- # the reponse. The element will automatically be updated with the changed value
- # (as returned from the server).
- #
- # Required +options+ are:
- # <tt>:url</tt>:: Specifies the url where the updated value should
- # be sent after the user presses "ok".
- #
- # Addtional +options+ are:
- # <tt>:rows</tt>:: Number of rows (more than 1 will use a TEXTAREA)
- # <tt>:cols</tt>:: Number of characters the text input should span (works for both INPUT and TEXTAREA)
- # <tt>:size</tt>:: Synonym for :cols when using a single line text input.
- # <tt>:cancel_text</tt>:: The text on the cancel link. (default: "cancel")
- # <tt>:save_text</tt>:: The text on the save link. (default: "ok")
- # <tt>:loading_text</tt>:: The text to display while the data is being loaded from the server (default: "Loading...")
- # <tt>:saving_text</tt>:: The text to display when submitting to the server (default: "Saving...")
- # <tt>:external_control</tt>:: The id of an external control used to enter edit mode.
- # <tt>:load_text_url</tt>:: URL where initial value of editor (content) is retrieved.
- # <tt>:options</tt>:: Pass through options to the AJAX call (see prototype's Ajax.Updater)
- # <tt>:with</tt>:: JavaScript snippet that should return what is to be sent
- # in the AJAX call, +form+ is an implicit parameter
- # <tt>:script</tt>:: Instructs the in-place editor to evaluate the remote JavaScript response (default: false)
- # <tt>:click_to_edit_text</tt>::The text shown during mouseover the editable text (default: "Click to edit")
- def in_place_editor(field_id, options = {})
-
- def text(key, options)
- options_value = options["#{key}_text".to_sym]
- locale_value = I18n.translate("in_place_editing.text.#{key}", :locale => options[:locale]) if !options_value
- value = options_value || (locale_value if !locale_value.start_with? "translation missing: ")
- "'#{value}'" if value
- end
-
- function = "new Ajax.InPlaceEditor("
- function << "'#{field_id}', "
- function << "'#{url_for(options[:url])}'"
-
- js_options = {}
-
- if protect_against_forgery?
- options[:with] ||= "Form.serialize(form)"
- options[:with] += " + '&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')"
- end
-
- js_options['cancelText'] = text(:cancel, options) if text(:cancel, options)
- js_options['okText'] = text(:save, options) if text(:save, options)
- js_options['loadingText'] = text(:loading, options) if text(:loading, options)
- js_options['savingText'] = text(:saving, options) if text(:saving, options)
- js_options['rows'] = options[:rows] if options[:rows]
- js_options['cols'] = options[:cols] if options[:cols]
- js_options['size'] = options[:size] if options[:size]
- js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control]
- js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url]
- js_options['ajaxOptions'] = options[:options] if options[:options]
- js_options['htmlResponse'] = !options[:script] if options[:script]
- js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with]
- js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text]
- js_options['textBetweenControls'] = %('#{options[:text_between_controls]}') if options[:text_between_controls]
- function << (', ' + options_for_javascript(js_options)) unless js_options.empty?
-
- function << ')'
-
- javascript_tag(function)
- end
-
- # Renders the value of the specified object and method with in-place editing capabilities.
- def in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {})
- tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
- tag_options = {:tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options)
- in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })
- tag.to_content_tag(tag_options.delete(:tag), tag_options) +
- in_place_editor(tag_options[:id], in_place_editor_options)
- end
-
-end
@@ -1,180 +0,0 @@
-# Authors:: Matt Aimonetti (http://railsontherun.com/),
-# Sven Fuchs (http://www.artweb-design.de),
-# Joshua Harvey (http://www.workingwithrails.com/person/759-joshua-harvey),
-# Saimon Moore (http://saimonmoore.net),
-# Stephan Soller (http://www.arkanis-development.de/)
-# Copyright:: Copyright (c) 2008 The Ruby i18n Team
-# License:: MIT
-require 'i18n/backend/simple'
-require 'i18n/exceptions'
-
-module I18n
- @@backend = Backend::Simple
- @@default_locale = 'en-US'
- @@exception_handler = :default_exception_handler
-
- class << self
- # Returns the current backend. Defaults to +Backend::Simple+.
- def backend
- @@backend
- end
-
- # Sets the current backend. Used to set a custom backend.
- def backend=(backend)
- @@backend = backend
- end
-
- # Returns the current default locale. Defaults to 'en-US'
- def default_locale
- @@default_locale
- end
-
- # Sets the current default locale. Used to set a custom default locale.
- def default_locale=(locale)
- @@default_locale = locale
- end
-
- # Returns the current locale. Defaults to I18n.default_locale.
- def locale
- Thread.current[:locale] ||= default_locale
- end
-
- # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
- def locale=(locale)
- Thread.current[:locale] = locale
- end
-
- # Sets the exception handler.
- def exception_handler=(exception_handler)
- @@exception_handler = exception_handler
- end
-
- # Allow client libraries to pass a block that populates the translation
- # storage. Decoupled for backends like a db backend that persist their
- # translations, so the backend can decide whether/when to yield or not.
- def populate(&block)
- backend.populate(&block)
- end
-
- # Stores translations for the given locale in the backend.
- def store_translations(locale, data)
- backend.store_translations locale, data
- end
-
- # Translates, pluralizes and interpolates a given key using a given locale,
- # scope, and default, as well as interpolation values.
- #
- # *LOOKUP*
- #
- # Translation data is organized as a nested hash using the upper-level keys
- # as namespaces. <em>E.g.</em>, ActionView ships with the translation:
- # <tt>:date => {:formats => {:short => "%b %d"}}</tt>.
- #
- # Translations can be looked up at any level of this hash using the key argument
- # and the scope option. <em>E.g.</em>, in this example <tt>I18n.t :date</tt>
- # returns the whole translations hash <tt>{:formats => {:short => "%b %d"}}</tt>.
- #
- # Key can be either a single key or a dot-separated key (both Strings and Symbols
- # work). <em>E.g.</em>, the short format can be looked up using both:
- # I18n.t 'date.formats.short'
- # I18n.t :'date.formats.short'
- #
- # Scope can be either a single key, a dot-separated key or an array of keys
- # or dot-separated keys. Keys and scopes can be combined freely. So these
- # examples will all look up the same short date format:
- # I18n.t 'date.formats.short'
- # I18n.t 'formats.short', :scope => 'date'
- # I18n.t 'short', :scope => 'date.formats'
- # I18n.t 'short', :scope => %w(date formats)
- #
- # *INTERPOLATION*
- #
- # Translations can contain interpolation variables which will be replaced by
- # values passed to #translate as part of the options hash, with the keys matching
- # the interpolation variable names.
- #
- # <em>E.g.</em>, with a translation <tt>:foo => "foo {{bar}}"</tt> the option
- # value for the key +bar+ will be interpolated into the translation:
- # I18n.t :foo, :bar => 'baz' # => 'foo baz'
- #
- # *PLURALIZATION*
- #
- # Translation data can contain pluralized translations. Pluralized translations
- # are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
- #
- # Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
- # pluralization rules. Other algorithms can be supported by custom backends.
- #
- # This returns the singular version of a pluralized translation:
- # I18n.t :foo, :count => 1 # => 'Foo'
- #
- # These both return the plural version of a pluralized translation:
- # I18n.t :foo, :count => 0 # => 'Foos'
- # I18n.t :foo, :count => 2 # => 'Foos'
- #
- # The <tt>:count</tt> option can be used both for pluralization and interpolation.
- # <em>E.g.</em>, with the translation
- # <tt>:foo => ['{{count}} foo', '{{count}} foos']</tt>, count will
- # be interpolated to the pluralized translation:
- # I18n.t :foo, :count => 1 # => '1 foo'
- #
- # *DEFAULTS*
- #
- # This returns the translation for <tt>:foo</tt> or <tt>default</tt> if no translation was found:
- # I18n.t :foo, :default => 'default'
- #
- # This returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt> if no
- # translation for <tt>:foo</tt> was found:
- # I18n.t :foo, :default => :bar
- #
- # Returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt>
- # or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
- # I18n.t :foo, :default => [:bar, 'default']
- #
- # <b>BULK LOOKUP</b>
- #
- # This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
- # I18n.t [:foo, :bar]
- #
- # Can be used with dot-separated nested keys:
- # I18n.t [:'baz.foo', :'baz.bar']
- #
- # Which is the same as using a scope option:
- # I18n.t [:foo, :bar], :scope => :baz
- def translate(key, options = {})
- locale = options.delete(:locale) || I18n.locale
- backend.translate locale, key, options
- rescue I18n::ArgumentError => e
- raise e if options[:raise]
- send @@exception_handler, e, locale, key, options
- end
- alias :t :translate
-
- # Localizes certain objects, such as dates and numbers to local formatting.
- def localize(object, options = {})
- locale = options[:locale] || I18n.locale
- format = options[:format] || :default
- backend.localize(locale, object, format)
- end
- alias :l :localize
-
- protected
- # Handles exceptions raised in the backend. All exceptions except for
- # MissingTranslationData exceptions are re-raised. When a MissingTranslationData
- # was caught and the option :raise is not set the handler returns an error
- # message string containing the key/scope.
- def default_exception_handler(exception, locale, key, options)
- return exception.message if MissingTranslationData === exception
- raise exception
- end
-
- # Merges the given locale, key and scope into a single array of keys.
- # Splits keys that contain dots into multiple keys. Makes sure all
- # keys are Symbols.
- def normalize_translation_keys(locale, key, scope)
- keys = [locale] + Array(scope) + [key]
- keys = keys.map{|k| k.to_s.split(/\./) }
- keys.flatten.map{|k| k.to_sym}
- end
- end
-end
Oops, something went wrong.

0 comments on commit 4e07c99

Please sign in to comment.