mdify 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/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mdify (0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ mdify!
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ mdify
2
+ =====
3
+ `mdify` is a tool for previewing Markdown documents right in your browser, with a nice stylesheet.
4
+
5
+ ![Screenshot of mdify](http://i.imgur.com/OiRr5.png)
6
+
7
+ Usage
8
+ -----
9
+ You can use it on your documents by running:
10
+
11
+ mdify super_secret.md
12
+
13
+ It will automatically open a new browser window with the content rendered in there.
14
+
15
+ Installing
16
+ ----
17
+ The installation requires Ruby 1.8.7 or greater.
18
+
19
+ gem install mdify
20
+
21
+ Emacs
22
+ ----
23
+ You can hook `mdify` to the `compile-command` in Emacs so it's run by pressing a
24
+ key.
25
+
26
+ First, bind the compile key to whatever you want to use:
27
+
28
+ (global-set-key [f5] 'compile)
29
+
30
+ Then create a new hook for the Markdown mode:
31
+
32
+ (add-hook 'markdown-mode-hook
33
+ (lambda ()
34
+ (set (make-local-variable 'compile-command) (concat "mdify " (buffer-name)))))
35
+
36
+ Now you can press F5 inside any Markdown document to automatically preview it in your browser.
37
+
38
+ Stylesheet
39
+ ----
40
+ The pretty styles are provided by Twitter's [Bootstrap](http://twitter.github.com/bootstrap/)
41
+ library. Right now there's no support for custom stylesheets but feel free to open an issue or
42
+ create a pull request if you want to add something else.
43
+
44
+ Farewell
45
+ ----
46
+ This was written by [Federico](http://mheroin.com). Drop me a line on Twitter
47
+ ([@febuiles](http://twitter.com/febuiles)) if you're using this.
data/Rakefile ADDED
@@ -0,0 +1,126 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Open an irb session preloaded with this library"
56
+ task :console do
57
+ sh "irb -rubygems -r ./lib/#{name}.rb"
58
+ end
59
+
60
+ #############################################################################
61
+ #
62
+ # Packaging tasks
63
+ #
64
+ #############################################################################
65
+
66
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
67
+ task :release => :build do
68
+ unless `git branch` =~ /^\* master$/
69
+ puts "You must be on the master branch to release!"
70
+ exit!
71
+ end
72
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
73
+ sh "git tag v#{version}"
74
+ sh "git push origin master"
75
+ sh "git push origin v#{version}"
76
+ sh "gem push pkg/#{name}-#{version}.gem"
77
+ end
78
+
79
+ desc "Build #{gem_file} into the pkg directory"
80
+ task :build => :gemspec do
81
+ sh "mkdir -p pkg"
82
+ sh "gem build #{gemspec_file}"
83
+ sh "mv #{gem_file} pkg"
84
+ end
85
+
86
+ desc "Generate #{gemspec_file}"
87
+ task :gemspec => :validate do
88
+ # read spec file and split out manifest section
89
+ spec = File.read(gemspec_file)
90
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
91
+
92
+ # replace name version and date
93
+ replace_header(head, :name)
94
+ replace_header(head, :version)
95
+ replace_header(head, :date)
96
+ #comment this out if your rubyforge_project has a different name
97
+ replace_header(head, :rubyforge_project)
98
+
99
+ # determine file list from git ls-files
100
+ files = `git ls-files`.
101
+ split("\n").
102
+ sort.
103
+ reject { |file| file =~ /^\./ }.
104
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
105
+ map { |file| " #{file}" }.
106
+ join("\n")
107
+
108
+ # piece file back together and write
109
+ manifest = " s.files = %w[\n#{files}\n ]\n"
110
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
111
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
112
+ puts "Updated #{gemspec_file}"
113
+ end
114
+
115
+ desc "Validate #{gemspec_file}"
116
+ task :validate do
117
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
118
+ unless libfiles.empty?
119
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
120
+ exit!
121
+ end
122
+ unless Dir['VERSION*'].empty?
123
+ puts "A `VERSION` file at root level violates Gem best practices."
124
+ exit!
125
+ end
126
+ end
data/bin/mdify ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
+
6
+ require 'mdify'
7
+ Mdify.preview(ARGV.first)
data/lib/mdify.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'tempfile'
3
+ require 'redcarpet'
4
+
5
+ require 'mdify/renderer'
6
+
7
+ module Mdify
8
+ VERSION = "0.1"
9
+
10
+ def self.preview(filename)
11
+ Renderer.new(filename).render
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module Mdify
2
+ HTML_TEMPLATE_PATH = File.join(File.dirname(__FILE__), "..", "..", "vendor", "template.html")
3
+
4
+ class Renderer
5
+ attr_reader :title, :content
6
+
7
+ def initialize(filename)
8
+ @title = filename
9
+ @content = File.read(filename)
10
+ end
11
+
12
+ def render
13
+ html = Redcarpet.new(@content).to_html
14
+ document = render_html(@title, html)
15
+ temp_file = create_temp_file(document)
16
+ exec "open #{temp_file}"
17
+ end
18
+
19
+ def render_html(title, html)
20
+ template_file = File.read(HTML_TEMPLATE_PATH)
21
+ document = template_file.sub(/\{\{ title \}\}/, title)
22
+ document.sub!(/\{\{ body \}\}/, html)
23
+ end
24
+
25
+ def create_temp_file(contents)
26
+ temp_file = Tempfile.new("mdify")
27
+ temp_file.write(contents)
28
+ temp_file.close
29
+ temp_file.path
30
+ end
31
+ end
32
+ end
data/mdify.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ ## Leave these as is they will be modified for you by the rake gemspec task.
7
+ ## If your rubyforge_project name is different, then edit it and comment out
8
+ ## the sub! line in the Rakefile
9
+ s.name = 'mdify'
10
+ s.version = '0.1'
11
+ s.date = '2011-11-28'
12
+ s.rubyforge_project = 'mdify'
13
+
14
+ ## Make sure your summary is short. The description may be as long
15
+ ## as you like.
16
+ s.summary = "Preview Markdown documents with your browser"
17
+ s.description = "mdify is a tool for previewing Markdown documents right in your browser, with a nice stylesheet."
18
+
19
+ ## List the primary authors. If there are a bunch of authors, it's probably
20
+ ## better to set the email to an email list or something. If you don't have
21
+ ## a custom homepage, consider using your GitHub URL or the like.
22
+ s.authors = ["Federico Builes"]
23
+ s.email = 'federico@mheroin.com'
24
+ s.homepage = 'http://github.com/febuiles/mdify'
25
+
26
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
27
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
28
+ s.require_paths = %w[lib]
29
+
30
+ ## If your gem includes any executables, list them here.
31
+ s.executables = ["mdify"]
32
+
33
+ ## List your runtime dependencies here. Runtime dependencies are those
34
+ ## that are needed for an end user to actually USE your code.
35
+ s.add_dependency("redcarpet")
36
+
37
+ ## List your development dependencies here. Development dependencies are
38
+ ## those that are only needed during development
39
+ # s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
40
+
41
+ ## Leave this section as-is. It will be automatically generated from the
42
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
43
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
44
+ # = MANIFEST =
45
+ s.files = %w[
46
+ Gemfile
47
+ Gemfile.lock
48
+ README.md
49
+ Rakefile
50
+ bin/mdify
51
+ lib/mdify.rb
52
+ lib/mdify/renderer.rb
53
+ mdify.gemspec
54
+ vendor/template.html
55
+ ]
56
+ # = MANIFEST =
57
+
58
+ ## Test files will be grabbed from the file list. Make sure the path glob
59
+ ## matches what you actually use.
60
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
61
+ end
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <title>{{ title }}</title>
5
+ <link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.css">
6
+ <style>
7
+ body { padding: 30px; width: 960px; }
8
+ code { background-color: #f5f5f5; }
9
+ h2 { margin-bottom: 10px; }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ {{ body }}
14
+ </body>
15
+ </html>
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdify
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Federico Builes
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-11-28 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: redcarpet
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: mdify is a tool for previewing Markdown documents right in your browser, with a nice stylesheet.
34
+ email: federico@mheroin.com
35
+ executables:
36
+ - mdify
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - Gemfile
43
+ - Gemfile.lock
44
+ - README.md
45
+ - Rakefile
46
+ - bin/mdify
47
+ - lib/mdify.rb
48
+ - lib/mdify/renderer.rb
49
+ - mdify.gemspec
50
+ - vendor/template.html
51
+ homepage: http://github.com/febuiles/mdify
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: mdify
80
+ rubygems_version: 1.8.10
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: Preview Markdown documents with your browser
84
+ test_files: []
85
+