sketchily 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README.md +4 -0
  2. data/Rakefile +5 -4
  3. data/app/assets/javascripts/sketchily_embed.js +1 -1
  4. data/app/assets/javascripts/sketchily_embed.js~ +0 -3
  5. data/app/views/sketchily/_embed.html.erb +27 -4
  6. data/app/views/sketchily/_embed.html.erb~ +27 -5
  7. data/app/views/sketchily/_embed.js.erb +6 -3
  8. data/app/views/sketchily/_embed.js.erb~ +4 -4
  9. data/lib/sketchily.rb +1 -10
  10. data/lib/sketchily.rb~ +2 -11
  11. data/lib/sketchily/sketchily.rb +18 -6
  12. data/lib/sketchily/sketchily.rb~ +19 -6
  13. data/lib/sketchily/sketchily_tag.rb +9 -3
  14. data/lib/sketchily/sketchily_tag.rb~ +10 -3
  15. data/lib/sketchily/version.rb +1 -1
  16. data/lib/sketchily/version.rb~ +1 -1
  17. data/spec/dummy/app/controllers/sketchily_controller.rb +9 -0
  18. data/spec/dummy/app/models/drawing.rb +2 -0
  19. data/spec/dummy/app/models/drawing.rb~ +3 -0
  20. data/spec/dummy/app/views/sketchily/sketchily.html.erb +3 -0
  21. data/spec/dummy/app/views/sketchily/sketchily_tag.html.erb +3 -0
  22. data/spec/dummy/config/routes.rb +3 -56
  23. data/spec/dummy/config/routes.rb~ +5 -0
  24. data/spec/dummy/db/development.sqlite3 +0 -0
  25. data/spec/dummy/db/migrate/20130211122120_create_drawings.rb +7 -0
  26. data/spec/dummy/db/schema.rb +20 -0
  27. data/spec/dummy/db/test.sqlite3 +0 -0
  28. data/spec/dummy/log/development.log +192 -0
  29. data/spec/dummy/log/test.log +75 -0
  30. data/spec/features/sketchily.rb~ +9 -0
  31. data/spec/features/sketchily_spec.rb +10 -0
  32. data/spec/features/sketchily_spec.rb~ +9 -0
  33. data/spec/features/sketchily_tag.rb~ +9 -0
  34. data/spec/features/sketchily_tag_spec.rb +10 -0
  35. data/spec/features/sketchily_tag_spec.rb~ +9 -0
  36. data/spec/features/user_views_sketchily_spec.rb~ +15 -0
  37. data/spec/{spec_helper.rb → minitest_helper.rb} +2 -1
  38. data/spec/spec_helper.rb~ +19 -0
  39. data/vendor/assets/javascripts/base64.js +95 -0
  40. data/vendor/assets/javascripts/base64.js~ +95 -0
  41. metadata +76 -4
data/README.md CHANGED
@@ -68,6 +68,10 @@ Currently available options are:
68
68
  - `hide_image_tool` true if you want to hide the image tool button
69
69
  - `hide_hyperlink_tool` true if you want to hide the hyperlink tool button
70
70
 
71
+ - `show_layers` (true if you want the layer selector to display automatically when the editor is loaded)
72
+
73
+ - `url` override contents of the canvas with the svg file in the given url (careful: changes lost whenever editor is loaded)
74
+
71
75
  - `id` override the default id (see explanation below)
72
76
  - `value` override the default value (the svg itself; can be useful when using form_for)
73
77
  - `index` override the default index (affects the tag name; can be useful when using form_for)
data/Rakefile CHANGED
@@ -16,11 +16,11 @@ RDoc::Task.new(:rdoc) do |rdoc|
16
16
  rdoc.rdoc_dir = 'rdoc'
17
17
  rdoc.title = 'Sketchily'
18
18
  rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
19
+ rdoc.rdoc_files.include('README.md')
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
26
 
@@ -30,9 +30,10 @@ Bundler::GemHelper.install_tasks
30
30
  require 'rake/testtask'
31
31
 
32
32
  Rake::TestTask.new(:test) do |t|
