sketchily 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -56,17 +56,28 @@ This gem also adds a helper method that can be called to display the resulting S
56
56
 
57
57
  Currently available options are:
58
58
 
59
- - `width` (total width of editor)
60
- - `height` (total height of editor)
61
- - `canvas_width` (initial canvas width)
62
- - `canvas_height` (initial canvas height)
63
- - `canvas_expansion` (0 if you want to disable scrolling)
64
- - `hide_rulers` (true if you want to hide the canvas rulers)
65
- - `hide_menu` (true if you want svg-edit's menu to be hidden)
66
- - `hide_image_tool` (true if you want to hide the image tool button)
67
- - `hide_hyperlink_tool` (true if you want to hide the hyperlink tool button)
59
+ - `width` total width of editor
60
+ - `height` total height of editor
61
+
62
+ - `canvas_width` initial canvas width
63
+ - `canvas_height` initial canvas height
64
+ - `canvas_expansion` 0 if you want to disable scrolling
65
+
66
+ - `hide_rulers` true if you want to hide the canvas rulers
67
+ - `hide_menu` true if you want svg-edit's menu to be hidden
68
+ - `hide_image_tool` true if you want to hide the image tool button
69
+ - `hide_hyperlink_tool` true if you want to hide the hyperlink tool button
70
+
71
+ - `id` override the default id (see explanation below)
72
+ - `value` override the default value (the svg itself; can be useful when using form_for)
73
+ - `index` override the default index (affects the tag name; can be useful when using form_for)
74
+
68
75
  - other standard html attributes for the input tag
69
76
 
77
+ Sketchily requires a unique `id` (by default, this is set in the same way as hidden_field) each time it is called in the same page.
78
+ However, some uses of `form_for` can generate repeated ids (e.g. multiple `form_for @my_object.new` in the same page).
79
+ In those cases, you need to generate and specify your own unique ids. A possible solution is to use one of the many uuid generator gems.
80
+
70
81
  It is recommended that the database entries associated with sketchily form elements be of type `text`.
71
82
 
72
83
  The following examples assume that the database table for `@my_object` has a `sketch` column of type `text`.
@@ -4,13 +4,13 @@
4
4
  # method
5
5
  # options %>
6
6
 
7
- <% sketchily_tag = ActionView::Helpers::InstanceTag.new(object_name, method, template, options.delete(:object)) %>
7
+ <% sketchily_tag = ActionView::Helpers::InstanceTag.new(object_name, method, template, options.delete(:object))
8
+ options = {:id => sketchily_tag.send(:tag_id),
9
+ :value => sketchily_tag.value(sketchily_tag.object)}.merge(options) %>
8
10
 
9
11
  <%= render :partial => "sketchily/embed",
10
12
  :formats => :html,
11
- :locals => options.slice(*Sketchily::OPTIONS).merge(
12
- {:id => sketchily_tag.send(:tag_id),
13
- :value => sketchily_tag.value(sketchily_tag.object)}) %>
13
+ :locals => options.slice(*Sketchily::OPTIONS) %>
14
14
 
15
- <%= sketchily_tag.to_input_field_tag("hidden", options.except(*Sketchily::OPTIONS)) %>
15
+ <%= sketchily_tag.to_input_field_tag("hidden", options.except(*Sketchily::SKETCHILY_OPTIONS)) %>
16
16
 
@@ -4,12 +4,14 @@
4
4
  # method
5
5
  # options %>
6
6
 
7
- <% sketchily_tag = ActionView::Helpers::InstanceTag.new(object_name, method, template, options.delete(:object)) %>
7
+ <% sketchily_tag = ActionView::Helpers::InstanceTag.new(object_name, method, template, options.delete(:object))
8
+ options = {:id => sketchily_tag.send(:tag_id),
9
+ :value => sketchily_tag.value(sketchily_tag.object)}.merge(
10
+ options) %>
8
11
 
9
12
  <%= render :partial => "sketchily/embed",
10
13
  :formats => :html,
11
- :locals => {:id => sketchily_tag.send(:tag_id),
12
- :value => sketchily_tag.value(sketchily_tag.object)}.merge(options.slice(*Sketchily::OPTIONS)) %>
14
+ :locals => options.slice(*Sketchily::OPTIONS) %>
13
15
 
14
- <%= sketchily_tag.to_input_field_tag("hidden", options.except(*Sketchily::OPTIONS)) %>
16
+ <%= sketchily_tag.to_input_field_tag("hidden", options.except(*Sketchily::SKETCHILY_OPTIONS)) %>
15
17
 
@@ -4,11 +4,12 @@
4
4
  # value
5
5
  # options %>
6
6
 
7
+ <% options = {:id => id,
8
+ :value => value}.merge(options) %>
9
+
7
10
  <%= render :partial => "sketchily/embed",
8
11
  :formats => :html,
9
- :locals => options.slice(*Sketchily::OPTIONS).merge(
10
- {:id => id,
11
- :value => value}) %>
12
+ :locals => options.slice(*Sketchily::OPTIONS) %>
12
13
 
13
- <%= tag :input, { "type" => "hidden", "name" => name, "id" => id, "value" => value }.update(options.except(*Sketchily::OPTIONS).stringify_keys) %>
14
+ <%= tag :input, {"type" => "hidden", "name" => name}.update(options.except(*Sketchily::SKETCHILY_OPTIONS).stringify_keys) %>
14
15
 
@@ -4,10 +4,13 @@
4
4
  # value
5
5
  # options %>
6
6
 
7
+ <% options = {:id => id,
8
+ :value => value}.merge(
9
+ options.slice(*Sketchily::OPTIONS)) %>
10
+
7
11
  <%= render :partial => "sketchily/embed",
8
12
  :formats => :html,
9
- :locals => {:id => id,
10
- :value => value}.merge(options.slice(*Sketchily::OPTIONS)) %>
13
+ :locals => options %>
11
14
 
12
- <%= tag :input, { "type" => "hidden", "name" => name, "id" => id, "value" => value }.update(options.except(*Sketchily::OPTIONS).stringify_keys) %>
15
+ <%= tag :input, {"type" => "hidden", "name" => name}.update(options.except(*Sketchily::SKETCHILY_OPTIONS).stringify_keys) %>
13
16
 
@@ -3,7 +3,7 @@ module Sketchily
3
3
  def sketchily(method, options = {})
4
4
  Sketchily.render(:partial => "sketchily/sketchily",
5
5
  :locals => {:template => @template, :object_name => @object_name,
6
- :method => method, :options => objectify_options(options)}).html_safe
6
+ :method => method, :options => objectify_options(options)})
7
7
  end
