pdzioba-areeya_textile 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = areeya_textile
2
2
 
3
- Prosty plugin do obsługi Textile w modelach ActiveRecord. Wymaga RedCloth[http://redcloth.org] oraz RSpec.
3
+ Prosty plugin do obsługi Textile w modelach ActiveRecord oraz widokach. Wymaga RedCloth[http://redcloth.org] oraz RSpec.
4
4
 
5
5
  Paweł Dzioba <pdzioba@me.com>
6
6
 
@@ -27,6 +27,10 @@ lub wpisując w config/environment.rb w aplikacji:
27
27
 
28
28
  == Wykorzystanie:
29
29
 
30
+ === Model
31
+
32
+ Przykład:
33
+
30
34
  class Page < ActiveRecord::Base
31
35
  acts_as_textile :body
32
36
  end
@@ -35,3 +39,18 @@ lub wpisując w config/environment.rb w aplikacji:
35
39
  @page.body.to_s #=> "h2. Textile Headline"
36
40
  @page.body.to_html #=> "<h2>Textile Headline</h2>"
37
41
 
42
+ === Widok
43
+
44
+ Skopiowanie wymaganych plików:
45
+
46
+ rake areeya_textile:install
47
+
48
+ Przykłady:
49
+
50
+ <%= text_area :page, :body %> # standardowe pole tekstowe
51
+ <%= textile_area :page, :body %> # pole tekstowe z paskiem narzędziowym
52
+ <%= textile_area :page, :body, :rows => 5, :cols => 10 %>
53
+
54
+ <% form_for :page do |f| -%> # pole tekstowe w formularzu
55
+ <%= f.textile_area :body %>
56
+ <% end -%>
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{areeya_textile}
5
- s.version = "1.0.0"
5
+ s.version = "1.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Pawe\305\202 Dzioba"]
9
- s.date = %q{2009-01-18}
10
- s.description = %q{Prosty plugin do obsługi Textile w modelach ActiveRecord.}
9
+ s.date = %q{2009-02-04}
10
+ s.description = %q{Prosty plugin do obsługi Textile w modelach ActiveRecord oraz widokach.}
11
11
  s.email = %q{pdzioba@me.com}
12
12
  s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
13
- s.files = ["init.rb", "LICENSE", "README.rdoc", "areeya_textile.gemspec", "lib/areeya_textile.rb", "lib/model_extensions.rb", "rails/init.rb", "spec/model_extensions_spec.rb", "spec/schema.rb", "spec/spec_helper.rb"]
13
+ s.files = ["init.rb", "LICENSE", "README.rdoc", "areeya_textile.gemspec", "files/public", "files/public/images", "files/public/images/areeya_textile", "files/public/images/areeya_textile/bold.png", "files/public/images/areeya_textile/hyperlink.png", "files/public/images/areeya_textile/image.png", "files/public/images/areeya_textile/italic.png", "files/public/images/areeya_textile/underline.png", "files/public/javascripts", "files/public/javascripts/areeya_textile.js", "lib/areeya_textile.rb", "lib/asset_copier.rb", "lib/model_extensions.rb", "lib/view_extensions.rb", "rails/init.rb", "spec/model_extensions_spec.rb", "spec/schema.rb", "spec/spec_helper.rb", "spec/view_extensions_spec.rb", "tasks/areeya_textile.rake"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/pdzioba/areeya_textile}
16
16
  s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--charset=UTF-8"]
@@ -0,0 +1,39 @@
1
+ function surround_selection(text_area, prefix, suffix) {
2
+ text_area = $(text_area);
3
+ if (document.selection) { //IE support
4
+ text_area.focus();
5
+ sel = document.selection.createRange();
6
+ if (sel.text != "")
7
+ sel.text = prefix + sel.text + suffix;
8
+ } else if (text_area.selectionStart || text_area.selectionStart == '0') { //Mozilla/Firefox/Netscape 7+ support
9
+ var startPos = text_area.selectionStart;
10
+ var endPos = text_area.selectionEnd;
11
+ selected_text = text_area.value.substring(startPos, endPos);
12
+ if (selected_text != "")
13
+ text_area.value = text_area.value.substring(0, startPos) + prefix + selected_text + suffix +
14
+ text_area.value.substring(endPos, text_area.value.length);
15
+ }
16
+ }
17
+
18
+ function insert_at_selection(text_area, value) {
19
+ text_area = $(text_area);
20
+ if (document.selection) { //IE support
21
+ text_area.focus();
22
+ document.selection.createRange().text = value;
23
+ } else if (text_area.selectionStart || text_area.selectionStart == '0') { //Mozilla/Firefox/Netscape 7+ support
24
+ var startPos = text_area.selectionStart;
25
+ var endPos = text_area.selectionEnd;
26
+ text_area.value = text_area.value.substring(0, startPos) + value +
27
+ text_area.value.substring(endPos, text_area.value.length);
28
+ }
29
+ }
30
+
31
+ function insert_hyperlink(text_area) {
32
+ url = prompt("Wprowadź adres URL:", "http://");
33
+ surround_selection(text_area, '"', '":' + url);
34
+ }
35
+
36
+ function insert_image(text_area) {
37
+ url = prompt("Wprowadź adres URL obrazka: ", "http://");
38
+ insert_at_selection(text_area, '!' + url + '!');
39
+ }
@@ -1,3 +1,4 @@
1
1
  module AreeyaTextile; end
2
2
 
3
3
  require File.dirname(__FILE__) + '/model_extensions'
4
+ require File.dirname(__FILE__) + '/view_extensions'
@@ -0,0 +1,87 @@
1
+ require 'find'
2
+ require 'digest/md5'
3
+
4
+ module AreeyaTextile
5
+ class AssetCopier
6
+ @source = File.expand_path(File.join(File.dirname(__FILE__), '..', 'files'))
7
+ @destination = RAILS_ROOT
8
+ @deleted_files = File.expand_path(File.join(File.dirname(__FILE__), '..', 'deleted_files'))
9
+ class << self
10
+ attr_accessor :source, :destination, :deleted_files
11
+ end
12
+
13
+ def self.copy(plugin_name)
14
+ begin
15
+ each_path do |path, dest_path, short_path|
16
+ if File.directory?(path)
17
+ unless File.exists?(dest_path)
18
+ FileUtils.mkdir_p(dest_path)
19
+ log "Tworzenie katalogu #{short_path} dla #{plugin_name}"
20
+ end
21
+ elsif !compare(path, dest_path)
22
+ FileUtils.cp(path, dest_path)
23
+ log "Kopiowanie #{short_path} z #{plugin_name}"
24
+ end
25
+ end
26
+ rescue Exception => e
27
+ log "Błąd podczas kopiowania plików: #{e.inspect}"
28
+ raise e
29
+ end
30
+ print_deletion_warnings(plugin_name)
31
+ end
32
+
33
+ def self.warn(plugin_name)
34
+ each_path do |path, dest_path, short_path|
35
+ next if File.directory?(path)
36
+ reinstall = false
37
+ if File.exists?(dest_path)
38
+ unless compare(path, dest_path)
39
+ log "UWAGA: #{short_path} musi być ponownie zainstalowany"
40
+ reinstall = true
41
+ end
42
+ else
43
+ reinstall = true
44
+ log "UWAGA: #{short_path} musi być zainstalowany"
45
+ end
46
+ log "UWAGA: Uruchom rake #{plugin_name}:install" if reinstall
47
+ end
48
+ print_deletion_warnings(plugin_name)
49
+ end
50
+
51
+ def self.compare(file1, file2)
52
+ File.exists?(file1) && File.exists?(file2) &&
53
+ Digest::MD5.hexdigest(File.read(file1)) == Digest::MD5.hexdigest(File.read(file2))
54
+ end
55
+
56
+ def self.print_deletion_warnings(plugin_name)
57
+ File.open(deleted_files, "r") do |f|
58
+ f.readlines.reject { |l| l =~ /^#/ || l.strip.blank? }.each do |l|
59
+ log "UWAGA: #{l} nie jest już dłużej wymagany przez plugin #{plugin_name} " <<
60
+ "i można go usunąć" if File.exists?(l)
61
+ end
62
+ end
63
+ end
64
+
65
+ def self.paths
66
+ returning [] do |paths|
67
+ Find.find(source) do |path|
68
+ Find.prune if path =~ /\/\..+/
69
+ Find.prune if path =~ /(CVS|.svn|.git)/
70
+ paths << path
71
+ end
72
+ end
73
+ end
74
+
75
+ def self.each_path
76
+ paths.each do |path|
77
+ dest_path = path.gsub(source, destination)
78
+ short_path = dest_path.gsub("#{destination}/", "")
79
+ yield path, dest_path, short_path
80
+ end
81
+ end
82
+
83
+ def self.log(msg)
84
+ puts msg
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,33 @@
1
+ module AreeyaTextile::ViewExtensions
2
+ module TextileArea
3
+ def textile_area(object_name, method, options={})
4
+ disable = options.delete(:disable) || {}
5
+ toolbar = textile_toolbar(options[:id] || "#{object_name}_#{method}", disable)
6
+ "<div class=\"areeya_textile\">#{toolbar}</div>" <<
7
+ "<div class=\"textile_area\">#{text_area(object_name, method, options)}</div>"
8
+ end
9
+
10
+ def textile_toolbar(id, disable)
11
+ html = javascript_include_tag("areeya_textile")
12
+ html << link_to_function(image_tag("areeya_textile/bold.png", :size => "23x22", :title => "Pogrubione"), "surround_selection('#{id}', '*', '*')")
13
+ html << "&nbsp;"
14
+ html << link_to_function(image_tag("areeya_textile/italic.png", :size => "23x22", :title => "Kursywa"), "surround_selection('#{id}', '_', '_')")
15
+ html << "&nbsp;"
16
+ html << link_to_function(image_tag("areeya_textile/underline.png", :size => "23x22", :title => "Podkreślenie"), "surround_selection('#{id}', '+', '+')")
17
+ html << "&nbsp;"
18
+ html << link_to_function(image_tag("areeya_textile/hyperlink.png", :size => "23x22", :title => "Link"), "insert_hyperlink('#{id}')")
19
+ html << "&nbsp;"
20
+ unless disable == :image
21
+ html << link_to_function(image_tag("areeya_textile/image.png", :size => "23x22", :title => "Obrazek"), "insert_image('#{id}')")
22
+ html << "&nbsp;&nbsp;"
23
+ end
24
+ html << "<small>(" << link_to("Textile Reference", "http://hobix.com/textile/", :target => "_blank") << ")</small>"
25
+ end
26
+ end
27
+
28
+ module FormBuilder
29
+ def textile_area(method, options={})
30
+ @template.textile_area(@object_name, method, options)
31
+ end
32
+ end
33
+ end
data/rails/init.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../lib/areeya_textile'
2
2
 
3
3
  ActiveRecord::Base.send(:include, AreeyaTextile::ModelExtensions::ActsMethods)
4
+ ActionView::Base.send :include, AreeyaTextile::ViewExtensions::TextileArea
5
+ ActionView::Helpers::FormBuilder.send :include, AreeyaTextile::ViewExtensions::FormBuilder
6
+
@@ -4,7 +4,7 @@ class Page < ActiveRecord::Base
4
4
  acts_as_textile :content
5
5
  end
6
6
 
7
- describe 'Atrybut z acts_as_textile' do
7
+ describe "Atrybut z acts_as_textile" do
8
8
  before(:each) do
9
9
  @page = Page.create(:name => 'Title', :content => 'h2. Textile Test Text')
10
10
  end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ include AreeyaTextile::ViewExtensions::TextileArea
4
+ include ActionView::Helpers::TagHelper
5
+ include ActionView::Helpers::AssetTagHelper
6
+ include ActionView::Helpers::JavaScriptHelper
7
+ include ActionView::Helpers::UrlHelper
8
+ include ActionView::Helpers::FormHelper
9
+
10
+ describe 'textile_area' do
11
+ it "powinien renderować text_area" do
12
+ textile_area(:article, :body).include?("<textarea").should be_true
13
+ textile_area(:article, :body).include?("</textarea>").should be_true
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/asset_copier')
2
+
3
+ namespace :areeya_textile do
4
+ desc "Instalacja plików wymaganych przez areeya_textile"
5
+ task :install do
6
+ AreeyaTextile::AssetCopier.copy "areeya_textile"
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdzioba-areeya_textile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Pawe\xC5\x82 Dzioba"
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-18 00:00:00 -08:00
12
+ date: 2009-02-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: "Prosty plugin do obs\xC5\x82ugi Textile w modelach ActiveRecord."
16
+ description: "Prosty plugin do obs\xC5\x82ugi Textile w modelach ActiveRecord oraz widokach."
17
17
  email: pdzioba@me.com
18
18
  executables: []
19
19
 
@@ -27,12 +27,26 @@ files:
27
27
  - LICENSE
28
28
  - README.rdoc
29
29
  - areeya_textile.gemspec
30
+ - files/public
31
+ - files/public/images
32
+ - files/public/images/areeya_textile
33
+ - files/public/images/areeya_textile/bold.png
34
+ - files/public/images/areeya_textile/hyperlink.png
35
+ - files/public/images/areeya_textile/image.png
36
+ - files/public/images/areeya_textile/italic.png
37
+ - files/public/images/areeya_textile/underline.png
38
+ - files/public/javascripts
39
+ - files/public/javascripts/areeya_textile.js
30
40
  - lib/areeya_textile.rb
41
+ - lib/asset_copier.rb
31
42
  - lib/model_extensions.rb
43
+ - lib/view_extensions.rb
32
44
  - rails/init.rb
33
45
  - spec/model_extensions_spec.rb
34
46
  - spec/schema.rb
35
47
  - spec/spec_helper.rb
48
+ - spec/view_extensions_spec.rb
49
+ - tasks/areeya_textile.rake
36
50
  has_rdoc: true
37
51
  homepage: http://github.com/pdzioba/areeya_textile
38
52
  post_install_message: