wysia 0.0.2

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/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .idea
20
+
21
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wysia.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Johnny Eradus
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Wysia
2
+
3
+ A WYSIWYG for textarea to work with **Rails 3** FormBuilders
4
+
5
+ This Gem uses
6
+ - [WYSIHTML5][1] <- this actually does all the hard work
7
+ - [Font Awesome][2] <- used for scaling icons wich are AWESOME
8
+
9
+ [1]:http://xing.github.com/wysihtml5/
10
+ [2]:http://fortawesome.github.com/Font-Awesome/
11
+
12
+ ## Installation
13
+
14
+ In your `Gemfile`, add the following dependencies:
15
+ ```ruby
16
+ gem 'wysia', :git => 'https://github.com/jhny/wysia.git'
17
+ ```
18
+ Run:
19
+ ```unix
20
+ $ bundle install
21
+ ```
22
+ ## Usage
23
+ Include the Javascript (wysihtm5) into your `application.js`:
24
+ ```ruby
25
+ //= require wysia.js
26
+ ```
27
+ Include de css into your `applications.css`
28
+ ```sass
29
+ @import "wysia.scss";
30
+ ```
31
+ In your forms use the `wysia_text_area` helper
32
+
33
+ ### default usage
34
+ ```ruby
35
+ = form_for @user do |f|
36
+ = f.wysia_text_area :about
37
+ ```
38
+ ### Configuration
39
+ #### Available options:
40
+ - All the usual options for a `text_area` can be used.
41
+ - `size`: `normal`, `small` or `mini`. Affects the button size of the toolbar. `normal` is default.
42
+ - `js`: `inline` or `yield`. Yields the javascript to a block called `:javascript` or its placed inline. `inline` is default.
43
+
44
+ using the options:
45
+ ```ruby
46
+ = f.wysia_text_area :about, {:class => "shaded comment grey remark", :rows => 3, :id => "about_#{@user.id}_remark", :size => "small"}
47
+ ```
48
+
49
+ 1. If you use `js: "yield"` as option, the javascript is yielded to a block called `:javascript`. In your layout or view use:
50
+ ```ruby
51
+ yield :javascript
52
+ ```
53
+
54
+ 2. If you have multiple `wysia_text_area` elements in a single page, you need to provide a ID to the options to make sure they are distinguisable for the javascript.
55
+
56
+ ## Contribute
57
+
58
+ ### Edit gem
59
+ Instead of pointing to the git repo, point to the local source `#gem 'wysia', :path => "/home/user/src/wysia"`
60
+
61
+ [issues]: https://github.com/jhny/wysia/issues
62
+ ### Submitting an Issue
63
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
64
+ submitting a bug report or feature request, check to make sure it hasn't
65
+ already been submitted. When submitting a bug report, please include a [Gist][]
66
+ that includes a stack trace and any details that may be necessary to reproduce
67
+ the bug, including your gem version, Ruby version, and operating system.
68
+ Ideally, a bug report should include a pull request with failing specs.
69
+
70
+ ## Additional information
71
+
72
+ ### Authors
73
+
74
+ * Johnny Eradus (https://github.com/jhny)
75
+ * Benjamin Udink ten Cate (https://github.com/hezus)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Wysia
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,80 @@
1
+ module Wysia
2
+ module FormHelper
3
+ def wysia_text_area(object_name, method, options = {})
4
+
5
+ #size = " btn-mini" if options[:size] == "mini"
6
+ size = " btn-small" if options[:size] == "small"
7
+ size = " btn-normal" if options[:size] == "normal"
8
+ size = "" if options[:size].nil?
9
+ options.delete(:size) if options[:size].present?
10
+ text_area_id = options[:id] || "#{object_name}_#{method}"
11
+ p options.inspect
12
+ content = <<HTML
13
+ <div id="#{text_area_id}_wysihtml5-toolbar" class="btn-toolbar">
14
+ <div class="btn-group">
15
+ <a class="btn#{size}" data-wysihtml5-command="bold"><i class="icon-bold"></i></a>
16
+ <a class="btn#{size}" data-wysihtml5-command="italic"><i class="icon-italic"></i></a>
17
+ </div>
18
+
19
+ <div class="btn-group">
20
+ <a class="btn#{size}" data-wysihtml5-command-value="h1" data-wysihtml5-command="formatBlock"><b>h1</b></a>
21
+ <a class="btn#{size}" data-wysihtml5-command-value="h2" data-wysihtml5-command="formatBlock"><b>h2</b></a>
22
+ </div>
23
+
24
+ <div class="btn-group">
25
+ <a class="btn#{size}" data-wysihtml5-command="insertOrderedList"><i class="icon-list-ol"></i></a>
26
+ <a class="btn#{size}" data-wysihtml5-command="insertUnorderedList"><i class="icon-list-ul"></i></a>
27
+ </div>
28
+
29
+ <div class="btn-group">
30
+ <a class="btn#{size}" data-wysihtml5-command="createLink"><i class="icon-link"></i></a>
31
+ </div>
32
+
33
+ <div class="btn-group">
34
+ <a class="btn#{size}" data-wysihtml5-action="change_view"><i class="icon-edit"></i></a>
35
+ </div>
36
+ <div data-wysihtml5-dialog="createLink" class="wysihtml5-dialog" style='display: none;'>
37
+ <label>
38
+ Link:
39
+ <input data-wysihtml5-dialog-field="href" value="http://" class="text">
40
+ </label>
41
+ <a data-wysihtml5-dialog-action="save" class="ok">OK</a>
42
+ <a data-wysihtml5-dialog-action="cancel" class="cancel">Cancel</a>
43
+ </div>
44
+ <div class="clearfix"></div>
45
+ </div>
46
+ #{text_area object_name, method, options}
47
+ HTML
48
+
49
+ js =<<javascript
50
+ var editor = new wysihtml5.Editor("#{text_area_id}", { // id of textarea element
51
+ toolbar:"#{text_area_id}_wysihtml5-toolbar", // id of toolbar element
52
+ stylesheets:"/assets/wysiwyg/stylesheet.css", // stylesheet to be used
53
+ parserRules:wysihtml5ParserRules // defined in parser rules set
54
+ });
55
+ javascript
56
+
57
+
58
+ if options[:js].present? && options[:js] == "yield"
59
+ content_for(:javascript) do
60
+ javascript_tag(js).html_safe
61
+ end
62
+ else
63
+ content = content + javascript_tag(js)
64
+ end
65
+
66
+ content.html_safe
67
+ end
68
+ def self.included(arg)
69
+ ActionView::Helpers::FormBuilder.send(:include, Wysia::FormBuilder)
70
+ end
71
+
72
+ end
73
+ end
74
+ module Wysia::FormBuilder
75
+ # ActionPack's metaprogramming would have done this for us, if FormHelper#labeled_input
76
+ # had been defined at load. Instead we define it ourselves here.
77
+ def wysia_text_area(method, options = {})
78
+ @template.wysia_text_area(@object_name, method, objectify_options(options))
79
+ end
80
+ end
data/lib/wysia.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "wysia/version"
2
+ require "wysia/wysia_form_helper"
3
+
4
+ module Wysia
5
+
6
+ module Rails
7
+ class Engine < ::Rails::Engine
8
+ end
9
+ end
10
+ end
11
+
12
+
13
+ class ActionView::Base
14
+ include Wysia::FormHelper
15
+ end
@@ -0,0 +1,2 @@
1
+ //= require wysiwyg/wysihtml5-0.3.0.js
2
+ //= require wysiwyg/advanced.js