marky 0.0.1
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 +62 -0
- data/README.md +54 -0
- data/SUBMISSION_GUIDELINES +13 -0
- data/lib/adapters/bluecloth.rb +15 -0
- data/lib/adapters/maruku.rb +16 -0
- data/lib/adapters/rdiscount.rb +16 -0
- data/lib/marky.rb +31 -0
- data/marky.gemspec +14 -0
- data/test/marky_test.rb +37 -0
- metadata +78 -0
data/README
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
-- RMU SESSION 2 | PROBLEM 2
|
2
|
+
|
3
|
+
If in doubt about how to submit, see SUBMISSION_GUIDELINES file.
|
4
|
+
|
5
|
+
For this exercise, we'll be working with design patterns originally
|
6
|
+
described in the much-acclaimed "Gang of Four" book. While this book is over 15
|
7
|
+
years old, many of the ideas within it are still relevant to modern object
|
8
|
+
oriented design. The tricky thing is that sometimes they are mis-applied, and
|
9
|
+
often they are described with rather anemic examples that don't quite show their
|
10
|
+
true power.
|
11
|
+
|
12
|
+
Our goal will be to come up with some good Ruby examples that demonstrate how a
|
13
|
+
given pattern can be applied in real code, while sticking to Ruby idioms. Follow
|
14
|
+
the guidelines below to complete the exercise.
|
15
|
+
|
16
|
+
== GUIDELINES
|
17
|
+
|
18
|
+
1. Spend some time reviewing some of the classic patterns, reading at least a
|
19
|
+
few of them before deciding to focus on any one of them. There is a decent
|
20
|
+
resource at: http://sourcemaking.com/design_patterns and tons of information on
|
21
|
+
Wikipedia as well. You can use any of the patterns that are listed at that URL,
|
22
|
+
except for Command pattern, since we covered that in the entrance exam.
|
23
|
+
|
24
|
+
2. When you find a pattern that sounds interesting to you, try to think of a
|
25
|
+
scenario in which you could apply it in real code. If you can come up with one,
|
26
|
+
announce that you'll be working on this pattern on the mailing list, along with
|
27
|
+
the scenario you plan to explore.
|
28
|
+
|
29
|
+
3. Write up some example code that demonstrates the pattern in action. You do
|
30
|
+
not need to build a complete application, but the example you show should have
|
31
|
+
enough context to look and feel 'real', rather than being some contrived foo/bar
|
32
|
+
example. Download the PDF of my book (http://rubybestpractices.com) if you want
|
33
|
+
some examples of how to present ideas using real or realistic code.
|
34
|
+
|
35
|
+
4. Even if you're not building a complete application, stub out enough things to
|
36
|
+
create a runnable simulation that demonstrates how your code would be used.
|
37
|
+
Bonus points of course would be given to those who build a real app that uses
|
38
|
+
the pattern in action.
|
39
|
+
|
40
|
+
5. Feel free to help each other as much as needed to come up with the best
|
41
|
+
possible examples. You are encouraged to review each other's work and offer
|
42
|
+
suggestions.
|
43
|
+
|
44
|
+
== RESTRICTIONS:
|
45
|
+
|
46
|
+
* I don't want more than three students to cover the same problem, so be sure to keep
|
47
|
+
an eye on who's working on what
|
48
|
+
|
49
|
+
* Not every pattern that exists is relevant to Ruby. Try your best to
|
50
|
+
choose one that is, and if you're not reasonably sure, ask your fellow
|
51
|
+
students and/or me to comment on your choice.
|
52
|
+
|
53
|
+
* Do not submit a Command pattern demonstration.
|
54
|
+
|
55
|
+
* Do not intentionally copy a scenario you've found online. It's not a problem
|
56
|
+
if the example you pick happens to have been covered somewhere online before,
|
57
|
+
but you should not just port some example from another language into Ruby, try
|
58
|
+
to come up with your own use case.
|
59
|
+
|
60
|
+
== QUESTIONS?
|
61
|
+
|
62
|
+
Hit up the mailing list or IRC.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Marky
|
2
|
+
=====
|
3
|
+
|
4
|
+
Marky is simple wrapper for converting strings/text to html using different markdown processors. It's the solution to assingment #2 of October RMU. Based on intirdea's multi_json gem.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
============
|
8
|
+
[sudo] gem install marky
|
9
|
+
|
10
|
+
By default, installing Marky will install also RDiscount, Maruku and BlueCloth if necessary.
|
11
|
+
|
12
|
+
Usage
|
13
|
+
=====
|
14
|
+
|
15
|
+
require 'marky'
|
16
|
+
Marky.adapter = :maruku
|
17
|
+
Marky.to_html("Hello, Marky")
|
18
|
+
=> "<p>Hello, Marky</p>"
|
19
|
+
|
20
|
+
Adapters
|
21
|
+
========
|
22
|
+
|
23
|
+
Right now, the available adapters are RDiscout, BlueCloth and Maruku. If you want to add another, just create a module into adapters dirrectory who implements to_html method.
|
24
|
+
|
25
|
+
Meta
|
26
|
+
====
|
27
|
+
|
28
|
+
* Author : Mitko Kostov
|
29
|
+
* Email : mitko.kostov@gmail.com
|
30
|
+
* Website : [http://mitkokostov.info](http://mitkokostov.info)
|
31
|
+
* Twitter : [http://twitter.com/mytrile](http://twitter.com/mytrile)
|
32
|
+
|
33
|
+
License
|
34
|
+
=======
|
35
|
+
|
36
|
+
Copyright (c) 2010 Mitko Kostov
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
39
|
+
of this software and associated documentation files (the "Software"), to deal
|
40
|
+
in the Software without restriction, including without limitation the rights
|
41
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
42
|
+
copies of the Software, and to permit persons to whom the Software is
|
43
|
+
furnished to do so, subject to the following conditions:
|
44
|
+
|
45
|
+
The above copyright notice and this permission notice shall be included in
|
46
|
+
all copies or substantial portions of the Software.
|
47
|
+
|
48
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
49
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
50
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
51
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
52
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
53
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
54
|
+
THE SOFTWARE.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Fork this repository and hack away! When you are ready for a review, log into
|
2
|
+
the RMU web app and request a review for the appropriate exercise(*).
|
3
|
+
|
4
|
+
Do not share your solution or the problem description with anyone else without
|
5
|
+
talking to me about it first. Likewise, your submission won't be shared with
|
6
|
+
anyone else by me unless I talk to you first.
|
7
|
+
|
8
|
+
NOTE: No work done after 10/25 will be evaluated, be sure to request a review
|
9
|
+
before then!
|
10
|
+
|
11
|
+
(*) As of the time of writing this feature is not in place, but will be before
|
12
|
+
10/11. Should you wish to submit a problem for review before then, please just
|
13
|
+
email me.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'bluecloth' unless defined?(::BlueCloth)
|
3
|
+
rescue LoadError
|
4
|
+
puts "BlueCloth is not installed. Please, do $ [sudo] gem install bluecloth"
|
5
|
+
end
|
6
|
+
module Marky
|
7
|
+
module Adapters
|
8
|
+
module Bluecloth
|
9
|
+
extend self
|
10
|
+
def to_html(string)
|
11
|
+
::BlueCloth.new(string).to_html
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'maruku' unless defined?(::Maruku)
|
3
|
+
rescue LoadError
|
4
|
+
puts "Maruku is not installed. Please, do $ [sudo] gem install bluecloth"
|
5
|
+
end
|
6
|
+
|
7
|
+
module Marky
|
8
|
+
module Adapters
|
9
|
+
module Maruku
|
10
|
+
extend self
|
11
|
+
def to_html(string)
|
12
|
+
::Maruku.new(string).to_html
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'rdiscount' unless defined?(::RDiscount)
|
3
|
+
rescue LoadError
|
4
|
+
puts "RDiscount is not installed. Please, do $ [sudo] gem install rdiscount"
|
5
|
+
end
|
6
|
+
|
7
|
+
module Marky
|
8
|
+
module Adapters
|
9
|
+
module Rdiscount
|
10
|
+
extend self
|
11
|
+
def to_html(string)
|
12
|
+
::RDiscount.new(string).to_html
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/marky.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'adapters')
|
2
|
+
# Marky is simple wrapper for converting strings/text to html using different markdown processors.
|
3
|
+
module Marky
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# Gets the default adapter. Sets it to RDiscount if adapter is not specified
|
7
|
+
def adapter
|
8
|
+
return @adapter if @adapter
|
9
|
+
self.adapter = :rdiscount
|
10
|
+
@adapter
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sets the markdown processor and requires the adapter.
|
14
|
+
# @param [String, Symbol] name of the adapter
|
15
|
+
def adapter=(adapter_name)
|
16
|
+
case adapter_name
|
17
|
+
when Symbol, String
|
18
|
+
require "adapters/#{adapter_name}"
|
19
|
+
@adapter = Marky::Adapters.const_get("#{adapter_name.to_s.capitalize}")
|
20
|
+
else
|
21
|
+
raise "Missing adapter #{adapter_name}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Compiles the string into HTML.
|
26
|
+
# @param [String] the string which will be compiles
|
27
|
+
def to_html(string)
|
28
|
+
adapter.to_html(string)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/marky.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "marky"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
|
5
|
+
s.authors = ["Mitko Kostov"]
|
6
|
+
s.description = %q{Marky is a simple wrapper for converting strings/text to html using different markdown processors.}
|
7
|
+
s.summary = %q{A gem to provide swappable markdown processors.}
|
8
|
+
s.email = ["mitko.kostov@gmail.com"]
|
9
|
+
s.homepage = "http://github.com/mytrile/marky"
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
end
|
14
|
+
|
data/test/marky_test.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'minitest/spec'
|
4
|
+
require 'marky'
|
5
|
+
|
6
|
+
MiniTest::Unit.autorun
|
7
|
+
|
8
|
+
describe Marky do
|
9
|
+
before do
|
10
|
+
Marky.adapter
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "when I don't specify adapter" do
|
14
|
+
it "the default adapter should be rdiscount" do
|
15
|
+
Marky.adapter.must_equal Marky::Adapters::Rdiscount
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "when I use different when I don't specify adapter" do
|
20
|
+
|
21
|
+
it "returns proper html when using RDiscount" do
|
22
|
+
Marky.adapter = :rdiscount
|
23
|
+
Marky.to_html("Hello, Marky").must_equal "<p>Hello, Marky</p>\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns proper html when using Maruku" do
|
27
|
+
Marky.adapter = :maruku
|
28
|
+
Marky.to_html("Hello, Marky").must_equal "<p>Hello, Marky</p>"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns proper html when using BlueCloth" do
|
32
|
+
Marky.adapter = :bluecloth
|
33
|
+
Marky.to_html("Hello, Marky").must_equal "<p>Hello, Marky</p>"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marky
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mitko Kostov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-10 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Marky is a simple wrapper for converting strings/text to html using different markdown processors.
|
23
|
+
email:
|
24
|
+
- mitko.kostov@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- README.md
|
34
|
+
- SUBMISSION_GUIDELINES
|
35
|
+
- lib/adapters/bluecloth.rb
|
36
|
+
- lib/adapters/maruku.rb
|
37
|
+
- lib/adapters/rdiscount.rb
|
38
|
+
- lib/marky.rb
|
39
|
+
- marky.gemspec
|
40
|
+
- test/marky_test.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/mytrile/marky
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 23
|
65
|
+
segments:
|
66
|
+
- 1
|
67
|
+
- 3
|
68
|
+
- 6
|
69
|
+
version: 1.3.6
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: A gem to provide swappable markdown processors.
|
77
|
+
test_files: []
|
78
|
+
|