8
8
 
9
9
  def svg_edit(method, options = {})
@@ -15,7 +15,7 @@ module Sketchily
15
15
  def sketchily(object_name, method, options = {})
16
16
  Sketchily.render(:partial => "sketchily/sketchily",
17
17
  :locals => {:template => self, :object_name => object_name,
18
- :method => method, :options => options}).html_safe
18
+ :method => method, :options => options})
19
19
  end
20
20
 
21
21
  def svg_edit(object_name, method, options = {})
@@ -26,3 +26,4 @@ end
26
26
 
27
27
  ActionView::Helpers::FormBuilder.send :include, Sketchily::FormBuilderInstanceMethods
28
28
  ActionView::Base.send :include, Sketchily::ActionViewBaseInstanceMethods
29
+
@@ -3,7 +3,7 @@ module SketchilyTag
3
3
  def sketchily_tag(name, value = nil, options = {})
4
4
  Sketchily.render(:partial => "sketchily/sketchily_tag",
5
5
  :locals => {:name => name, :id => sanitize_to_id(name),
6
- :value => value, :options => options}).html_safe
6
+ :value => value, :options => options})
7
7
  end
8
8
 
9
9
  def svg_edit_tag(name, value = nil, options = {})
@@ -13,3 +13,4 @@ module SketchilyTag
13
13
  end
14
14
 
15
15
  ActionView::Base.send :include, SketchilyTag::ActionViewBaseInstanceMethods
16
+
@@ -1,3 +1,3 @@
1
1
  module Sketchily
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Sketchily
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.4"
3
3
  end
data/lib/sketchily.rb CHANGED
@@ -5,7 +5,9 @@ require "sketchily/sketchily_tag"
5
5
  module Sketchily
6
6
  ASSET_FILES = %w(sketchily.css sketchily.js sketchily_embed.js canvg/canvg.js canvg/rgbcolor.js extensions/ext-*.js locale/lang.*.js)
7
7
 
8
- OPTIONS = [:width, :height, :canvas_width, :canvas_height, :canvas_expansion, :hide_rulers, :hide_menu, :hide_image_tool, :hide_hyperlink_tool]
8
+ SKETCHILY_OPTIONS = [:width, :height, :canvas_width, :canvas_height, :canvas_expansion, :hide_rulers, :hide_menu, :hide_image_tool, :hide_hyperlink_tool]
9
+ TAG_OPTIONS = [:id, :value, :index]
10
+ OPTIONS = SKETCHILY_OPTIONS + TAG_OPTIONS
9
11
 
10
12
  ROOT = File.expand_path('../..', __FILE__)
11
13
 
@@ -17,7 +19,7 @@ module Sketchily
17
19
  end
18
20
 
19
21
  def self.render(options = {}, local_assigns = {}, &block)
20
- VIEW.render(options, local_assigns, &block)
22
+ VIEW.render(options, local_assigns, &block).html_safe
21
23
  end
22
24
  end
23
25
 
data/lib/sketchily.rb~ CHANGED
@@ -5,7 +5,9 @@ require "sketchily/sketchily_tag"
5
5
  module Sketchily
6
6
  ASSET_FILES = %w(sketchily.css sketchily.js sketchily_embed.js canvg/canvg.js canvg/rgbcolor.js extensions/ext-*.js locale/lang.*.js)
7
7
 
8
- OPTIONS = [:width, :height, :canvas_width, :canvas_height, :canvas_expansion, :hide_rulers, :hide_menu, :hide_image_tool, :hide_hyperlink_tool]
8
+ SKETCHILY_OPTIONS = [:width, :height, :canvas_width, :canvas_height, :canvas_expansion, :hide_rulers, :hide_menu, :hide_image_tool, :hide_hyperlink_tool]
9
+ TAG_OPTIONS = [:id, :value]
10
+ OPTIONS = SKETCHILY_OPTIONS + TAG_OPTIONS
9
11
 
10
12
  ROOT = File.expand_path('../..', __FILE__)
11
13
 
@@ -17,9 +19,7 @@ module Sketchily
17
19
  end
18
20
 
19
21
  def self.render(options = {}, local_assigns = {}, &block)
20
- VIEW.render(options, local_assigns, &block)
22
+ VIEW.render(options, local_assigns, &block).html_safe
21
23
  end
22
24
  end
23
25
 
24
-
25
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sketchily
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: