markdown_checkboxes 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd7589c90a43830985a675bf69fda41511348195
4
+ data.tar.gz: 58f0d22bc7118899a68cc5b4bda7906509edb575
5
+ SHA512:
6
+ metadata.gz: d94edcc96124b714d00a5a9ea545766d045cbbc097e7fbfdb220d79612298f820b0cc5220bde7968e646c7546e6c927b9611d819b6bb547d0b810b72bdfd8581
7
+ data.tar.gz: 52cdbe0c1c9b727800c02a9ea2e7f8126ae8612f9717437209fa809b107ebfd5e1d7312feb6d164f78202385fed05bf236ae5ca877466cb27e34a0411e5f3fb0
@@ -0,0 +1,20 @@
1
+ class DataStruct
2
+ attr_accessor :data
3
+
4
+ def initialize
5
+ @data = {}
6
+ end
7
+
8
+ def serializable_hash
9
+ Hash[@data.map { |k,v| [k.to_s, v.to_s] }]
10
+ end
11
+
12
+ def method_missing(name, *args, &block)
13
+ if name.to_s =~ /=$/
14
+ @data[name.to_s.gsub('_', '-').chop] = args.first
15
+ else
16
+ super(name, *args, &block)
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,46 @@
1
+ require 'redcarpet'
2
+ require 'action_view'
3
+ require File.dirname(__FILE__) + '/markdown_checkboxes/data_struct'
4
+
5
+ class CheckboxMarkdown < Redcarpet::Markdown
6
+ include ActionView::Helpers::FormTagHelper
7
+
8
+ VERSION = '0.3.0'
9
+
10
+ def render(text, &block)
11
+ text = parse_with_checkboxes(text, &block)
12
+ super(text)
13
+ end
14
+
15
+ private
16
+
17
+ def parse_with_checkboxes(text, &block)
18
+ checkbox_regex = /-\s?\[(x|\s)\]/
19
+
20
+ text.gsub(checkbox_regex).with_index do |current_match, current_index|
21
+ checked = current_match =~ /x/ ? true : false
22
+
23
+ body =
24
+ text.gsub(checkbox_regex).with_index do |match, index|
25
+ if index == current_index
26
+ checked ? "- [ ]" : "- [x]"
27
+ else
28
+ match
29
+ end
30
+ end
31
+
32
+ check_box_tag "check_#{current_index}", "", checked, data: data_options(body, &block)
33
+ end
34
+ end
35
+
36
+ def data_options(body)
37
+ if block_given?
38
+ data_struct = DataStruct.new
39
+ yield(data_struct, body)
40
+ data_struct.serializable_hash
41
+ else
42
+ {}
43
+ end
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown_checkboxes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Brightbit Apps
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.5.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.5.4
69
+ description: Adding checkbox rendering functionality on top of the redcarpet markdown
70
+ parser
71
+ email: hello@brightbit.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/markdown_checkboxes.rb
77
+ - lib/markdown_checkboxes/data_struct.rb
78
+ homepage: http://rubygems.org/gems/markdown_checkboxes
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Markdown with checkbox support
102
+ test_files: []