33
+ Rake::Task['app:db:test:prepare'].invoke
33
34
  t.libs << 'lib'
34
- t.libs << 'test'
35
- t.pattern = 'test/**/*_test.rb'
35
+ t.libs << 'spec'
36
+ t.pattern = 'spec/**/*_spec.rb'
36
37
  t.verbose = false
37
38
  end
38
39
 
@@ -1,2 +1,2 @@
1
1
  //= require embedapi
2
- //= require svgutils
2
+ //= require base64
@@ -1,4 +1 @@
1
- //= require jquery
2
- //= require jquery_ujs
3
1
  //= require embedapi
4
- //= require svgutils
@@ -11,12 +11,33 @@
11
11
  hide_rulers ||= false
12
12
  hide_menu ||= false
13
13
  hide_image_tool ||= false
14
- hide_hyperlink_tool ||= false %>
14
+ hide_hyperlink_tool ||= false
15
+ show_layers ||= false
16
+ url ||= nil
17
+ %>
18
+
19
+ <% iframe_src = URI.parse("/assets/svg-editor.html")
20
+
21
+ query_hash = {:dimensions => [canvas_width, canvas_height].join(','),
22
+ :canvas_expansion => canvas_expansion,
23
+ :showRulers => !hide_rulers,
24
+ :showlayers => show_layers}
25
+ if url
26
+ query_hash[:url] = url
27
+ else
28
+ query_hash[:source] = nil
29
+ end
30
+
31
+ iframe_src.query = query_hash.map{|k,v| "#{k}=#{v}"}.join('&') %>
15
32
 
16
33
  <%= javascript_include_tag "sketchily_embed" %>
17
34
 
18
- <iframe src="/assets/svg-editor.html?source=&dimensions=<%= "#{canvas_width},#{canvas_height}" %>&canvas_expansion=<%= canvas_expansion %>&showRulers=<%= !hide_rulers %>"
19
- width="<%= width %>" height="<%= height %>" id="svgedit_<%= id %>"></iframe>
35
+ <%= content_tag(:iframe,
36
+ "svg-edit",
37
+ :src => iframe_src.to_s.html_safe,
38
+ :width => width,
39
+ :height => height,
40
+ :id => "svgedit_#{id}") %>
20
41
 
21
42
  <script type="text/javascript">
22
43
  <%= render :partial => "sketchily/embed",
@@ -25,5 +46,7 @@
25
46
  :value => value,
26
47
  :hide_menu => hide_menu,
27
48
  :hide_image_tool => hide_image_tool,
28
- :hide_hyperlink_tool => hide_hyperlink_tool} %>
49
+ :hide_hyperlink_tool => hide_hyperlink_tool,
50
+ :url => url} %>
29
51
  </script>
52
+
@@ -11,10 +11,34 @@
11
11
  hide_rulers ||= false
12
12
  hide_menu ||= false
13
13
  hide_image_tool ||= false
14
- hide_hyperlink_tool ||= false %>
14
+ hide_hyperlink_tool ||= false
15
+ show_layers ||= false
16
+ url ||= nil
17
+ %>
18
+
19
+ <% iframe_src = URI.parse("/assets/svg-editor.html")
20
+
21
+ query_hash = {:dimensions => [canvas_width, canvas_height].join(','),
22
+ :canvas_expansion => canvas_expansion,
23
+ :showRulers => !hide_rulers,
24
+ :showlayers => show_layers}
25
+ if url
26
+ query_hash[:url] = url
27
+ else
28
+ query_hash[:source] = nil
29
+ end
30
+
31
+ iframe_src.query = query_hash.map{|k,v| "#{k}=#{v}"}.join('&') %>
15
32
 
16
33
  <%= javascript_include_tag "sketchily_embed" %>
17
34
 
35
+ <%= content_tag(:iframe,
36
+ "svg-edit",
37
+ :src => iframe_src.to_s.html_safe,
38
+ :width => width,
39
+ :height => height,
40
+ :id => "svgedit_#{id}") %>
41
+
18
42
  <script type="text/javascript">
19
43
  <%= render :partial => "sketchily/embed",
20
44
  :formats => :js,
@@ -22,8 +46,6 @@
22
46
  :value => value,
23
47
  :hide_menu => hide_menu,
24
48
  :hide_image_tool => hide_image_tool,
25
- :hide_hyperlink_tool => hide_hyperlink_tool} %>
49
+ :hide_hyperlink_tool => hide_hyperlink_tool,
50
+ :url => url} %>
26
51
  </script>
27
-
28
- <iframe src="/assets/svg-editor.html?source=&dimensions=<%= "#{canvas_width},#{canvas_height}" %>&canvas_expansion=<%= canvas_expansion %>&showRulers=<%= !hide_rulers %>"
29
- width="<%= width %>" height="<%= height %>" id="svgedit_<%= id %>"></iframe>
@@ -5,7 +5,8 @@
5
5
  # value
6
6
  # hide_menu
7
7
  # hide_image_tool
8
- # hide_hyperlink_tool %>
8
+ # hide_hyperlink_tool
9
+ # url %>
9
10
 
10
11
  var svgCanvas_<%= id %> = null;
11
12
 
@@ -24,7 +25,7 @@ function handleSvgData_<%= id %>(data, error) {
24
25
  alert('Error: ' + error);
25
26
  }
26
27
  else {
27
- $("input#<%= id %>").attr("value", svgedit.utilities.encode64("<?xml version=\"1.0\"?>\n" + data));
28
+ $("input#<%= id %>").attr("value", sketchily_encode64("<?xml version=\"1.0\"?>\n" + data));
28
29
  $("input#<%= id %>").closest("form").off("submit", submitHandler_<%= id %>);
29
30
  $("input#<%= id %>").closest("form").one("submit", attachSubmitHandler_<%= id %>);
30
31
  $("input#<%= id %>").closest("form").submit();
@@ -58,7 +59,9 @@ function initEmbed_<%= id %>() {
58
59
  hyperlinkTool.parentNode.removeChild(hyperlinkTool);
59
60
  <% end %>
60
61
 
61
- svgCanvas_<%= id %>.setSvgString(svgedit.utilities.decode64("<%= value.try(:squish) %>"));
62
+ <% unless url %>
63
+ svgCanvas_<%= id %>.setSvgString(sketchily_decode64("<%= value.try(:squish) %>"));
64
+ <% end %>
62
65
 
63
66
  attachSubmitHandler_<%= id %>();
64
67
  }
@@ -5,7 +5,8 @@
5
5
  # value
6
6
  # hide_menu
7
7
  # hide_image_tool
8
- # hide_hyperlink_tool %>
8
+ # hide_hyperlink_tool
9
+ # url %>
9
10
 
10
11
  var svgCanvas_<%= id %> = null;
11
12
 
@@ -24,9 +25,8 @@ function handleSvgData_<%= id %>(data, error) {
24
25
  alert('Error: ' + error);
25
26
  }
26
27
  else {
27
- $("input#<%= id %>").attr("value", svgedit.utilities.encode64("<?xml version=\"1.0\"?>\n" + data));
28
+ $("input#<%= id %>").attr("value", sketchily_encode64("<?xml version=\"1.0\"?>\n" + data));
28
29
  $("input#<%= id %>").closest("form").off("submit", submitHandler_<%= id %>);
29
- waitingForCallback_<%= id %> = false;
30
30
  $("input#<%= id %>").closest("form").one("submit", attachSubmitHandler_<%= id %>);
31
31
  $("input#<%= id %>").closest("form").submit();
32
32
  }
@@ -59,7 +59,7 @@ function initEmbed_<%= id %>() {
59
59
  hyperlinkTool.parentNode.removeChild(hyperlinkTool);
60
60
  <% end %>
61
61
 
62
- svgCanvas_<%= id %>.setSvgString(svgedit.utilities.decode64("<%= value.try(:squish) %>"));
62
+ svgCanvas_<%= id %>.setSvgString(sketchily_decode64("<%= value.try(:squish) %>"));
63
63
 
64
64
  attachSubmitHandler_<%= id %>();
65
65
  }
data/lib/sketchily.rb CHANGED
@@ -5,21 +5,12 @@ 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
- SKETCHILY_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, :show_layers, :url]
9
9
  TAG_OPTIONS = [:id, :value, :index]
