From 93a306d1f0c39eb883269e1bdacc4efe246df4ed Mon Sep 17 00:00:00 2001 From: K-S-A Date: Tue, 28 Mar 2017 17:37:49 +0300 Subject: [PATCH 1/7] Update CheckboxMarkdown to accept html_options --- Rakefile | 2 +- lib/markdown_checkboxes.rb | 44 ++++++++++---------------- lib/markdown_checkboxes/data_struct.rb | 27 ++++++++++------ test/test_data_struct.rb | 34 ++++++++++++-------- test/test_markdown_checkboxes.rb | 37 ++++++++++++++-------- 5 files changed, 78 insertions(+), 66 deletions(-) diff --git a/Rakefile b/Rakefile index debc11c..5814915 100644 --- a/Rakefile +++ b/Rakefile @@ -4,5 +4,5 @@ Rake::TestTask.new do |t| t.libs << 'test' end -desc "Run tests" +desc 'Run tests' task :default => :test diff --git a/lib/markdown_checkboxes.rb b/lib/markdown_checkboxes.rb index 2fe350f..0ed2842 100644 --- a/lib/markdown_checkboxes.rb +++ b/lib/markdown_checkboxes.rb @@ -1,45 +1,35 @@ require 'redcarpet' require 'action_view' -require File.dirname(__FILE__) + '/markdown_checkboxes/data_struct' +require 'markdown_checkboxes/data_struct' class CheckboxMarkdown < Redcarpet::Markdown include ActionView::Helpers::FormTagHelper - VERSION = '1.0.0' + CHECKBOX_REGEX = /-\s?\[(x|\s)\]/ - def render(text, &block) - text = parse_with_checkboxes(text, &block) - super(text) + def render(text, html_options = {}, &block) + super(parse_with_checkboxes(text, html_options, &block)) end private - def parse_with_checkboxes(text, &block) - checkbox_regex = /-\s?\[(x|\s)\]/ + def parse_with_checkboxes(text, html_options, &block) + text.gsub(CHECKBOX_REGEX).with_index do |current_match, current_index| + checked = current_match =~ /x/ + body = updated_body(text, current_index, checked) - text.gsub(checkbox_regex).with_index do |current_match, current_index| - checked = current_match =~ /x/ ? true : false - - body = - text.gsub(checkbox_regex).with_index do |match, index| - if index == current_index - checked ? "- [ ]" : "- [x]" - else - match - end - end - - check_box_tag "check_#{current_index}", "", checked, data: data_options(body, &block) + check_box_tag("check_#{current_index}", '', checked, **html_options, data: data_options(body, &block)) end end - def data_options(body) - if block_given? - data_struct = DataStruct.new - yield(data_struct, body) - data_struct.serializable_hash - else - {} + def data_options(body, &block) + DataStruct.new(body, &block).data + end + + def updated_body(text, current_index, current_checked) + text.gsub(CHECKBOX_REGEX).with_index do |match, index| + next match if index != current_index + current_checked ? '- [ ]' : '- [x]' end end diff --git a/lib/markdown_checkboxes/data_struct.rb b/lib/markdown_checkboxes/data_struct.rb index 76aee11..77bf3df 100644 --- a/lib/markdown_checkboxes/data_struct.rb +++ b/lib/markdown_checkboxes/data_struct.rb @@ -1,20 +1,27 @@ class DataStruct attr_accessor :data - def initialize + def initialize(body) @data = {} + yield(self, body) if block_given? end - def serializable_hash - Hash[@data.map { |k,v| [k.to_s, v.to_s] }] + def method_missing(name, *args, &block) + return super if !is_setter(name) + @data[dashed(name)] = args.first.to_s end - def method_missing(name, *args, &block) - if name.to_s =~ /=$/ - @data[name.to_s.gsub('_', '-').chop] = args.first - else - super(name, *args, &block) - end + def respond_to_missing?(method_name, include_private = false) + is_setter(method_name) || @data.has_key?(dashed(method_name)) || super end -end + private + + def is_setter(method_name) + !!(method_name.to_s =~ /=\z/) + end + + def dashed(value) + value.to_s.gsub('_', '-').sub(/=\z/, '') + end +end diff --git a/test/test_data_struct.rb b/test/test_data_struct.rb index fce82c2..27bb828 100644 --- a/test/test_data_struct.rb +++ b/test/test_data_struct.rb @@ -1,11 +1,11 @@ require 'test/unit' -require File.dirname(__FILE__) + '/../lib/markdown_checkboxes/data_struct' +require 'markdown_checkboxes/data_struct' class DataStructTest < Test::Unit::TestCase def setup - @struct = DataStruct.new - @struct.key = "value" + @struct = DataStruct.new('Lorem ipsum...') + @struct.key = 'value' @struct.test = true end @@ -13,19 +13,15 @@ def test_data_struct_exists assert @struct.is_a? DataStruct end - def test_methods_turn_into_key_value_pairs - assert_equal @struct.data["key"], "value" - assert_equal @struct.data["test"], true - end - - def test_serializable_hash - assert_equal @struct.serializable_hash, { "key" => "value", "test" => "true" } + def test_methods_turn_into_stringified_key_value_pairs + assert_equal @struct.data['key'], 'value' + assert_equal @struct.data['test'], 'true' end def test_underscores_turning_to_dashes - @struct.okc_thunder = "awesome" - assert @struct.data.has_key? "okc-thunder" - assert_equal @struct.data["okc-thunder"], 'awesome' + @struct.okc_thunder = 'awesome' + assert @struct.data.has_key?('okc-thunder') + assert_equal @struct.data['okc-thunder'], 'awesome' end def test_still_calls_real_method_missing @@ -34,5 +30,15 @@ def test_still_calls_real_method_missing end end -end + def test_responds_to_setters + assert_respond_to @struct, :setter= + assert_respond_to @struct, :alt_setter= + end + def test_responds_to_data_keys_getters + @struct.okc_thunder = 'awesome' + assert_respond_to @struct, :okc_thunder + refute_respond_to @struct, :getter + end + +end diff --git a/test/test_markdown_checkboxes.rb b/test/test_markdown_checkboxes.rb index 9d78c28..92711c7 100644 --- a/test/test_markdown_checkboxes.rb +++ b/test/test_markdown_checkboxes.rb @@ -1,10 +1,10 @@ require 'test/unit' -require File.dirname(__FILE__) + '/../lib/markdown_checkboxes' +require 'markdown_checkboxes' class MarkdownCheckboxesTest < Test::Unit::TestCase def setup - @m ||= CheckboxMarkdown.new(Redcarpet::Render::HTML.new()) + @m ||= CheckboxMarkdown.new(Redcarpet::Render::HTML.new) end def test_proper_markdown_inheritance @@ -13,32 +13,41 @@ def test_proper_markdown_inheritance end def test_standard_markdown - assert_equal @m.render("## Hello"), "

Hello

\n" - assert_equal @m.render("**Bold**"), "

Bold

\n" + assert_equal @m.render('## Hello'), "

Hello

\n" + assert_equal @m.render('**Bold**'), "

Bold

\n" end def test_checkbox_existence - assert_match //, @m.render("- [ ]") - assert_match /type="checkbox"/, @m.render("- [ ]") + assert_match(//, @m.render('- [ ]')) + assert_match(/type="checkbox"/, @m.render('- [ ]')) end def test_checkbox_check_attribute - assert_match /checked="checked"/, @m.render("- [x]") - assert_no_match /checked="checked"/, @m.render("- [ ]") + assert_match(/checked="checked"/, @m.render('- [x]')) + assert_no_match(/checked="checked"/, @m.render('- [ ]')) end def test_checkbox_data_setting - assert_match(/data-remote="true"/, - @m.render("- [ ]") do |data, updated_text| - data.remote = true - end + assert_match( + /data-remote="true"/, + @m.render('- [ ]') { |data, _| data.remote = true } ) - assert_match(/data-method="put"/, - @m.render("- [x]") do |data, updated_text| + assert_match( + /data-method="put"/, + @m.render('- [x]') do |data, _| data.remote = true data.method = :put end ) end + + def test_checkbox_disabled_html_option + assert_match(/disabled="disabled"/, @m.render('- [ ]', disabled: true)) + assert_match(/disabled="disabled"/, @m.render('- [x]', disabled: true)) + refute_match(/disabled/, @m.render('- [ ]', disabled: false)) + refute_match(/disabled/, @m.render('- [x]', disabled: false)) + refute_match(/disabled/, @m.render('- [ ]')) + refute_match(/disabled/, @m.render('- [x]')) + end end From 8a6fd1309886f160fa976beb92f5a46407841aa7 Mon Sep 17 00:00:00 2001 From: K-S-A Date: Tue, 28 Mar 2017 17:45:22 +0300 Subject: [PATCH 2/7] Update gemspec --- markdown_checkboxes.gemspec | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/markdown_checkboxes.gemspec b/markdown_checkboxes.gemspec index ac704ff..8931596 100644 --- a/markdown_checkboxes.gemspec +++ b/markdown_checkboxes.gemspec @@ -1,20 +1,37 @@ -require File.dirname(__FILE__) + '/lib/markdown_checkboxes' +# coding: utf-8 + +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |s| s.name = 'markdown_checkboxes' - s.version = CheckboxMarkdown::VERSION - s.date = '2013-11-20' + s.version = '1.1.0' + s.date = '2017-03-28' s.summary = 'Markdown with checkbox support' s.description = 'Adding checkbox rendering functionality on top of the redcarpet markdown parser' s.authors = ['Brightbit Apps'] s.email = 'hello@brightbit.com' - s.files = ['lib/markdown_checkboxes.rb', 'lib/markdown_checkboxes/data_struct.rb'] s.homepage = 'http://rubygems.org/gems/markdown_checkboxes' s.license = 'MIT' - s.add_runtime_dependency "redcarpet", '>= 3.0.0' - s.add_runtime_dependency "actionpack", '>= 2.0.0' + if s.respond_to?(:metadata) + s.metadata['allowed_push_host'] = 'https://rubygems.org' + else + raise 'RubyGems 2.0 or newer is required to protect against ' \ + 'public gem pushes.' + end + + s.files = `git ls-files -z`.split("\x0").reject do |f| + f.match(%r{^(test|spec|features)/}) + end + + s.bindir = 'exe' + s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) } + s.require_paths = %w(lib) + + s.add_runtime_dependency 'redcarpet', '~> 3.4' + s.add_runtime_dependency 'actionpack', '~> 5.0' - s.add_development_dependency "rake-compiler", "~> 0.8.3" - s.add_development_dependency "test-unit", "~> 2.5.4" + s.add_development_dependency 'rake-compiler', '~> 1.0' + s.add_development_dependency 'test-unit', '~> 3.2' end From 06579ff153c4b35ff58e2d49455e06f18bb2a6e2 Mon Sep 17 00:00:00 2001 From: K-S-A Date: Tue, 28 Mar 2017 18:08:08 +0300 Subject: [PATCH 3/7] Remove 1.0.0 .gem file --- markdown_checkboxes-1.0.0.gem | Bin 5120 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 markdown_checkboxes-1.0.0.gem diff --git a/markdown_checkboxes-1.0.0.gem b/markdown_checkboxes-1.0.0.gem deleted file mode 100644 index 8f2e5d1b71136340be00183f3ee0cb75804e83d6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5120 zcmeH~XIK+R8plHwLMKS1h9ayWNC_pu&;lrZDT06^CV=z~D;*RNkd9QTh7}g1EGR{! zssW|MNGDPRlonXZ0a*fsWB2Y{A3xlE((~@&{W9f!X5N|qGxM8wJRJQ|4k&-rIj3O2 z*D~27Q&3O<{81j+m!+J%y!^lV{^6H{LX{N&Lb6|LL7&eX;OCF>Jqmx*+0oJcbH^9; z|K$I3YoBfIi{amE6OzCHsLD(-qox_Qoc0=&We+FWp$f?v3Ldc*scX7RpwVADnP8FniU|-!jS;D=(FrsV(?BaUwWb9=uxWX0l{F{SuKUojxv= z>xAgtr0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2Z35jcPYsPW~KmZR$#a{HdP!33t}bA+11n zp8Kl9F^TJl&IZW^@0C^4CXFa@=@&~9-B(S|{out#SZ1_7W36HUNDF$!eH(7vv-#14 zZ_x{a37n$o&6Lw?y+Y>(ZgQ+Cm5cgOx}vXu>iXLxfoIBk>L*qjl9=%bA0Z|_Y49{m uBZ*0h<8%gT5qACxpYEnh!{m94qi0De!lN40*2r From 00701d0ee6cc84bac0a339c9747c3e8be8def643 Mon Sep 17 00:00:00 2001 From: K-S-A Date: Tue, 28 Mar 2017 18:08:45 +0300 Subject: [PATCH 4/7] Add 1.1.0 .gem file --- markdown_checkboxes-1.1.0.gem | Bin 0 -> 7680 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 markdown_checkboxes-1.1.0.gem diff --git a/markdown_checkboxes-1.1.0.gem b/markdown_checkboxes-1.1.0.gem new file mode 100644 index 0000000000000000000000000000000000000000..5f7583cbd3bf7f375074a82ed2f0b9ada0d0fcf9 GIT binary patch literal 7680 zcmeHLXHXQ%mL?67lp*IlAXz4WL{V~(q~s`JfRP*}4jF_2Mvx>?0Tt093_&si5=2Qu zPNGD~86?j0?f$s0?pE#ox_94hdH$U4KGof)zdHR@ozD&KYwKX^Yb)*)MDSOc#4m%v zU)k zr}6(3|IfGm@wh*2|972op~wgjAycMA#G}UA9@7$3E$b%E^#=~!x{X(;-kHWRc3f-r z?YPE9s+_@Wff7T|&Pruo92xj?>f|uY3Spi`-MzQityla5r1?{1&gAnO3^L;5Je{xV zZfC@Zj~L*gOBM|WeG?t>#YU14oY>o7(t>P*HG~^wheml6C3v-fdxz!wvRnZDm~9Hq zV~HVq`%ppCcEup8o2H0Gr~a6dN>1eQ)O}xLL{aq(=^3J@-%=is>F9=?J7{s6eZii) zrE*-adL;ij;d_DOdR&+j1v@i9?IClaLUc$=ttssq7(uN?u}z?fZO28lg_7I2jXE^h z>+TkUUd$~HtU3h5m!m7CZn148Cl5d6qg}w!ylX!u^}7P{DvyjlTonu+k_ z?$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: Tue, 28 Mar 2017 18:17:26 +0300 Subject: [PATCH 5/7] Update README.md --- .gitignore | 9 +++++++++ Gemfile | 4 ++++ README.md | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f10e18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/.bundle/ +/.yardoc +/Gemfile.lock +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/tmp/ +.rbenv-gemsets diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..99ebcaa --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in markdown_checkboxes.gemspec +gemspec diff --git a/README.md b/README.md index 8f42dcb..1e790eb 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,28 @@ Assuming you have your infrastructure set up accordingly, this should send an HT your post's body, as well as fire unobtrusive javascript after the action is completed (allowing you to do things like prevent a page refresh, and other cool js things) +### Passing html options + +Also, it is possible to pass html options to rendered checkboxes. + +You can pass second argument to `#render` method with hash of options: + +```ruby +markdown = '- [ ] - [x]' +html_options = { disabled: true } + +parser.render(markdown, html_options) do |data, updated_text| + # ... +end +``` + +Result will look like follows: + +```html + + +``` + ### Installation ``` From a73e0380b95cc949009f6b9574b77038b4e59982 Mon Sep 17 00:00:00 2001 From: K-S-A Date: Tue, 28 Mar 2017 18:21:19 +0300 Subject: [PATCH 6/7] Fix gemspec files --- markdown_checkboxes.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/markdown_checkboxes.gemspec b/markdown_checkboxes.gemspec index 8931596..c92a7ca 100644 --- a/markdown_checkboxes.gemspec +++ b/markdown_checkboxes.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |s| s.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) + f.match(/\.gem\z/) end s.bindir = 'exe' From b2ec9442fda2f561370ef5e33372839b40d9be21 Mon Sep 17 00:00:00 2001 From: K-S-A Date: Sat, 8 Apr 2017 07:08:49 +0300 Subject: [PATCH 7/7] Add raw-text option --- lib/markdown_checkboxes.rb | 4 +++- test/test_markdown_checkboxes.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/markdown_checkboxes.rb b/lib/markdown_checkboxes.rb index 0ed2842..fd15e82 100644 --- a/lib/markdown_checkboxes.rb +++ b/lib/markdown_checkboxes.rb @@ -14,9 +14,11 @@ def render(text, html_options = {}, &block) private def parse_with_checkboxes(text, html_options, &block) + raw_text = html_options.delete(:raw_text) { text } + text.gsub(CHECKBOX_REGEX).with_index do |current_match, current_index| checked = current_match =~ /x/ - body = updated_body(text, current_index, checked) + body = updated_body(raw_text, current_index, checked) check_box_tag("check_#{current_index}", '', checked, **html_options, data: data_options(body, &block)) end diff --git a/test/test_markdown_checkboxes.rb b/test/test_markdown_checkboxes.rb index 92711c7..12b2d1b 100644 --- a/test/test_markdown_checkboxes.rb +++ b/test/test_markdown_checkboxes.rb @@ -50,4 +50,9 @@ def test_checkbox_disabled_html_option refute_match(/disabled/, @m.render('- [ ]')) refute_match(/disabled/, @m.render('- [x]')) end + + def test_raw_text_in_html_options + assert_match(/lorem\sipsum/, @m.render('- [ ]', disabled: true, raw_text: 'lorem ipsum') { |data, text| data.url = 'path?key=' + text }) + assert_match(/hello\sworld/, @m.render('- [ ]', disabled: false, raw_text: 'hello world') { |data, text| data.url = 'path?key=' + text }) + end end