krambook 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,51 @@
1
+ ## Introduction
2
+
3
+ Krambook makes it easier to work with your ebooks. It currently provides two things;
4
+
5
+ 1. Mimics the workflow of LeanPub.
6
+ It will take your Book.txt parse it and save a `Joined.md` in your manuscript folder
7
+
8
+ 2. Supports external source code files.
9
+
10
+ More things are planned in the future.
11
+
12
+ # Installation and Usage
13
+
14
+ ## Install:
15
+
16
+ ```sh
17
+ $ gem install krambook
18
+ ````
19
+
20
+ ## Usage:
21
+
22
+ cd into your LeanPub ebook folder and then run:
23
+
24
+ ```sh
25
+ $ krambook
26
+ ````
27
+
28
+ To include external code files:
29
+
30
+ ```sh
31
+ $ krambook -f includey
32
+ ```
33
+
34
+ The format for external files is:
35
+
36
+ ```markdown
37
+ \~\~\~ ruby
38
+ This will be replaced by an external file
39
+ \~\~\~
40
+ {: .language-ruby include="external_file.rb"}
41
+ ```
42
+
43
+ ### Help:
44
+
45
+ To get help run:
46
+
47
+ ```sh
48
+ $ krambook -h
49
+ ```
50
+
51
+ # More Docs Coming Soon
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'krambook'
6
+ Krambook::CLI.start
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env gem build
2
+ # encoding: utf-8
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'krambook'
6
+ s.rubyforge_project = 'krambook'
7
+ s.authors = ["K-2052"]
8
+ s.email = 'k@2052.me'
9
+ s.summary = 'Kraft your ebooks with Kramdown.'
10
+ s.homepage = 'http://github.com/bookworm/krambook'
11
+ s.description = 'Kraft your ebooks with Kramdown. Intended as a collection
12
+ of helpers for working with Markdown based ebooks.
13
+ Currently operates like a local version of LeanPub.'
14
+ s.required_rubygems_version = '>= 1.3.6'
15
+ s.version = '0.0.1'
16
+ s.date = Time.now.strftime("%Y-%m-%d")
17
+
18
+ s.files = `git ls-files`.split("\n") | Dir.glob("{lib}/**/*")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ['lib']
22
+ s.rdoc_options = ['--charset=UTF-8']
23
+
24
+ s.add_dependency('kramdown')
25
+ s.add_dependency('bundler', '~> 1.0')
26
+ s.add_dependency('thor')
27
+ s.add_dependency('active_support')
28
+ end
@@ -0,0 +1,35 @@
1
+ require 'kramdown'
2
+ require 'kramdown/converter/includey'
3
+ require 'thor'
4
+
5
+
6
+ module Krambook
7
+ class CLI < Thor
8
+ include Thor::Actions
9
+
10
+ class_option :format, :desc => 'The format to convert to', :aliases => '-f', :default => 'kramdown', :type => :string
11
+ class_option :help, :type => :boolean, :desc => 'Show help usage'
12
+ default_task :join
13
+
14
+ desc 'join', 'Joins the markdown files'
15
+ def join
16
+ files = []
17
+ joined_file_path = File.expand_path './manuscript/' + 'Joined.md'
18
+ File.delete(joined_file_path) if File.exist?(joined_file_path)
19
+
20
+ File.open(File.expand_path('./manuscript/Book.txt'), 'r') do |f|
21
+ f.each_line do |line|
22
+ files << line.gsub(/\s+/, "")
23
+ end
24
+ end
25
+
26
+ File.open(joined_file_path, 'a') do |f|
27
+ files.each do |file_path|
28
+ full_file_path = File.expand_path './manuscript/' + file_path
29
+ f.puts Kramdown::Document.new(IO.read(full_file_path)).send("to_#{options[:format]}".to_sym) if File.exists?(full_file_path)
30
+ f.puts '' unless file_path = files.last
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ module Kramdown
2
+ module Converter
3
+ class Includey < ::Kramdown::Converter::Kramdown
4
+ def convert_codeblock(el, indent)
5
+ if el.attr.include?('include')
6
+ file_path = File.expand_path(Dir.pwd + '/' + el.attr['include'])
7
+ el.value = IO.read(file_path) if File.exists?(file_path)
8
+ end
9
+
10
+ attr = el.attr.dup
11
+ lang = extract_code_language!(attr)
12
+ "~~~ #{lang}\n" + el.value.split(/\n/).map {|l| l.empty? ? "" : "#{l}"}.join("\n") + "\n~~~\n"
13
+ end
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: krambook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - K-2052
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: kramdown
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: thor
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: active_support
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! "Kraft your ebooks with Kramdown. Intended as a collection \n of
79
+ helpers for working with Markdown based ebooks. \n Currently
80
+ operates like a local version of LeanPub."
81
+ email: k@2052.me
82
+ executables:
83
+ - krambook
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - Gemfile
88
+ - README.md
89
+ - bin/krambook
90
+ - krambook.gemspec
91
+ - lib/krambook.rb
92
+ - lib/kramdown/converter/includey.rb
93
+ homepage: http://github.com/bookworm/krambook
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.6
112
+ requirements: []
113
+ rubyforge_project: krambook
114
+ rubygems_version: 1.8.23
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Kraft your ebooks with Kramdown.
118
+ test_files: []