10
10
  OPTIONS = SKETCHILY_OPTIONS + TAG_OPTIONS
11
11
 
12
- ROOT = File.expand_path('../..', __FILE__)
13
-
14
- VIEW = ActionView::Base.new
15
- VIEW.view_paths << "#{ROOT}/app/views"
16
-
17
12
  ActiveSupport.on_load(:before_initialize) do
18
13
  Rails.configuration.assets.precompile += Sketchily::ASSET_FILES
19
14
  end
20
-
21
- def self.render(options = {}, local_assigns = {}, &block)
22
- VIEW.render(options, local_assigns, &block).html_safe
23
- end
24
15
  end
25
16
 
data/lib/sketchily.rb~ CHANGED
@@ -5,21 +5,12 @@ 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
- 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]
8
+ SKETCHILY_OPTIONS = [:width, :height, :canvas_width, :canvas_height, :canvas_expansion, :hide_rulers, :hide_menu, :hide_image_tool, :hide_hyperlink_tool, :url, :show_layers]
9
+ TAG_OPTIONS = [:id, :value, :index]
10
10
  OPTIONS = SKETCHILY_OPTIONS + TAG_OPTIONS
11
11
 
12
- ROOT = File.expand_path('../..', __FILE__)
13
-
14
- VIEW = ActionView::Base.new
15
- VIEW.view_paths << "#{ROOT}/app/views"
16
-
17
12
  ActiveSupport.on_load(:before_initialize) do
18
13
  Rails.configuration.assets.precompile += Sketchily::ASSET_FILES
19
14
  end
20
-
21
- def self.render(options = {}, local_assigns = {}, &block)
22
- VIEW.render(options, local_assigns, &block).html_safe
23
- end
24
15
  end
25
16
 
@@ -1,9 +1,15 @@
1
1
  module Sketchily
2
2
  module FormBuilderInstanceMethods
3
3
  def sketchily(method, options = {})
4
- Sketchily.render(:partial => "sketchily/sketchily",
5
- :locals => {:template => @template, :object_name => @object_name,
6
- :method => method, :options => objectify_options(options)})
4
+ @template.render(
5
+ :partial => "sketchily/sketchily",
6
+ :locals => {
7
+ :template => @template,
8
+ :object_name => @object_name,
9
+ :method => method,
10
+ :options => objectify_options(options)
11
+ }
12
+ )
7
13
  end
8
14
 
9
15
  def svg_edit(method, options = {})
@@ -13,9 +19,15 @@ module Sketchily
13
19
 
14
20
  module ActionViewBaseInstanceMethods
15
21
  def sketchily(object_name, method, options = {})
16
- Sketchily.render(:partial => "sketchily/sketchily",
17
- :locals => {:template => self, :object_name => object_name,
18
- :method => method, :options => options})
22
+ self.render(
23
+ :partial => "sketchily/sketchily",
24
+ :locals => {
25
+ :template => self,
26
+ :object_name => object_name,
27
+ :method => method,
28
+ :options => options
29
+ }
30
+ )
19
31
  end
20
32
 
21
33
  def svg_edit(object_name, method, options = {})
@@ -1,9 +1,16 @@
1
1
  module Sketchily
2
2
  module FormBuilderInstanceMethods
3
3
  def sketchily(method, options = {})
4
- Sketchily.render(:partial => "sketchily/sketchily",
5
- :locals => {:template => @template, :object_name => @object_name,
6
- :method => method, :options => objectify_options(options)}).html_safe
4
+ @template ||= self
5
+ @template.render(
6
+ :partial => "sketchily/sketchily",
7
+ :locals => {
8
+ :template => @template,
9
+ :object_name => @object_name,
10
+ :method => method,
11
+ :options => objectify_options(options)
12
+ }
13
+ )
7
14
  end
8
15
 
9
16
  def svg_edit(method, options = {})
