markdown-ui 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +19 -0
  8. data/Rakefile +10 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/exe/markdown-ui +37 -0
  12. data/lib/markdown-ui.rb +130 -0
  13. data/lib/markdown-ui/button/animated.rb +22 -0
  14. data/lib/markdown-ui/button/basic.rb +17 -0
  15. data/lib/markdown-ui/button/custom.rb +20 -0
  16. data/lib/markdown-ui/button/element.rb +59 -0
  17. data/lib/markdown-ui/button/focusable.rb +23 -0
  18. data/lib/markdown-ui/button/group/buttons/custom.rb +21 -0
  19. data/lib/markdown-ui/button/group/buttons/element.rb +28 -0
  20. data/lib/markdown-ui/button/group/buttons/icon.rb +19 -0
  21. data/lib/markdown-ui/button/group/buttons/standard.rb +19 -0
  22. data/lib/markdown-ui/button/icon.rb +17 -0
  23. data/lib/markdown-ui/button/labeled_icon.rb +23 -0
  24. data/lib/markdown-ui/button/standard.rb +17 -0
  25. data/lib/markdown-ui/container/alignment/center.rb +19 -0
  26. data/lib/markdown-ui/container/alignment/left.rb +19 -0
  27. data/lib/markdown-ui/container/alignment/right.rb +19 -0
  28. data/lib/markdown-ui/container/custom.rb +17 -0
  29. data/lib/markdown-ui/container/element.rb +38 -0
  30. data/lib/markdown-ui/container/standard.rb +17 -0
  31. data/lib/markdown-ui/container/text.rb +17 -0
  32. data/lib/markdown-ui/content/custom.rb +16 -0
  33. data/lib/markdown-ui/content/header.rb +19 -0
  34. data/lib/markdown-ui/content/icon.rb +24 -0
  35. data/lib/markdown-ui/content/item.rb +21 -0
  36. data/lib/markdown-ui/content/list.rb +23 -0
  37. data/lib/markdown-ui/content/parser.rb +66 -0
  38. data/lib/markdown-ui/content/text.rb +24 -0
  39. data/lib/markdown-ui/divider/element.rb +0 -0
  40. data/lib/markdown-ui/divider/hidden.rb +0 -0
  41. data/lib/markdown-ui/divider/standard.rb +0 -0
  42. data/lib/markdown-ui/grid/column/column.rb +18 -0
  43. data/lib/markdown-ui/grid/grid.rb +18 -0
  44. data/lib/markdown-ui/grid/row/row.rb +18 -0
  45. data/lib/markdown-ui/header/header.rb +30 -0
  46. data/lib/markdown-ui/label/custom.rb +20 -0
  47. data/lib/markdown-ui/label/element.rb +34 -0
  48. data/lib/markdown-ui/menu/custom.rb +20 -0
  49. data/lib/markdown-ui/menu/element.rb +62 -0
  50. data/lib/markdown-ui/menu/pagination.rb +17 -0
  51. data/lib/markdown-ui/menu/pointing.rb +17 -0
  52. data/lib/markdown-ui/menu/secondary.rb +17 -0
  53. data/lib/markdown-ui/menu/standard.rb +17 -0
  54. data/lib/markdown-ui/menu/tabular.rb +17 -0
  55. data/lib/markdown-ui/menu/text.rb +17 -0
  56. data/lib/markdown-ui/menu/vertical.rb +17 -0
  57. data/lib/markdown-ui/message/custom_message.rb +20 -0
  58. data/lib/markdown-ui/message/list_message.rb +17 -0
  59. data/lib/markdown-ui/message/message.rb +40 -0
  60. data/lib/markdown-ui/message/standard_message.rb +17 -0
  61. data/lib/markdown-ui/segment/custom_segment.rb +18 -0
  62. data/lib/markdown-ui/segment/horizontal_segment.rb +16 -0
  63. data/lib/markdown-ui/segment/padded_segment.rb +16 -0
  64. data/lib/markdown-ui/segment/piled_segment.rb +16 -0
  65. data/lib/markdown-ui/segment/segment.rb +34 -0
  66. data/lib/markdown-ui/segment/stacked_segment.rb +16 -0
  67. data/lib/markdown-ui/segment/standard_segment.rb +16 -0
  68. data/lib/markdown-ui/segment/vertical_segment.rb +16 -0
  69. data/lib/markdown-ui/tag/custom_tag.rb +25 -0
  70. data/lib/markdown-ui/tag/item_tag.rb +24 -0
  71. data/lib/markdown-ui/tag/list_tag.rb +40 -0
  72. data/lib/markdown-ui/tag/span_tag.rb +14 -0
  73. data/lib/markdown-ui/tag/standard_tag.rb +23 -0
  74. data/lib/markdown-ui/tag/tag.rb +37 -0
  75. data/lib/markdown-ui/utils/klass_util.rb +11 -0
  76. data/lib/markdown-ui/version.rb +3 -0
  77. data/markdown-ui.gemspec +36 -0
  78. data/website/index.html +369 -0
  79. data/website/index.md +389 -0
  80. metadata +208 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 591d33b4d03097bf5b99242462f542997ecc1bfd
4
+ data.tar.gz: d2b95bc4f0c1c9f551753efa078e705474d98eac
5
+ SHA512:
6
+ metadata.gz: 11f01d6fd6b71526f30cdf01b2135210d28ca30e15acae138bb19239d0157368e04da124ec470166f5ea3efff8b84e80db00bcb56a913fd63cacfeb705fbdab1
7
+ data.tar.gz: d8dedef2931d40f51a996e0b142f9c151b65dcdb08d1c17fc59e07d92fc1e83dea2be551668a06d6e01f44c3065cde098ed083f80831279bb5868d486ec37929
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markdown-ui.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Joel Bryan Juliano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # MarkdownUI
2
+
3
+ Write UI/UX in Markdown Syntax. See http://jjuliano.github.io/markdown-ui/
4
+
5
+ ## Installation
6
+
7
+ $ gem install markdown-ui
8
+
9
+ ## Usage
10
+
11
+ $ markdown-ui file.md
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it ( https://github.com/[my-github-username]/markdown-ui/fork )
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "."
6
+ t.test_files = FileList["test/*test.rb"]
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "markdown-ui"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "markdown-ui"
5
+
6
+ parser = Redcarpet::Markdown.new(MarkdownUI::Renderer, quote: true, tables: true)
7
+
8
+ f = File.open(ARGV.first, 'r')
9
+ puts <<-EOS
10
+ <!doctype html>
11
+
12
+ <html lang="en">
13
+ <head>
14
+ <meta charset="utf-8">
15
+
16
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.0.1/semantic.min.css">
17
+ <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.0.1/semantic.min.js"></script>
19
+
20
+ <!--[if lt IE 9]>
21
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
22
+ <![endif]-->
23
+ <style>
24
+ code { white-space:pre }
25
+ </style>
26
+ </head>
27
+
28
+ <body>
29
+ EOS
30
+
31
+ puts parser.render f.read
32
+
33
+ puts <<-EOS
34
+ </body>
35
+ </html>
36
+ EOS
37
+ f.close
@@ -0,0 +1,130 @@
1
+ # coding: UTF-8
2
+ require "markdown-ui/version"
3
+
4
+ require 'redcarpet'
5
+ require 'nokogiri'
6
+ require 'ostruct'
7
+
8
+ ['markdown-ui/**/*.rb'].each do |dir|
9
+ Dir[File.join(File.dirname(__FILE__), dir)].sort.each { |f| require_relative f }
10
+ end
11
+
12
+ module MarkdownUI
13
+ class Renderer < Redcarpet::Render::HTML
14
+ include Redcarpet::Render::SmartyPants
15
+
16
+ def paragraph(text)
17
+ text
18
+ end
19
+
20
+ def emphasis(text)
21
+ MarkdownUI::Content::Icon.new(text).render
22
+ end
23
+
24
+ def double_emphasis(text)
25
+ args = text.split("|")
26
+ element = args[0].split(" ")
27
+
28
+ content = if args[1].strip =~ /\,/
29
+ args[1].split(",")
30
+ else
31
+ args[1].strip
32
+ end
33
+
34
+ klass = if args[0].strip =~ /\./
35
+ k = args[0].split(".")
36
+ k.reverse!
37
+ k.shift
38
+ else
39
+ !args[2].nil? ? args[2].downcase : nil
40
+ end
41
+
42
+ data_attributes = !args[3].nil? ? args[3].downcase : nil
43
+
44
+ html do
45
+ case element.join(" ")
46
+ when /button/i
47
+ MarkdownUI::Button::Element.new(element, content, klass).render
48
+ when /menu/i
49
+ MarkdownUI::Menu::Element.new(element, content, klass).render
50
+ when /message/i
51
+ MarkdownUI::Message.new(element, content, klass).render
52
+ when /tag/i
53
+ MarkdownUI::Tag.new(element[0].downcase, content, klass, data_attributes).render
54
+ when /header/i
55
+ MarkdownUI::Header.new(content, 0).render
56
+ end
57
+ end
58
+ end
59
+
60
+ def block_quote(text)
61
+ element, content = text.split(':')
62
+
63
+ html do
64
+ case element
65
+ when /segment/i
66
+ MarkdownUI::Segment.new(element, content).render
67
+ when /grid/i
68
+ MarkdownUI::Grid.new(element, content).render
69
+ when /column/i
70
+ MarkdownUI::Column.new(element, content).render
71
+ when /container/i
72
+ MarkdownUI::Container::Element.new(element, content).render
73
+ when /buttons/i
74
+ MarkdownUI::Button::Group::Buttons::Element.new(element, content).render
75
+ when /button/i
76
+ MarkdownUI::Button::Element.new(element, content).render
77
+ when /menu/i
78
+ MarkdownUI::Menu::Element.new(element, content).render
79
+ when /message/i
80
+ MarkdownUI::Message.new(element, content).render
81
+ when /label/i
82
+ MarkdownUI::Label::Element.new(element, content).render
83
+ end
84
+ end
85
+ end
86
+
87
+ def list(content, list_type)
88
+ klass = "ui"
89
+ html { MarkdownUI::Content::List.new(content, klass, list_type).render }
90
+ end
91
+
92
+ def link(link, klass, content)
93
+ _klass = "ui #{klass}"
94
+ html { MarkdownUI::Content::Item.new(content, _klass, link).render }
95
+ end
96
+
97
+ def quote(text)
98
+ html { "<p>#{text}</p>" }
99
+ end
100
+
101
+ def header(text, level)
102
+ html { MarkdownUI::Header.new(text, level).render }
103
+ end
104
+
105
+ def table_cell(content, alignment)
106
+ body, klass = content.split(":")
107
+
108
+ "<div class=\"ui #{klass}column\">#{body}</div>"
109
+ end
110
+
111
+ protected
112
+
113
+ def html
114
+ if block_given?
115
+ HTMLFormatter.new(yield).to_html
116
+ end
117
+ end
118
+
119
+ end
120
+
121
+ class HTMLFormatter
122
+ def initialize(text)
123
+ @doc = Nokogiri::XML(text, &:noblanks).to_xhtml(indent: 2)
124
+ end
125
+
126
+ def to_html
127
+ @doc
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,22 @@
1
+ # coding: UTF-8
2
+
3
+ module MarkdownUI::Button
4
+ class Animated
5
+ def initialize(content, klass = nil)
6
+ @klass = klass
7
+ @visible_content, @hidden_content = content.split(";")
8
+ end
9
+
10
+ def render
11
+ klass = "ui #{@klass} animated button"
12
+ visible_content = MarkdownUI::Content::Parser.new(@visible_content).parse
13
+ hidden_content = MarkdownUI::Content::Parser.new(@hidden_content).parse
14
+
15
+ content = []
16
+ content << MarkdownUI::StandardTag.new(visible_content, "visible content").render
17
+ content << MarkdownUI::StandardTag.new(hidden_content, "hidden content").render
18
+
19
+ MarkdownUI::StandardTag.new(content.join, klass).render
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ # coding: UTF-8
2
+
3
+ module MarkdownUI::Button
4
+ class Basic
5
+ def initialize(content, klass = nil)
6
+ @klass = klass
7
+ @content = content
8
+ end
9
+
10
+ def render
11
+ content = MarkdownUI::Content::Parser.new(@content).parse
12
+ klass = "ui #{@klass} basic button"
13
+
14
+ MarkdownUI::StandardTag.new(content, klass).render
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ # coding: UTF-8
2
+
3
+ module MarkdownUI::Button
4
+ class Custom
5
+ def initialize(element, content, klass = nil)
6
+ @element = element
7
+ @klass = klass
8
+ @content = content
9
+ end
10
+
11
+ def render
12
+ element = @element.join(" ").strip
13
+ content = MarkdownUI::Content::Parser.new(@content).parse
14
+ klass = "ui #{element} #{@klass} button"
15
+
16
+ MarkdownUI::StandardTag.new(content, klass).render
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,59 @@
1
+ module MarkdownUI::Button
2
+ class Element
3
+ def initialize(element, content, klass = nil)
4
+ @element = element
5
+ @content = content
6
+ @klass = klass
7
+ end
8
+
9
+ def render
10
+ element = if @element.is_a? Array
11
+ @element
12
+ else
13
+ @element.split(" ")
14
+ end
15
+
16
+ content = @content
17
+
18
+ klass = if @klass.nil?
19
+ element.join(" ").strip
20
+ else
21
+ @klass
22
+ end
23
+
24
+ mode = OpenStruct.new(
25
+ :icon? => element.grep(/icon/i).any?,
26
+ :flag? => element.grep(/flag/i).any?,
27
+ :image? => element.grep(/image/i).any?,
28
+ :focusable? => element.grep(/focusable/i).any?,
29
+ :animated? => element.grep(/animated/i).any?,
30
+ :labeled? => element.grep(/labeled/i).any?,
31
+ :basic? => element.grep(/basic/i).any?
32
+ )
33
+
34
+ if standard_button?(mode) && element.size > 1
35
+ MarkdownUI::Button::Custom.new(element, content, klass).render
36
+ elsif mode.icon? && mode.labeled?
37
+ icon, label = content
38
+ MarkdownUI::Button::LabeledIcon.new(icon, label, klass).render
39
+ elsif mode.icon? && !mode.labeled?
40
+ MarkdownUI::Button::Icon.new(content, klass).render
41
+ elsif mode.focusable?
42
+ MarkdownUI::Button::Focusable.new(content, klass).render
43
+ elsif mode.basic?
44
+ MarkdownUI::Button::Basic.new(content, klass).render
45
+ elsif mode.animated?
46
+ MarkdownUI::Button::Animated.new(content, klass).render
47
+ elsif standard_button?(mode)
48
+ MarkdownUI::Button::Standard.new(content, klass).render
49
+ end
50
+ end
51
+
52
+ protected
53
+
54
+ def standard_button?(mode)
55
+ !mode.focusable? && !mode.animated? && !mode.icon? && !mode.labeled? && !mode.basic?
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,23 @@
1
+ # coding: UTF-8
2
+
3
+ module MarkdownUI::Button
4
+ class Focusable
5
+ def initialize(content, klass = nil)
6
+ @klass = klass
7
+ @content = content
8
+ end
9
+
10
+ def render
11
+ content = MarkdownUI::Content::Parser.new(@content).parse
12
+ klass = MarkdownUI::KlassUtil.new("ui #{@klass} button").klass
13
+
14
+ output = []
15
+ output << "<button"
16
+ output << "#{klass}>"
17
+ output << content
18
+ output << "</button>"
19
+
20
+ output.join
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # coding: UTF-8
2
+
3
+ module MarkdownUI::Button
4
+ module Group
5
+ module Buttons
6
+ class Custom
7
+ def initialize(element, content)
8
+ @element = element
9
+ @content = content
10
+ end
11
+
12
+ def render
13
+ klass = "ui #{@element} buttons"
14
+ content = @content.strip
15
+
16
+ MarkdownUI::StandardTag.new(content, klass).render
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end