refinerycms-formtastic 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ .formtastic {
2
+ .input {
3
+ .label {
4
+ float: none;
5
+ margin: 0 0 0.5em 0;
6
+
7
+ abbr {
8
+ margin-left: 0.3em;
9
+ }
10
+ }
11
+ }
12
+
13
+ .inputs {
14
+ input {
15
+ width: 400px;
16
+ }
17
+
18
+ input, textarea, select {
19
+ border: 1px solid #7F9DB9;
20
+ line-height: 20px;
21
+ padding: 0.4% 0.5%;
22
+ }
23
+
24
+ input.widest, select.widest, textarea.widest {
25
+ width: 98%;
26
+ }
27
+ select.widest {
28
+ max-width: 98%;
29
+ }
30
+
31
+ input.larger {
32
+ font-size: 200%;
33
+ }
34
+ }
35
+
36
+ .tab-panels {
37
+ fieldset {
38
+ border: 1px solid red;
39
+
40
+ ol {
41
+ background-color: #F2F2F2;
42
+ border: 1px solid #CCCCCC;
43
+ padding: 5px;
44
+ }
45
+ }
46
+ }
47
+
48
+ fieldset {
49
+ ol {
50
+ li.wymeditor {
51
+ width: 100%;
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ .ui-tabs {
58
+ margin-bottom: 1em;
59
+ }
@@ -0,0 +1,71 @@
1
+ module Refinery
2
+ module Formtastic
3
+ module PageTabsHelper
4
+ def tabbed_fieldsets(form, tabs, i18n_scope = nil)
5
+ content_tag(:div, :class => 'field') do
6
+ content_tag(:div, :id => 'page-tabs', :class => 'clearfix ui-tabs ui-widget ui-widget-content ui-corner-all') do
7
+ tabbed_fieldset_headers(tabs, i18n_scope) +
8
+ tabbed_fieldset_bodies(form, tabs)
9
+ end
10
+ end
11
+ end
12
+
13
+ def tabbed_fieldset_headers(tabs, i18n_scope = nil)
14
+ content_tag(:ul, :id => 'page_parts') do
15
+ contents = []
16
+ tabs.each_with_index do |tab, tab_index|
17
+ classes = ['ui-state-default']
18
+ classes << 'ui-state-active' if tab_index == 0
19
+ contents << content_tag(:li, :class => classes.join(' ')) do
20
+ link_to tab_name(tab, i18n_scope), "##{tab_id(tab)}"
21
+ end
22
+ end
23
+ contents.join("\n").html_safe
24
+ end
25
+ end
26
+
27
+ def tabbed_fieldset_bodies(form, tabs)
28
+ content_tag(:div, :id => 'page_part_editors') do
29
+ tabs.map do |tab|
30
+ tabbed_fieldset_body(form, tab)
31
+ end.join("\n").html_safe
32
+ end
33
+ end
34
+
35
+ def tabbed_fieldset_body(form, tab)
36
+ if tab.is_a?(Symbol)
37
+ editor_only_fieldset_body(form, tab)
38
+ else
39
+ partial_fieldset_body(form, tab)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def tab_id(tab)
46
+ name = tab.is_a?(Symbol) ? tab : tab.name
47
+ end
48
+
49
+ def tab_name(tab, i18n_scope = nil)
50
+ name = tab_id(tab)
51
+ t(name.to_s, :scope => i18n_scope, :default => name.to_s.titleize)
52
+ end
53
+
54
+ def editor_only_fieldset_body(form, tab)
55
+ content_tag(:div, :class => 'page_part', :id => tab.to_s) do
56
+ form.inputs do
57
+ form.input tab, :as => :wymeditor
58
+ end
59
+ end
60
+ end
61
+
62
+ def partial_fieldset_body(form, tab)
63
+ content_tag(:div, :class => 'page_part', :id => 'images') do
64
+ render tab.partial, :f => form
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ Refinery::AdminController.send(:helper, 'refinery/formtastic/page_tabs')
@@ -0,0 +1,5 @@
1
+ class WymeditorInput < Formtastic::Inputs::TextInput
2
+ def input_html_options
3
+ super.merge(:class => 'wymeditor widest', :rows => 20)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ formtastics:
5
+ title: Formtastic
@@ -0,0 +1,5 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ formtastics:
5
+ title: Formtastic
@@ -0,0 +1,5 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ formtastics:
5
+ title: Formtastic
@@ -0,0 +1,5 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ formtastics:
5
+ title: Formtastic
@@ -0,0 +1,5 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ formtastics:
5
+ title: Formtastic
@@ -0,0 +1,19 @@
1
+ module Refinery
2
+ class FormtasticsGenerator < Rails::Generators::Base
3
+
4
+ def rake_db
5
+ rake("refinery_formtastics:install:migrations")
6
+ end
7
+
8
+ def append_load_seed_data
9
+ create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
10
+ append_file 'db/seeds.rb', :verbose => true do
11
+ <<-EOH
12
+
13
+ # Added by Refinery CMS Formtastics extension
14
+ Refinery::Formtastics::Engine.load_seed
15
+ EOH
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ require 'refinerycms-core'
2
+ require 'formtastic'
3
+
4
+ module Refinery
5
+ autoload :FormtasticGenerator, 'generators/refinery/formtastic_generator'
6
+
7
+ module Formtastics
8
+ require 'refinery/formtastic/engine'
9
+
10
+ class << self
11
+ attr_writer :root
12
+
13
+ def root
14
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
15
+ end
16
+
17
+ def factory_paths
18
+ @factory_paths ||= [ root.join('spec', 'factories').to_s ]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module Refinery
2
+ module Formtastic
3
+ class Engine < Rails::Engine
4
+ isolate_namespace Refinery::Formtastic
5
+
6
+ config.after_initialize do
7
+ Refinery::Core.config.register_stylesheet("formtastic")
8
+ Refinery::Core.config.register_stylesheet("refinery/formtastic/admin")
9
+ require 'refinery/formtastic/extensions/page_tab'
10
+ require 'refinery/formtastic/page_tabs_helper'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'refinery/pages/tab'
2
+
3
+ module Refinery
4
+ module Pages
5
+ class Tab
6
+ def initialize(options = {})
7
+ options.each do |key, value|
8
+ self.send("#{key}=", value)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ require 'refinery/formtastic'
data/readme.md ADDED
@@ -0,0 +1,83 @@
1
+ # Formtastic extension for Refinery CMS.
2
+
3
+ The purpose of this extension is to allow the use of formtastic within Refinery CMS admin views. The main
4
+ user of this would be other extensions, in which case be sure to add a dependency on this gem to your
5
+ extension.
6
+
7
+ ## Why use this gem?
8
+
9
+ In general, Refinery CMS attempts to follow a path of the most common rails way, in order to make it accessible
10
+ to as many developers as possible. When building CRUD interfaces, I find that most rails developers tend to use
11
+ a form builder of some sort. Although there are other excellent candidates, Formtastic appears to be the most
12
+ widely used form builder, which is predominantly why it was chosen here.
13
+
14
+ The reasons for using this over the default Refinery option (of no form builder) are twofold.
15
+
16
+ Firstly, for brevity. It'll let you replace this:
17
+
18
+ ```erb
19
+ <div class='field'>
20
+ <%= f.label :latitude -%>
21
+ <%= f.text_field :latitude -%>
22
+ </div>
23
+
24
+ <div class='field'>
25
+ <%= f.label :longitude -%>
26
+ <%= f.text_field :longitude -%>
27
+ </div>
28
+ ```
29
+
30
+ With this:
31
+
32
+ ```erb
33
+ <%= f.inputs :latitude, :longitude %>
34
+ ```
35
+
36
+ This comes with all the usual benefits of removing duplication, such as less chance of getting the markup wrong
37
+ in one specific place.
38
+
39
+ Secondly, for more object oriented field helpers. I strongly recommend creating custom field type classes for any
40
+ type of custom field input (such as an image picker, map location selector, a number with currency, etc). The
41
+ benefits of using a object oriented structure for this over the more functional programming style of using helpers
42
+ (let alone just wacking it in the view) should be obvious.
43
+
44
+ ## Can my Refinery CMS app have a mix of engines with and without formtastic?
45
+
46
+ Yes. I've tried to style the formtastic forms to look identical to Refinery defaults.
47
+
48
+ ## To install
49
+
50
+ Add "refinerycms-formtastic" to your gemfile. There are no generators or migrations to run.
51
+
52
+ ## Input types
53
+
54
+ I've included an input type class for the Wymeditor textareas
55
+
56
+ ```ruby
57
+ f.input tab, :as => :wymeditor
58
+ ```
59
+
60
+ ## Refinery Specific helpers
61
+
62
+ I've added a helper to replace the huge swathe of markup needed to add the tabbed panels used in most
63
+ refinery extensions (such as Pages, Blog, etc).
64
+
65
+ ```erb
66
+ <%= tabbed_fieldsets f, [
67
+ :description,
68
+ :potential_uses,
69
+ Refinery::Pages::Tab.new(:name => 'images', :partial => '/refinery/admin/pages/tabs/images')
70
+ ] %>
71
+ ```
72
+ It must be supplied with the form object, and an array of tabs. These tabs can be a symbol, in which case
73
+ they simply display a Wymeditor field of that name, or a Refinery::Pages::Tab object, which basically
74
+ just defines a name and a partial.
75
+
76
+ ## How to build this extension as a gem
77
+
78
+ cd vendor/extensions/formtastic
79
+ gem build refinerycms-formtastic.gemspec
80
+ gem install refinerycms-formtastic.gem
81
+
82
+ # Sign up for a http://rubygems.org/ account and publish the gem
83
+ gem push refinerycms-formtastic.gem
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-formtastic
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Craig Ambrose
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: refinerycms-core
16
+ requirement: &70236508182500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70236508182500
25
+ - !ruby/object:Gem::Dependency
26
+ name: formtastic
27
+ requirement: &70236508182020 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70236508182020
36
+ - !ruby/object:Gem::Dependency
37
+ name: refinerycms-testing
38
+ requirement: &70236508181560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.5
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70236508181560
47
+ description: A rails engine which allows the use of Formtastic in the RefineryCMS
48
+ backend.
49
+ email: craig@craigambrose.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - app/assets/stylesheets/refinery/formtastic/admin.css.scss
55
+ - app/helpers/refinery/formtastic/page_tabs_helper.rb
56
+ - app/inputs/wymeditor_input.rb
57
+ - config/locales/en.yml
58
+ - config/locales/es.yml
59
+ - config/locales/fr.yml
60
+ - config/locales/nb.yml
61
+ - config/locales/nl.yml
62
+ - lib/generators/refinery/formtastics_generator.rb
63
+ - lib/refinery/formtastic/engine.rb
64
+ - lib/refinery/formtastic/extensions/page_tab.rb
65
+ - lib/refinery/formtastic.rb
66
+ - lib/refinerycms-formtastic.rb
67
+ - readme.md
68
+ homepage: http://github.com/craigambrose/refinerycms-formtastic
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.17
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Use formtastic with Refinery CMS
92
+ test_files: []