@@ -13,9 +20,15 @@ module Sketchily
13
20
 
14
21
  module ActionViewBaseInstanceMethods
15
22
  def sketchily(object_name, method, options = {})
16
- Sketchily.render(:partial => "sketchily/sketchily",
17
- :locals => {:template => self, :object_name => object_name,
18
- :method => method, :options => options}).html_safe
23
+ self.render(
24
+ :partial => "sketchily/sketchily",
25
+ :locals => {
26
+ :template => self,
27
+ :object_name => object_name,
28
+ :method => method,
29
+ :options => options
30
+ }
31
+ )
19
32
  end
20
33
 
21
34
  def svg_edit(object_name, method, options = {})
@@ -1,9 +1,15 @@
1
1
  module SketchilyTag
2
2
  module ActionViewBaseInstanceMethods
3
3
  def sketchily_tag(name, value = nil, options = {})
4
- Sketchily.render(:partial => "sketchily/sketchily_tag",
5
- :locals => {:name => name, :id => sanitize_to_id(name),
6
- :value => value, :options => options})
4
+ self.render(
5
+ :partial => "sketchily/sketchily_tag",
6
+ :locals => {
7
+ :name => name,
8
+ :id => sanitize_to_id(name),
9
+ :value => value,
10
+ :options => options
11
+ }
12
+ )
7
13
  end
8
14
 
9
15
  def svg_edit_tag(name, value = nil, options = {})
@@ -1,9 +1,16 @@
1
1
  module SketchilyTag
2
2
  module ActionViewBaseInstanceMethods
3
3
  def sketchily_tag(name, value = nil, options = {})
4
- Sketchily.render(:partial => "sketchily/sketchily_tag",
5
- :locals => {:name => name, :id => sanitize_to_id(name),
6
- :value => value, :options => options}).html_safe
4
+ self.render(
5
+ :partial => "sketchily/sketchily_tag",
6
+ :locals => {
7
+ :template => self,
8
+ :name => name,
9
+ :id => sanitize_to_id(name),
10
+ :value => value,
11
+ :options => options
12
+ }
13
+ )
7
14
  end
8
15
 
9
16
  def svg_edit_tag(name, value = nil, options = {})
@@ -1,3 +1,3 @@
1
1
  module Sketchily
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Sketchily
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -0,0 +1,9 @@
1
+ class SketchilyController < ApplicationController
2
+ def sketchily
3
+ @drawing = Drawing.new
4
+ end
5
+
6
+ def sketchily_tag
7
+ @drawing = Drawing.new
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ class Drawing < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class Drawing < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ <%= form_for @drawing do |f| %>
2
+ <%= f.sketchily :svg %>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= form_tag 'drawing', :url => drawings_path do %>
2
+ <%= sketchily_tag 'drawing' %>
3
+ <% end %>
@@ -1,58 +1,5 @@
1
1
  Dummy::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
4
-
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
8
-
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
12
-
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
14
- # resources :products
15
-
16
- # Sample resource route with options:
17
- # resources :products do
18
- # member do
19
- # get 'short'
20
- # post 'toggle'
21
- # end
22
- #
23
- # collection do
24
- # get 'sold'
25
- # end
26
- # end
27
-
28
- # Sample resource route with sub-resources:
29
- # resources :products do
30
- # resources :comments, :sales
31
- # resource :seller
32
- # end
33
-
34
- # Sample resource route with more complex sub-resources
35
- # resources :products do
36
- # resources :comments
37
- # resources :sales do
38
- # get 'recent', :on => :collection
39
- # end
40
- # end
41
-
42
- # Sample resource route within a namespace:
43
- # namespace :admin do
44
- # # Directs /admin/products/* to Admin::ProductsController
45
- # # (app/controllers/admin/products_controller.rb)
46
- # resources :products
47
- # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => 'welcome#index'
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- # match ':controller(/:action(/:id))(.:format)'
2
+ resource :drawings
3
+ get 'sketchily', :to => 'sketchily#sketchily'
4
+ get 'sketchily_tag', :to => 'sketchily#sketchily_tag'
58
5
  end