polyblock 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a92299658f7303efd6feefcedd9ae1f402366c2a
4
- data.tar.gz: 2832a3dd1838a1cdad87f1f0b1d88515e1441162
3
+ metadata.gz: a5431ce08071cf86b397e36aeea37599757119d5
4
+ data.tar.gz: d49a53f8a8153a86fc19adef8bed5dfba1558410
5
5
  SHA512:
6
- metadata.gz: 17fe32d78b3c2ca2d1520b8a2292b8246b07115422159824a2b2c86278a6f0f10bd7f858873129e4080b04e3a2a0fee3d54c2c5b075ce8d6dae7611c4b2bbefe
7
- data.tar.gz: 7128999258a93f7f3d435cf0634e11de5af1428d8a6790b891ca7ea76ffb14fcd5fc74c42beccc56b4a4924dda761657849340e9ac57efba939c063e6dfaa850
6
+ metadata.gz: 1f4855ebd857aba89ea075267b85a51282f9ad4a7ffa5c2cc75afad24886546bafa4189dc0805ef5c743c5160054aaf1a50080471c13d32e1b4cc1dbd121ee2e
7
+ data.tar.gz: b2927232df13beed70eab6c63b290d2100ce7ee456c2ed79907e578acb2f18b5c5fbf8188cbc8facab24e491b516f6b31a72896abb70d36083065611516e4cb9
@@ -58,15 +58,15 @@ module Polyblock
58
58
  end
59
59
 
60
60
  def self.fetch_or_initialize(name)
61
- if name.is_a? Block
62
- name
63
- elsif name.is_a? String
64
- matches = where :name => name
65
- if matches.any?
66
- matches.first
67
- else
68
- new({:name => name})
61
+ if name.is_a?(Block) then name
62
+ else
63
+ name = name.to_s if name.is_a? Symbol
64
+ unless name.is_a? String
65
+ raise 'Invalid name passed to Polyblock::Block#fetch_or_initialize'
69
66
  end
67
+ matches = find_by(name: name)
68
+ return matches if matches.present?
69
+ new({name: name})
70
70
  end
71
71
  end
72
72
  def self.fetch_or_create(name)
@@ -14,7 +14,7 @@ module Polyblock
14
14
  # Fill the editor content
15
15
  page.execute_script <<-SCRIPT
16
16
  var ckeditor = CKEDITOR.instances['#{locator}'];
17
- ckeditor.setData('#{params[:with].gsub("'", "\\\'")}');
17
+ ckeditor.setData('#{params[:with].gsub("'", "\\\\'")}');
18
18
  ckeditor.focus();
19
19
  setTimeout(function(){
20
20
  ckeditor.updateElement();
@@ -0,0 +1,11 @@
1
+ require 'polyblock'
2
+ require 'polyblock/strong_params_helper'
3
+
4
+ module Polyblock
5
+ module ControllerHelpers
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ include StrongParamsHelper
9
+ end
10
+ end
11
+ end
@@ -1,12 +1,32 @@
1
- require "ckeditor"
2
- require 'polyblock/strong_params_helper'
1
+ require 'polyblock'
2
+ require 'ckeditor'
3
3
 
4
4
  module Polyblock
5
- class Engine < Rails::Engine
5
+ require 'rails'
6
+ class Engine < ::Rails::Engine
6
7
  isolate_namespace Polyblock
8
+
9
+ require 'polyblock/controller_helpers'
10
+ require 'polyblock/view_helpers'
11
+ require 'polyblock/strong_params_helper'
12
+ require 'polyblock/simple_form_helper'
13
+
7
14
  initializer 'polyblock_engine.action_controller' do |app|
8
15
  ActiveSupport.on_load :action_controller do
9
- helper Polyblock::StrongParamsHelper
16
+ ActionController::Base.send :include, ControllerHelpers
17
+ end
18
+ end
19
+
20
+ initializer 'polyblock.view_helpers' do
21
+ ActiveSupport.on_load :action_view do
22
+ ActionView::Base.send :include, ViewHelpers
23
+ if defined? SimpleForm
24
+ ActionView::Base.send :include, SimpleFormHelper
25
+ SimpleForm::FormBuilder.send :define_method, 'simple_fields_for_polyblock' do |*args, &block|
26
+ name, *remaining_args = args
27
+ template.simple_fields_for_polyblock name, self, *remaining_args, &block
28
+ end
29
+ end
10
30
  end
11
31
  end
12
32
  end
@@ -1,22 +1,14 @@
1
- require 'polyblock/view_helpers'
2
1
  require 'polyblock/glue'
3
2
 
4
3
  module Polyblock
5
4
  require 'rails'
6
5
 
7
6
  class Railtie < Rails::Railtie
8
- initializer "polyblock.insert_into_active_record" do |app|
7
+ initializer 'polyblock.insert_into_active_record' do |app|
9
8
  ActiveSupport.on_load :active_record do
10
9
  Polyblock::Railtie.insert
11
10
  end
12
11
  end
13
-
14
- initializer "polyblock.view_helpers" do
15
- ActionView::Base.send :include, ViewHelpers
16
- end
17
- # initializer "polyblock.capybara_helpers" do
18
- # RSpec.send :include, CapybaraHelpers
19
- # end
20
12
  end
21
13
 
22
14
  class Railtie
@@ -0,0 +1,59 @@
1
+ require 'polyblock'
2
+
3
+ module Polyblock
4
+ module SimpleFormHelper
5
+
6
+ # def self.simple_fields_for_polyblock(fb, title, *args, &block)
7
+ # ( '<div class="polyblock-fields">' <<
8
+ # fb.simple_fields_for(title, *args, &block) << '</div>' ).html_safe
9
+ # end
10
+ # def simple_fields_for_polyblock(fb, title, *args, &block)
11
+ # if title.is_a? FormBuilder
12
+ # return retrofit_simple_fields_for_polyblock(fb, title, *args, &block)
13
+ # end
14
+ # pb = pb_from_name(name, fb)
15
+ # new_block = block_given? ? block : ->(fb2) {
16
+ # render partial: 'polyblock/simple_fields_for',
17
+ # locals: { f: fb2 } }
18
+ # Polyblock::SimpleFormHelper.simple_fields_for_polyblock(
19
+ # fb, title, *args, &new_block)
20
+ # end
21
+
22
+ # Retrofit method
23
+ # def retrofit_simple_fields_for_polyblock(name, f, options={}, &block)
24
+ def simple_fields_for_polyblock(name, f, options={}, &block)
25
+ pb = pb_from_name(name, f)
26
+ settings = {
27
+ :field => {
28
+ :as => :ckeditor,
29
+ :label => name.to_s.titleize,
30
+ :input_html => {
31
+ :value => pb.present? ? pb.content : nil
32
+ }
33
+ },
34
+ :use_input_field => false
35
+ }.deep_merge(options)
36
+
37
+ # Merge in legacy fields
38
+ [:label, :input_html].each{|o|
39
+ settings[:field][o] = settings[o] if settings[o].present? }
40
+
41
+ new_block = block_given? ? block : ->(fb2) {
42
+ render partial: 'polyblock/simple_fields_for',
43
+ locals: { f: fb2, pb: pb, name: name, options: settings } }
44
+ new_block.call(f)
45
+ end
46
+
47
+ protected
48
+ def pb_from_name(name, fb)
49
+ if name.is_a?(Symbol)
50
+ if fb.object.is_a?(Polyblock::Block) then fb.object
51
+ else fb.object.send(name) end
52
+ else
53
+ foi_block = Block.fetch_or_initialize name
54
+ return foi_block if foi_block.present?
55
+ raise 'Invalid name passed to pb_from_name helper!'
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module Polyblock
2
- VERSION = "1.1.1"
2
+ VERSION = '1.2.0'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'polyblock'
2
+
1
3
  module Polyblock
2
4
  module ViewHelpers
3
5
 
@@ -58,26 +60,26 @@ module Polyblock
58
60
  render :partial => 'polyblock/fields_for', :locals => {:f => f, :pb => pb, :name => name, :options => options}
59
61
  end
60
62
 
61
- def simple_fields_for_polyblock(name, f, options={})
62
- pb = pb_from_name(name, f)
63
- settings = {
64
- :field => {
65
- :as => :ckeditor,
66
- :label => name.to_s.titleize,
67
- :input_html => {
68
- :value => pb.present? ? pb.content : nil
69
- }
70
- },
71
- :use_input_field => false
72
- }.deep_merge(options)
73
-
74
- # Merge in legacy fields
75
- [:label, :input_html].each{|o|
76
- settings[:field][o] = settings[o] if settings[o].present? }
77
-
78
- render partial: 'polyblock/simple_fields_for',
79
- locals: { f: f, pb: pb, name: name, options: settings }
80
- end
63
+ # def simple_fields_for_polyblock(name, f, options={})
64
+ # pb = pb_from_name(name, f)
65
+ # settings = {
66
+ # :field => {
67
+ # :as => :ckeditor,
68
+ # :label => name.to_s.titleize,
69
+ # :input_html => {
70
+ # :value => pb.present? ? pb.content : nil
71
+ # }
72
+ # },
73
+ # :use_input_field => false
74
+ # }.deep_merge(options)
75
+ #
76
+ # # Merge in legacy fields
77
+ # [:label, :input_html].each{|o|
78
+ # settings[:field][o] = settings[o] if settings[o].present? }
79
+ #
80
+ # render partial: 'polyblock/simple_fields_for',
81
+ # locals: { f: f, pb: pb, name: name, options: settings }
82
+ # end
81
83
 
82
84
  def simple_form_for_polyblocks(options={})
83
85
  options = {
@@ -90,19 +92,15 @@ module Polyblock
90
92
  render :partial => 'polyblock/editor_bar'
91
93
  end
92
94
 
93
- private
94
- def pb_from_name(name, f)
95
- if name.is_a?(Polyblock::Block) then name
96
- elsif name.is_a?(String)
97
- Block.fetch_or_initialize(name)
98
- elsif name.is_a?(Symbol)
99
- if f.object.is_a? Block
100
- f.object
101
- else
102
- f.object.send(name)
103
- end
95
+ protected
96
+ def pb_from_name(name, fb)
97
+ if name.is_a?(Symbol)
98
+ if fb.object.is_a?(Polyblock::Block) then fb.object
99
+ else fb.object.send(name) end
104
100
  else
105
- raise 'Invalid name passed to Polyblock pb helper!'
101
+ foi_block = Block.fetch_or_initialize name
102
+ return foi_block if foi_block.present?
103
+ raise 'Invalid name passed to pb_from_name helper!'
106
104
  end
107
105
  end
108
106
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-13 00:00:00.000000000 Z
11
+ date: 2015-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -285,10 +285,12 @@ files:
285
285
  - lib/generators/polyblock/install/templates/polyblock_migration.rb
286
286
  - lib/polyblock.rb
287
287
  - lib/polyblock/capybara_helpers.rb
288
+ - lib/polyblock/controller_helpers.rb
288
289
  - lib/polyblock/engine.rb
289
290
  - lib/polyblock/glue.rb
290
291
  - lib/polyblock/has_polyblock.rb
291
292
  - lib/polyblock/railtie.rb
293
+ - lib/polyblock/simple_form_helper.rb
292
294
  - lib/polyblock/strong_params_helper.rb
293
295
  - lib/polyblock/validators.rb
294
296
  - lib/polyblock/validators/polyblock_presence_validator.rb