Permalink
Browse files

Initial version commit

  • Loading branch information...
0 parents commit 29d501c5ca8a1b8a6186ad5463e3d0ca640b5b27 @Slotos Slotos committed Apr 17, 2012
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,17 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/./version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Slotos"]
+ gem.email = ["slotos@gmail.com"]
+ gem.description = %q{Implementation of globalize_fields - has_many friendly Globalize3 helper for ActiveAdmin.}
+ gem.summary = %q{Globalize3 helper for ActiveAdmin.}
+ gem.homepage = "https://github.com/mimimi/ActiveAdmin-Globalize3-inputs"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "ActiveAdmin-Globalize3-inputs"
+ gem.require_paths = ["lib"]
+ gem.version = GlobalizeAAInputs::VERSION
+end
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in ..gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Slotos
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
+# .
+
+This small hack implements has_many friendly Globalize3 helper for ActiveAdmin.
+
+Admittedly it generates structure that [jQueryUI tabs()](http://jqueryui.com/demos/tabs/) expect. However the whole idea is pretty simple and you should be able to change it to suit your needs.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'ActiveAdmin-Globalize3-inputs', :git => 'https://github.com/mimimi/ActiveAdmin-Globalize3-inputs'
+
+And then execute:
+
+ $ bundle
+
+## Usage by example
+
+```ruby
+ActiveAdmin.register Gallery do
+ form do |f|
+ f.globalize_inputs :translations do |lf|
+ lf.inputs do
+ lf.input :title
+ lf.input :description
+
+ lf.input :locale, :as => :hidden
+ end
+ end
+
+ f.has_many :photos do |photo|
+ photo.inputs do
+ photo.input :image, :as => :file
+ end
+
+ photo.globalize_inputs :translations do |lp|
+ lp.inputs do
+ lp.input :description
+
+ lp.input :locale, :as => :hidden
+ end
+ end
+ end
+
+ f.buttons
+ end
+end
+```
+
+## Contributing
+
+1. Fork
+2. Invent better name
+3. Improve
+4. Enjoy
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
+require 'formtastic/globalize_inputs'
+require 'active_admin/globalize_inputs'
@@ -0,0 +1,8 @@
+module ActiveAdmin
+ class FormBuilder
+ def globalize_inputs(*args, &proc)
+ content = with_new_form_buffer { super }
+ form_buffers.last << content.html_safe
+ end
+ end
+end
@@ -0,0 +1,25 @@
+module Formtastic
+ class FormBuilder
+ def globalize_inputs(*args, &proc)
+ index = options[:child_index] || "#{self.object.class.to_s}-#{self.object.object_id}"
+ linker = ActiveSupport::SafeBuffer.new
+ fields = ActiveSupport::SafeBuffer.new
+ ::I18n.available_locales.each do |locale|
+ linker << self.template.content_tag(:li,
+ self.template.content_tag(:a,
+ ::I18n.t("translation.#{locale}"),
+ :href => "#lang-#{locale}-#{index}"
+ )
+ )
+ fields << self.template.content_tag(:div,
+ self.semantic_fields_for(*(args.dup << self.object.translation_for(locale)), &proc),
+ :id => "lang-#{locale}-#{index}"
+ )
+ end
+
+ linker = self.template.content_tag(:ul, linker, :class => "language-selection")
+
+ self.template.content_tag(:div, linker + fields, :class => "language-tabs-#{index}") + self.template.content_tag(:script, "$('.language-tabs-#{index}').tabs();", :type => "text/javascript")
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module GlobalizeAAInputs
+ VERSION = "0.0.1"
+end

0 comments on commit 29d501c

Please sign in to comment.