mdpage 0.0.1 → 0.0.2

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/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/*.html
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .DS_Store
20
+
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ # gem "rails"
5
+ gem 'rdiscount'
6
+ gem 'rake'
7
+ gem 'rspec'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Masahiro Arakane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # mdpage : html generater for markdown files.
2
+ [![Build Status](https://secure.travis-ci.org/arafine/mdpage.png?branch=master)](http://travis-ci.org/arafine/mdpage)
3
+
4
+ ## Usage
5
+ mdpage <file1> <file2>...
6
+ files encoding should be **UTF-8**.
7
+
8
+ ## Dependency
9
+ :default
10
+ - rdiscount
11
+
12
+ :development
13
+ - rspec
14
+ - rake
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'rubygems'
4
+ require 'bundler/gem_tasks'
5
+ require 'bundler'
6
+
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit e.status_code
13
+ end
14
+
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
17
+
18
+ task :default => :spec
19
+
20
+ desc "Run all specs in spec directory"
21
+ RSpec::Core::RakeTask.new(:spec)
data/bin/mdpage CHANGED
@@ -10,5 +10,5 @@ if (ARGV.include? '--help') || (ARGV.include? '-h')
10
10
  end
11
11
 
12
12
  require 'mdpage'
13
- MdPage.new(ARGV).to_html
14
-
13
+ MdPage::Page.new(ARGV).to_html_files
14
+ puts "Done!"
@@ -8,6 +8,7 @@
8
8
  font: 14px Helvetica, arial, freesans, clean, Meiryo, sans-serif;
9
9
  margin: 0;
10
10
  padding: 0;
11
+ line-height: 1.4em;
11
12
  }
12
13
  div#markdown-body {
13
14
  width: 880px;
@@ -0,0 +1,3 @@
1
+ module MdPage
2
+ VERSION = "0.0.2"
3
+ end
data/lib/mdpage.rb CHANGED
@@ -1,38 +1,50 @@
1
1
  require "rdiscount"
2
2
  require "erb"
3
3
 
4
- class MdPage
5
- attr_reader :argv, :path_check, :doc
4
+ module MdPage
5
+ class Page
6
+ attr_reader :argv, :path_check, :doc, :result
6
7
 
7
- def initialize(argv)
8
- @argv = argv
9
- check_results = @argv.map {|av| File.exist? av}
10
- @path_check = check_results.include?(false) ? false : true
11
- tpl_path = File.dirname(__FILE__) + "/default.html.erb"
12
- @template = File.open(tpl_path, "r:utf-8") {|f| f.read}
13
- @doc = Hash.new
14
- end
8
+ def initialize(argv)
9
+ @argv = argv
10
+ check_results = @argv.map {|av| File.exist? av}
11
+ @path_check = check_results.include?(false) ? false : true
12
+ tpl_path = File.dirname(__FILE__) + "/mdpage/default.html.erb"
13
+ @template = File.open(tpl_path, "r:utf-8") {|f| f.read}
14
+ @doc = Hash.new
15
+ @result = nil
16
+ end
15
17
 
16
- def md2html(file)
17
- begin
18
- raw_contents = File.open(file, "r:utf-8") {|f| f.read}
18
+ def md2html(file)
19
+ begin
20
+ raw_contents = File.open(file, "r:utf-8") {|f| f.read}
21
+ rescue
22
+ raise "#{file} encoding should be UTF-8."
23
+ end
19
24
  raw_contents =~ /^.*#\s?(.+)\n.+/
20
25
  @doc[:title] = $1 || ''
21
- rescue
22
- raise "#{file} encoding should be UTF-8."
26
+ contents = RDiscount.new(raw_contents).to_html
27
+ return contents
23
28
  end
24
- contents = RDiscount.new(raw_contents).to_html
25
- return contents
26
- end
27
29
 
28
- def to_html
29
- erb = ERB.new(@template)
30
- @argv.each do |file|
31
- @doc[:contents] = md2html(file)
32
- html = erb.result(binding)
33
- out_path = File.expand_path(file) + ".html"
34
- File.open(out_path, "w:utf-8") {|f| f.write html}
30
+ def to_html_files
31
+ path_data = to_html_objects
32
+ path_data.each do |k, v|
33
+ File.open(k, "w:utf-8") {|f| f.write v}
34
+ end
35
+ @result = true
35
36
  end
36
- end
37
37
 
38
+ def to_html_objects
39
+ erb = ERB.new(@template)
40
+ html_objects = Hash.new
41
+ @argv.each do |file|
42
+ @doc[:contents] = md2html(file)
43
+ html = erb.result(binding)
44
+ out_path = File.expand_path(file) + ".html"
45
+ html_objects.store(out_path, html)
46
+ end
47
+ return html_objects
48
+ end
49
+ end
38
50
  end
data/mdpage.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../lib/mdpage/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Masahiro Arakane"]
5
+ gem.email = ["arafine@me.com"]
6
+ gem.description = <<-DESC
7
+ Simple styled document generator for markdown files
8
+ Usage:
9
+ mdpage <file1> <file2> ...
10
+ DESC
11
+ gem.summary = %q{Simple styled document generator for markdown files}
12
+ gem.homepage = "https://github.com/arafine/mdpage.git"
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "mdpage"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = MdPage::VERSION
19
+ end
data/spec/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ mdpage-*.gem
data/spec/mdpage_spec.rb CHANGED
@@ -1,10 +1,8 @@
1
- # coding: utf-8
2
-
3
1
  $:.unshift(File.dirname(__FILE__) + "/../lib")
4
2
  require "mdpage"
5
3
  require "rspec"
6
4
 
7
- describe MdPage do
5
+ describe MdPage::Page do
8
6
  before(:each) do
9
7
  files = [
10
8
  "#{File.dirname(__FILE__)}/sample.md"
@@ -13,45 +11,50 @@ describe MdPage do
13
11
  "#{File.dirname(__FILE__)}/sample.md",
14
12
  "#{File.dirname(__FILE__)}/sample2.md"
15
13
  ]
16
- @mdp = MdPage.new(files)
17
- @mdp_invalid_enc = MdPage.new(files2)
14
+ @mdp = MdPage::Page.new(files)
15
+ @mdp_invalid_enc = MdPage::Page.new(files2)
18
16
  end
19
17
 
20
- context 'Initializing MdPage' do
21
- it "init with file path as Array" do
18
+ context 'path_chekc should be return true' do
19
+ it "as init with file path as Array" do
22
20
  argv = ["#{File.dirname(__FILE__)}/sample.md"]
23
- mdp = MdPage.new(argv)
21
+ mdp = MdPage::Page.new(argv)
24
22
  mdp.path_check.should == true
25
23
  end
26
24
 
27
- it "init with invalid file path" do
25
+ it "as init with invalid file path" do
28
26
  argv = ["#{File.dirname(__FILE__)}/faff/sample.md"]
29
- mdp = MdPage.new(argv)
27
+ mdp = MdPage::Page.new(argv)
30
28
  mdp.path_check.should == false
31
29
  end
32
30
 
33
- it "init with one or more valid file path" do
31
+ it "as init with one or more valid file path" do
34
32
  argv = [
35
33
  "#{File.dirname(__FILE__)}/sample.md",
36
34
  "#{File.dirname(__FILE__)}/sample2.md"
37
35
  ]
38
- mdp = MdPage.new(argv)
36
+ mdp = MdPage::Page.new(argv)
39
37
  mdp.path_check.should == true
40
38
  end
41
39
 
42
- it "init with one or more invalid file path" do
40
+ it "as init with one or more invalid file path" do
43
41
  argv = [
44
42
  "#{File.dirname(__FILE__)}/sample.md",
45
43
  "#{File.dirname(__FILE__)}/rere/sample2.md"
46
44
  ]
47
- mdp = MdPage.new(argv)
45
+ mdp = MdPage::Page.new(argv)
48
46
  mdp.path_check.should == false
49
47
  end
50
48
  end
51
49
 
52
- context 'Generate html' do
53
- it "MdPage should be return true if generated htmlfile" do
54
- @mdp.to_html.should_not == nil
50
+ context 'Generating html objects' do
51
+ it "should be return Hash" do
52
+ @mdp.to_html_objects.class.should == Hash.new.class
53
+ end
54
+
55
+ it "result should be true as generate html files" do
56
+ @mdp.to_html_files
57
+ @mdp.result.should == true
55
58
  end
56
59
  end
57
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdpage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,34 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-04 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rdiscount
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 1.6.8
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 1.6.8
30
- description:
31
- email: arafine@me.com
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! " Simple styled document generator for markdown
15
+ files\n Usage:\n mdpage <file1>
16
+ <file2> ...\n"
17
+ email:
18
+ - arafine@me.com
32
19
  executables:
33
20
  - mdpage
34
21
  extensions: []
35
22
  extra_rdoc_files: []
36
23
  files:
24
+ - .gitignore
25
+ - .travis.yml
26
+ - Gemfile
27
+ - LICENSE
28
+ - README.md
29
+ - Rakefile
37
30
  - bin/mdpage
38
31
  - lib/mdpage.rb
39
- - lib/default.html.erb
32
+ - lib/mdpage/default.html.erb
33
+ - lib/mdpage/version.rb
34
+ - mdpage.gemspec
35
+ - spec/.gitignore
40
36
  - spec/mdpage_spec.rb
41
37
  - spec/sample.md
42
38
  - spec/sample2.md
@@ -63,6 +59,10 @@ rubyforge_project:
63
59
  rubygems_version: 1.8.24
64
60
  signing_key:
65
61
  specification_version: 3
66
- summary: Simple style document generator
67
- test_files: []
62
+ summary: Simple styled document generator for markdown files
63
+ test_files:
64
+ - spec/.gitignore
65
+ - spec/mdpage_spec.rb
66
+ - spec/sample.md
67
+ - spec/sample2.md
68
68
  has_rdoc: