fckeditor 0.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.
- data/README +45 -0
- data/lib/connector.rb +5 -0
- data/lib/fckeditor.rb +112 -0
- metadata +40 -0
data/README
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
FCKeditor
|
2
|
+
|
3
|
+
========================================================
|
4
|
+
|
5
|
+
This is a class which creates the correct HTML to use the FCKeditor.
|
6
|
+
|
7
|
+
TODO:
|
8
|
+
-create connectors
|
9
|
+
-create better docs
|
10
|
+
|
11
|
+
Howto use with rails:
|
12
|
+
|
13
|
+
1. Install the gem
|
14
|
+
|
15
|
+
2. require the gem in your controller like:
|
16
|
+
|
17
|
+
--
|
18
|
+
require 'rubygems'
|
19
|
+
require_gem 'fckeditor'
|
20
|
+
--
|
21
|
+
|
22
|
+
3. Create a new editor instance like this:
|
23
|
+
|
24
|
+
--
|
25
|
+
@editor = FCKeditor.new('name_of_editor')
|
26
|
+
--
|
27
|
+
|
28
|
+
In your controller offcourse
|
29
|
+
|
30
|
+
4. Change properties of the editor, you can change:
|
31
|
+
|
32
|
+
-instance_name,
|
33
|
+
-width,
|
34
|
+
-height,
|
35
|
+
-toolbar_set,
|
36
|
+
-value,
|
37
|
+
-base_path,
|
38
|
+
-xml
|
39
|
+
-config
|
40
|
+
|
41
|
+
5. Dump the map of the FCKeditor in the public map
|
42
|
+
|
43
|
+
6. Create the editor in your rhtml file with:
|
44
|
+
|
45
|
+
@editor.create
|
data/lib/connector.rb
ADDED
data/lib/fckeditor.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
#Class which handles the creation of an instance of the FCKEditor in the browser
|
4
|
+
class FCKEditor
|
5
|
+
#Properties
|
6
|
+
attr_accessor :instance_name,
|
7
|
+
:width,
|
8
|
+
:height,
|
9
|
+
:toolbar_set,
|
10
|
+
:value,
|
11
|
+
:base_path,
|
12
|
+
:xml
|
13
|
+
|
14
|
+
attr_writer :config
|
15
|
+
|
16
|
+
#Contructor, sets default values and instance_name which must be unique
|
17
|
+
def initialize (instance_name)
|
18
|
+
@instance_name, @base_path, @width, @height, @toolbar_set, @value, @config, @xml = instance_name, '/../FCKeditor', '100%', '200', 'Default', '', Array.new, true
|
19
|
+
end
|
20
|
+
|
21
|
+
#Creates the HTML for the editor based on the user agent string
|
22
|
+
def create (user_agent)
|
23
|
+
if is_compatible? user_agent
|
24
|
+
link = build_link(@base_path + '/editor/fckeditor.html',
|
25
|
+
{:InstanceName => @instance_name,
|
26
|
+
:Toolbar => @toolbar_set} )
|
27
|
+
|
28
|
+
html = build_tag('input', {:type => 'hidden',
|
29
|
+
:id => @instance_name,
|
30
|
+
:name => @instance_name,
|
31
|
+
:value => CGI::escapeHTML(@value)}
|
32
|
+
)
|
33
|
+
|
34
|
+
html += build_tag('input',
|
35
|
+
{:type => 'hidden',
|
36
|
+
:id => @instance_name + '___Config',
|
37
|
+
:value => self.config}
|
38
|
+
)
|
39
|
+
|
40
|
+
html += build_tag('iframe',
|
41
|
+
{:id => @instance_name + '___Frame',
|
42
|
+
:src => link,
|
43
|
+
:width => @width,
|
44
|
+
:height => @height,
|
45
|
+
:frameborder => 'no',
|
46
|
+
:scrolling => 'no'},
|
47
|
+
false
|
48
|
+
)
|
49
|
+
else
|
50
|
+
html = build_tag('textarea',
|
51
|
+
{:name => @instance_name,
|
52
|
+
:rows => 4,
|
53
|
+
:cols => 40,
|
54
|
+
:style => "width: #{@width}; height: #{@height}",
|
55
|
+
:wrap => 'virtual'},
|
56
|
+
false,
|
57
|
+
CGI::escapeHTML(@value)
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
"<div>#{html}</div>"
|
62
|
+
end
|
63
|
+
|
64
|
+
#Build a link with params, :base is the directory, the rest of the key/value pairs are html encoded and are used as parameters for the link
|
65
|
+
def build_link (path, params)
|
66
|
+
path + '?' + params.dup.to_a.delete_if { |value|
|
67
|
+
value[0].to_s.empty?
|
68
|
+
}.map { |value|
|
69
|
+
value[0].to_s + '=' + value[1].to_s
|
70
|
+
}.join('&')
|
71
|
+
end
|
72
|
+
|
73
|
+
#Builds a HTML tag
|
74
|
+
#The tag_name is the name of the tag
|
75
|
+
#Params: key/value pairs form the tags parameters
|
76
|
+
#Self-closing: true => <tag_name content />
|
77
|
+
# false => <tag_name content></tag_name
|
78
|
+
#text: text between opening and closing tag, works only if self_closing = false
|
79
|
+
def build_tag (tag_name, params = {}, self_closing = true, text = '')
|
80
|
+
content = params.dup.to_a.delete_if { |value|
|
81
|
+
value[0].to_s.empty?
|
82
|
+
}.map { |value|
|
83
|
+
CGI::escapeHTML(value[0].to_s) + '="' + CGI::escapeHTML(value[1].to_s) + '"'
|
84
|
+
}.join(' ')
|
85
|
+
|
86
|
+
return self_closing ? "<#{tag_name} #{content}#{' /' if @xml}>" : "<#{tag_name} #{content}>#{text}</#{tag_name}>"
|
87
|
+
end
|
88
|
+
|
89
|
+
#Config values encoded as url params
|
90
|
+
def config
|
91
|
+
@config.dup.to_a.map { |value|
|
92
|
+
value[0].to_s + '=' + value[1].to_s
|
93
|
+
}.join('&')
|
94
|
+
end
|
95
|
+
|
96
|
+
#Checks if the browser is compatible based on the user agent string
|
97
|
+
def is_compatible? (user_agent)
|
98
|
+
if user_agent.include? 'MSIE' and (not user_agent.include? 'mac' or user_agent.include? 'Opera')
|
99
|
+
version = user_agent[(user_agent.rindex('MSIE') + 5), 3].to_f
|
100
|
+
return version > 5.5
|
101
|
+
elsif user_agent.include? 'Gecko/'
|
102
|
+
version = user_agent[(user_agent.rindex('Gecko/') + 6), 8].to_i
|
103
|
+
return version >= 20030210
|
104
|
+
else
|
105
|
+
return false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private :build_link,
|
110
|
+
:build_tag,
|
111
|
+
:is_compatible?
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.3
|
3
|
+
specification_version: 1
|
4
|
+
name: fckeditor
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2005-07-18
|
8
|
+
summary: A class for generating the HTML needed for the FCKEditor
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: tim@stokman.net
|
12
|
+
homepage: timstokman.net
|
13
|
+
rubyforge_project: fckeditor
|
14
|
+
description:
|
15
|
+
autorequire: fckeditor
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
authors:
|
28
|
+
- Tim Stokman
|
29
|
+
files:
|
30
|
+
- lib/fckeditor.rb
|
31
|
+
- lib/connector.rb
|
32
|
+
- README
|
33
|
+
test_files: []
|
34
|
+
rdoc_options: []
|
35
|
+
extra_rdoc_files:
|
36
|
+
- README
|
37
|
+
executables: []
|
38
|
+
extensions: []
|
39
|
+
requirements: []
|
40
|
+
dependencies: []
|