codemerger 0.2.1 → 0.5.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 138e0018aa36bcdef11297caa65360ba39db60afe8afc5d23f13e7d6897cbd05
4
+ data.tar.gz: 1e986254f52e0005d9effd651d281cd5e55b04b70b0358bbb40ecba81a6b1612
5
+ SHA512:
6
+ metadata.gz: bd032ec6da7b1c713240d098fe1f43c58ed8f1bfe050e6489c28605c6a7b4f69b736c49cebd61b6ac9cd8413deef4db75eacb6a646dec79f497c82564245f4bb
7
+ data.tar.gz: c6c06615c9e412e058d72271c30c53599d1c2718940aec7c233d44a447c8881caeca2a697e792f188edbfecae4de258e5a534c49d4a4e8a382313ac781d66fd5
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.3.7
data/Gemfile CHANGED
@@ -1,4 +1,13 @@
1
1
  source "http://rubygems.org"
2
+ gem "kramdown"
3
+ gem "rake"
4
+ gem "rouge"
2
5
 
3
- # Specify your gem's dependencies in codemerger.gemspec
4
- gemspec
6
+ group :development, :test do
7
+ gem "simplecov", require: false
8
+ # gem "rspec"
9
+ gem "bundler"
10
+ gem "jeweler"
11
+ gem "minitest"
12
+ gem "rubocop"
13
+ end
data/Gemfile.lock CHANGED
@@ -1,19 +1,141 @@
1
- PATH
2
- remote: .
3
- specs:
4
- codemerger (0.0.1)
5
- maruku
6
-
7
1
  GEM
8
2
  remote: http://rubygems.org/
9
3
  specs:
10
- maruku (0.6.0)
11
- syntax (>= 1.0.0)
12
- syntax (1.0.0)
4
+ addressable (2.4.0)
5
+ ast (2.4.2)
6
+ base64 (0.2.0)
7
+ bigdecimal (3.1.9)
8
+ builder (3.3.0)
9
+ date (3.4.1)
10
+ descendants_tracker (0.0.4)
11
+ thread_safe (~> 0.3, >= 0.3.1)
12
+ docile (1.4.1)
13
+ faraday (0.9.2)
14
+ multipart-post (>= 1.2, < 3)
15
+ git (1.11.0)
16
+ rchardet (~> 1.8)
17
+ github_api (0.16.0)
18
+ addressable (~> 2.4.0)
19
+ descendants_tracker (~> 0.0.4)
20
+ faraday (~> 0.8, < 0.10)
21
+ hashie (>= 3.4)
22
+ mime-types (>= 1.16, < 3.0)
23
+ oauth2 (~> 1.0)
24
+ hashie (5.0.0)
25
+ highline (3.1.2)
26
+ reline
27
+ io-console (0.8.0)
28
+ jeweler (2.3.9)
29
+ builder
30
+ bundler
31
+ git (>= 1.2.5)
32
+ github_api (~> 0.16.0)
33
+ highline (>= 1.6.15)
34
+ nokogiri (>= 1.5.10)
35
+ psych
36
+ rake
37
+ rdoc
38
+ semver2
39
+ json (2.10.1)
40
+ jwt (2.10.1)
41
+ base64
42
+ kramdown (2.5.1)
43
+ rexml (>= 3.3.9)
44
+ language_server-protocol (3.17.0.4)
45
+ lint_roller (1.1.0)
46
+ mime-types (2.99.3)
47
+ minitest (5.25.4)
48
+ multi_json (1.15.0)
49
+ multi_xml (0.7.1)
50
+ bigdecimal (~> 3.1)
51
+ multipart-post (2.4.1)
52
+ nokogiri (1.18.3-aarch64-linux-gnu)
53
+ racc (~> 1.4)
54
+ nokogiri (1.18.3-aarch64-linux-musl)
55
+ racc (~> 1.4)
56
+ nokogiri (1.18.3-arm-linux-gnu)
57
+ racc (~> 1.4)
58
+ nokogiri (1.18.3-arm-linux-musl)
59
+ racc (~> 1.4)
60
+ nokogiri (1.18.3-arm64-darwin)
61
+ racc (~> 1.4)
62
+ nokogiri (1.18.3-x86_64-darwin)
63
+ racc (~> 1.4)
64
+ nokogiri (1.18.3-x86_64-linux-gnu)
65
+ racc (~> 1.4)
66
+ nokogiri (1.18.3-x86_64-linux-musl)
67
+ racc (~> 1.4)
68
+ oauth2 (1.4.8)
69
+ faraday (>= 0.8, < 3.0)
70
+ jwt (>= 1.0, < 3.0)
71
+ multi_json (~> 1.3)
72
+ multi_xml (~> 0.5)
73
+ rack (>= 1.2, < 3)
74
+ parallel (1.26.3)
75
+ parser (3.3.7.1)
76
+ ast (~> 2.4.1)
77
+ racc
78
+ psych (5.2.3)
79
+ date
80
+ stringio
81
+ racc (1.8.1)
82
+ rack (2.2.11)
83
+ rainbow (3.1.1)
84
+ rake (13.2.1)
85
+ rchardet (1.9.0)
86
+ rdoc (6.12.0)
87
+ psych (>= 4.0.0)
88
+ regexp_parser (2.10.0)
89
+ reline (0.6.0)
90
+ io-console (~> 0.5)
91
+ rexml (3.4.1)
92
+ rouge (4.5.1)
93
+ rubocop (1.72.2)
94
+ json (~> 2.3)
95
+ language_server-protocol (~> 3.17.0.2)
96
+ lint_roller (~> 1.1.0)
97
+ parallel (~> 1.10)
98
+ parser (>= 3.3.0.2)
99
+ rainbow (>= 2.2.2, < 4.0)
100
+ regexp_parser (>= 2.9.3, < 3.0)
101
+ rubocop-ast (>= 1.38.0, < 2.0)
102
+ ruby-progressbar (~> 1.7)
103
+ unicode-display_width (>= 2.4.0, < 4.0)
104
+ rubocop-ast (1.38.0)
105
+ parser (>= 3.3.1.0)
106
+ ruby-progressbar (1.13.0)
107
+ semver2 (3.4.2)
108
+ simplecov (0.22.0)
109
+ docile (~> 1.1)
110
+ simplecov-html (~> 0.11)
111
+ simplecov_json_formatter (~> 0.1)
112
+ simplecov-html (0.13.1)
113
+ simplecov_json_formatter (0.1.4)
114
+ stringio (3.1.5)
115
+ thread_safe (0.3.6)
116
+ unicode-display_width (3.1.4)
117
+ unicode-emoji (~> 4.0, >= 4.0.4)
118
+ unicode-emoji (4.0.4)
13
119
 
14
120
  PLATFORMS
15
- x86-mingw32
121
+ aarch64-linux-gnu
122
+ aarch64-linux-musl
123
+ arm-linux-gnu
124
+ arm-linux-musl
125
+ arm64-darwin
126
+ x86_64-darwin
127
+ x86_64-linux-gnu
128
+ x86_64-linux-musl
16
129
 
17
130
  DEPENDENCIES
18
- codemerger!
19
- maruku
131
+ bundler
132
+ jeweler
133
+ kramdown
134
+ minitest
135
+ rake
136
+ rouge
137
+ rubocop
138
+ simplecov
139
+
140
+ BUNDLED WITH
141
+ 2.5.22
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 Rodrigo Urubatan <rodrigo@urubatan.com.br>
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.markdown CHANGED
@@ -1,53 +1,53 @@
1
- This gem is used to help writing technical posts for wordpress.
2
-
3
- To use this GEM I usually create a new directory for the post or post group project, then I create a Gemfile like this:
4
-
1
+ This gem is used to help writing technical posts for wordpress.
2
+
3
+ To use this GEM I usually create a new directory for the post or post group project, then I create a Gemfile like this:
4
+
5
5
  source "http://rubygems.org"
6
6
  group :rake do
7
- gem "codemerger", "0.1.0", :require => "codemerger/rake_tasks"
7
+ gem "codemerger", "0.5.0", :require => "codemerger/rake_tasks"
8
8
  end
9
-
10
- After that I create a Rakefile like this:
11
-
9
+
10
+ After that I create a Rakefile like this:
11
+
12
12
  require "rubygems"
13
13
  require "bundler/setup"
14
14
  Bundler.require :rake
15
15
 
16
- Then just start creating the post file in the root directory, the project supports .html or .markdown files for the posts.
17
- Inside this file, when I want to include a source sample, I create another file for the sample, and then I include it into the main post file with a code like this:
18
-
19
- {{full/path/to/the/file.rb}}
20
-
21
- When the post is ready I run teh rake task:
22
-
23
- rake codemerger:merge
24
-
25
- After that, the file I was writting is processed, a new file is created into the output directory and the sample source files are included with a code like this:
26
-
27
- <b>{{full/path/to/the/file.rb}}</b>
28
- <pre line="1" lang="ruby">
29
- ruby code
30
- </pre>
31
-
32
- This snippet is then copied and pasted to a post into my wordpress blog, and the code gets colored using the plugin wp-syntax, and the output can be turned into PDF with the plugin wp-mpdf.
33
-
34
- Today this gem supports source files in the following languages:
35
-
36
- * Ruby (including Rakefile and Gemfile)
37
- * Java
38
- * YAML
39
- * HTML
40
- * XML
41
- * Scala
42
- * CSS
43
- * Javascript
44
- * Bash
45
- * Batch
46
-
47
- All other files are configured as "text".
48
-
49
- For the next steps I'm planning to write more automated tests, refactor the language support code out, today it is a switch statement to convert from a file extension to a name supported by wp-syntax/Geshi and add support for templates and direct conversion of the source samples to colored HTML.
50
-
51
- All these changes are simple, but besides the automated tests, I do not need any of the other right now, if you think they will be usefull for you, send me a message, file an enhancement request or fork, implement and send me a pull request.
52
-
53
- Any testing or comments will be of great value, today, I think only I'm using this GEM.
16
+ Then just start creating the post file in the root directory, the project supports .html or .markdown files for the posts.
17
+ Inside this file, when I want to include a source sample, I create another file for the sample, and then I include it into the main post file with a code like this:
18
+
19
+ {{full/path/to/the/file.rb}}
20
+
21
+ When the post is ready I run teh rake task:
22
+
23
+ rake codemerger:merge
24
+
25
+ After that, the file I was writting is processed, a new file is created into the output directory and the sample source files are included with a code like this:
26
+
27
+ <b>{{full/path/to/the/file.rb}}</b>
28
+ <pre line="1" lang="ruby">
29
+ ruby code
30
+ </pre>
31
+
32
+ This snippet is then copied and pasted to a post into my wordpress blog, and the code gets colored using the plugin wp-syntax, and the output can be turned into PDF with the plugin wp-mpdf.
33
+
34
+ Today this gem supports source files in the following languages:
35
+
36
+ * Ruby (including Rakefile and Gemfile)
37
+ * Java
38
+ * YAML
39
+ * HTML
40
+ * XML
41
+ * Scala
42
+ * CSS
43
+ * Javascript
44
+ * Bash
45
+ * Batch
46
+
47
+ All other files are configured as "text".
48
+
49
+ For the next steps I'm planning to write more automated tests, refactor the language support code out, today it is a switch statement to convert from a file extension to a name supported by wp-syntax/Geshi and add support for templates and direct conversion of the source samples to colored HTML.
50
+
51
+ All these changes are simple, but besides the automated tests, I do not need any of the other right now, if you think they will be usefull for you, send me a message, file an enhancement request or fork, implement and send me a pull request.
52
+
53
+ Any testing or comments will be of great value, today, I think only I'm using this GEM.
data/Rakefile CHANGED
@@ -1,5 +1,44 @@
1
- require 'bundler'
2
- task :fake do
3
-
1
+ require "rubygems"
2
+ require "bundler"
3
+ require "rake/testtask"
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ warn e.message
8
+ warn "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require "jeweler"
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "codemerger"
16
+ gem.homepage = "https://github.com/urubatan/codemerger"
17
+ gem.license = "MIT"
18
+ gem.summary = %(Used to create blog posts and tecnical articles that need code samples, the code samples will be taken from the actual source code file instead of a copy paste approach)
19
+ gem.description = %{This gem is used to help writing technical posts for wordpress.
20
+ The output is copied and pasted to a post into my wordpress blog, and the code gets colored using the plugin wp-syntax, and the output can be turned into PDF with the plugin wp-mpdf.
21
+
22
+ Today this gem supports source files in the following languages:
23
+
24
+ * Ruby (including Rakefile and Gemfile)
25
+ * Java
26
+ * YAML
27
+ * HTML
28
+ * XML
29
+ * Scala
30
+ * CSS
31
+ * Javascript
32
+ * Bash
33
+ * Batch
34
+
35
+ All other files are configured as "text".}
36
+ gem.email = "rodrigo@urubatan.com.br"
37
+ gem.authors = [ "Rodrigo Urubatan" ]
38
+ # dependencies defined in Gemfile
39
+ end
40
+ Jeweler::RubygemsDotOrgTasks.new
41
+
42
+ Rake::TestTask.new do |t|
43
+ t.pattern = "test/*_spec.rb"
4
44
  end
5
- Bundler::GemHelper.install_tasks :name => 'codemerger'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
data/codemerger.gemspec CHANGED
@@ -1,38 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
1
4
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "codemerger/version"
5
+ # stub: codemerger 0.5.0 ruby lib
4
6
 
5
7
  Gem::Specification.new do |s|
6
- s.name = "codemerger"
7
- s.version = Codemerger::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Rodrigo Urubatan"]
10
- s.email = ["rodrigo@urubatan.com.br"]
11
- s.homepage = "https://github.com/urubatan/codemerger"
12
- s.summary = %q{Used to create blog posts and tecnical articles that need code samples, the code samples will be taken from the actual source code file instead of a copy paste approach}
13
- s.description = %q{This gem is used to help writing technical posts for wordpress.
14
- The output is copied and pasted to a post into my wordpress blog, and the code gets colored using the plugin wp-syntax, and the output can be turned into PDF with the plugin wp-mpdf.
15
-
16
- Today this gem supports source files in the following languages:
17
-
18
- * Ruby (including Rakefile and Gemfile)
19
- * Java
20
- * YAML
21
- * HTML
22
- * XML
23
- * Scala
24
- * CSS
25
- * Javascript
26
- * Bash
27
- * Batch
28
-
29
- All other files are configured as "text".}
8
+ s.name = "codemerger".freeze
9
+ s.version = "0.5.0".freeze
30
10
 
31
- s.rubyforge_project = "codemerger"
32
- s.add_dependency 'maruku'
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Rodrigo Urubatan".freeze]
14
+ s.date = "2025-02-26"
15
+ s.description = "This gem is used to help writing technical posts for wordpress.\n The output is copied and pasted to a post into my wordpress blog, and the code gets colored using the plugin wp-syntax, and the output can be turned into PDF with the plugin wp-mpdf.\n\nToday this gem supports source files in the following languages:\n\n* Ruby (including Rakefile and Gemfile)\n* Java\n* YAML\n* HTML\n* XML\n* Scala\n* CSS\n* Javascript\n* Bash\n* Batch\n\nAll other files are configured as \"text\".".freeze
16
+ s.email = "rodrigo@urubatan.com.br".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.markdown"
20
+ ]
21
+ s.files = [
22
+ ".ruby-version",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "codemerger.gemspec",
30
+ "lib/codemerger.rb",
31
+ "lib/codemerger/document_with_css.html.erb",
32
+ "lib/codemerger/merger.rb",
33
+ "lib/codemerger/rake_tasks.rb",
34
+ "lib/codemerger/version.rb",
35
+ "test/merger_spec.rb",
36
+ "test/sample.rb",
37
+ "test/test.html",
38
+ "test/test2.markdown",
39
+ "test/test_helper.rb",
40
+ "test/version_spec.rb"
41
+ ]
42
+ s.homepage = "https://github.com/urubatan/codemerger".freeze
43
+ s.licenses = ["MIT".freeze]
44
+ s.rubygems_version = "3.5.22".freeze
45
+ s.summary = "Used to create blog posts and tecnical articles that need code samples, the code samples will be taken from the actual source code file instead of a copy paste approach".freeze
33
46
 
34
- s.files = `git ls-files`.split("\n")
35
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
37
- s.require_paths = ["lib"]
47
+ s.specification_version = 4
48
+
49
+ s.add_runtime_dependency(%q<kramdown>.freeze, [">= 0".freeze])
50
+ s.add_runtime_dependency(%q<rake>.freeze, [">= 0".freeze])
51
+ s.add_runtime_dependency(%q<rouge>.freeze, [">= 0".freeze])
52
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
53
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0".freeze])
54
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0".freeze])
55
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0".freeze])
56
+ s.add_development_dependency(%q<rubocop>.freeze, [">= 0".freeze])
38
57
  end
58
+
@@ -0,0 +1,48 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <% if @converter.root.options[:encoding] %>
5
+ <meta http-equiv="Content-type" content="text/html;charset=<%= @converter.root.options[:encoding] %>">
6
+ <% end %>
7
+ <%
8
+ extend ::Kramdown::Utils::Html
9
+ title = ''
10
+ h = @converter.root.children.find {|c| c.type == :header}
11
+ if h
12
+ collector = lambda {|c| c.children.collect {|cc| cc.type == :text ? escape_html(cc.value, :text) : collector.call(cc)}.join('')}
13
+ title = collector.call(h)
14
+ end
15
+ %>
16
+ <title><%= title %></title>
17
+ <meta name="generator" content="kramdown <%= ::Kramdown::VERSION %>" />
18
+ <style>
19
+ p:has(.code-title) {
20
+ margin-bottom: 0;
21
+ .code-title {
22
+ font-weight: bold;
23
+ }
24
+ }
25
+
26
+ .highlighter-rouge {
27
+ border: 1px solid black;
28
+ display: block;
29
+ width: fit-content;
30
+ margin: 1em 0;
31
+
32
+ pre.highlight {
33
+ margin: 0;
34
+ }
35
+
36
+ }
37
+
38
+ p:has(.code-title)+.highlighter-rouge {
39
+ margin-top: 0;
40
+ }
41
+
42
+ <%= Rouge::Themes::Github.render(scope: '.highlight') %>
43
+ </style>
44
+ </head>
45
+ <body>
46
+ <%= @body %>
47
+ </body>
48
+ </html>
@@ -0,0 +1,106 @@
1
+ require "fileutils"
2
+ require "kramdown"
3
+
4
+ module Codemerger
5
+ class Merger
6
+ def initialize(dir_name)
7
+ @dir_name = dir_name
8
+ end
9
+
10
+ def clean_dirs
11
+ FileUtils.rm_rf "output"
12
+ FileUtils.mkdir_p "output"
13
+ FileUtils.mkdir_p "output/#{@dir_name}" if @dir_name != "."
14
+ end
15
+
16
+ def get_language_str(ext)
17
+ case ext
18
+ when ".yml" then "yaml"
19
+ when ".xml" then "xml"
20
+ when ".html" then "xml"
21
+ when ".rb" then "ruby"
22
+ when ".java" then "java"
23
+ when ".scala" then "scala"
24
+ when ".erb" then "erb"
25
+ when ".xsl" then "xslt"
26
+ when ".css" then "css"
27
+ when ".scss" then "scss"
28
+ when ".coffee" then "coffeescript"
29
+ when ".js" then "javascript"
30
+ when ".sh" then "bash"
31
+ when ".bat" then "batch"
32
+ when ".xhtml" then "xml"
33
+ when nil then "ruby"
34
+ else; "text"
35
+ end
36
+ end
37
+
38
+ def sanitize(fname)
39
+ fname.gsub(/.*?:/, "")
40
+ end
41
+
42
+ def read_contents(fname)
43
+ if fname =~ /.+:/
44
+ `git cat-file blob #{fname}`
45
+ else
46
+ IO.readlines(fname).join("")
47
+ end
48
+ end
49
+
50
+ def build_html_merged_file_content(f_name)
51
+ ext = f_name[/(\.[a-zA-Z]+)/]
52
+ lang_str = get_language_str(ext)
53
+ %(
54
+ <b>#{sanitize(f_name)}</b>
55
+ <pre line="1" lang="#{lang_str}">
56
+ #{read_contents(f_name)}
57
+ </pre>
58
+ )
59
+ end
60
+
61
+ def build_md_merged_file_content(f_name)
62
+ ext = f_name[/(\.[a-zA-Z]+)/]
63
+ lang_str = get_language_str(ext)
64
+ %(_#{sanitize(f_name)}_{:.code-title}
65
+
66
+ ~~~ #{lang_str}
67
+ #{read_contents(f_name)}
68
+ ~~~
69
+ )
70
+ end
71
+
72
+ def process_files
73
+ in_files = Dir.glob("#{@dir_name}/**/*.{markdown,md,html}")
74
+ in_files.sort.each do |file|
75
+ in_lines = IO.readlines(file).join("")
76
+ is_markdown = (file =~ /markdown$/) || (file =~ /md$/)
77
+ out_fname = file[/^.*\./]
78
+ out_f_name = "output/#{out_fname}html"
79
+ out_d = File.dirname(out_f_name)
80
+ FileUtils.mkdir_p out_d
81
+ File.open(out_f_name, "w:utf-8") do |out_f|
82
+ if is_markdown
83
+ in_lines.gsub!(%r{(\{\{[/a-zA-Z0-9:_]+(?>\.[a-z:_A-Z0-9]{2,}){0,3}\}\})}) do |f_name_match|
84
+ puts "Merging #{f_name_match}"
85
+ f_name = f_name_match[2..-3]
86
+ build_md_merged_file_content(f_name)
87
+ end
88
+ out_f << process_markdown(in_lines)
89
+ else
90
+ out_f << in_lines.gsub(%r{(\{\{[/a-zA-Z0-9_]+(?>\.[a-zA-Z0-9]{2,}){0,3}\}\})}) do |f_name_match|
91
+ puts "Merging #{f_name_match}"
92
+ f_name = f_name_match[2..-3]
93
+ build_html_merged_file_content(f_name)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ def process_markdown(text)
101
+ template = "string://#{File.read(File.join(File.dirname(File.expand_path(__FILE__)),'document_with_css.html.erb'))}"
102
+ doc = Kramdown::Document.new(text, syntax_highlighter: :rouge, header_links: true, auto_ids: true, template: template)
103
+ doc.to_html
104
+ end
105
+ end
106
+ end
@@ -1,43 +1,9 @@
1
- namespace "codemerger" do
2
- desc "Merge all the markdown files and the source files to create the output/post.html file"
3
- task :merge do
4
- require 'fileutils'
5
- FileUtils.rm_rf 'output'
6
- FileUtils.mkdir_p 'output'
7
- in_files = Dir.glob("*.{markdown,html}")
8
- in_files.sort.each do |file|
9
- in_lines = IO.readlines(file).join('')
10
- in_lines = Maruku.new(in_lines).to_html if file =~ /markdown$/
11
- out_fname = file[/^.*\./]
12
- out_f = File.new("output/#{out_fname}html", 'w')
13
- out_f << in_lines.gsub(/(\{\{[\/a-zA-Z0-9_]+(?>\.[a-zA-Z0-9]{2,}){0,3}\}\})/) do |f_name_match|
14
- f_name = f_name_match[2..-3]
15
- ext = f_name[/(\.[a-zA-Z]+)/]
16
- lang_str = case ext
17
- when ".yml"; "lang=\"yaml\""
18
- when ".xml"; "lang=\"xml\""
19
- when ".html"; "lang=\"xml\""
20
- when ".rb"; "lang=\"ruby\""
21
- when ".java"; "lang=\"java\""
22
- when ".scala"; "lang=\"scala\""
23
- when ".erb"; "lang=\"ruby\""
24
- when ".xsl"; "lang=\"xml\""
25
- when ".css"; "lang=\"css\""
26
- when ".js"; "lang=\"javascript\""
27
- when ".sh"; "lang=\"bash\""
28
- when ".bat"; "lang=\"batch\""
29
- when ".xhtml"; "lang=\"xml\""
30
- when nil; "lang=\"ruby\""
31
- else; "lang=\"text\""
32
- end
33
-
34
- <<_EOF_
35
- <b>#{f_name}</b>
36
- <pre line="1" #{lang_str}>
37
- #{IO.readlines(f_name).join('')}
38
- </pre>
39
- _EOF_
40
- end
41
- end
42
- end
43
- end
1
+ require "codemerger"
2
+ namespace "codemerger" do
3
+ desc "Merge all the markdown files and the source files to create the output/post.html file"
4
+ task :merge do
5
+ @merger = Codemerger::Merger.new "."
6
+ @merger.clean_dirs
7
+ @merger.process_files
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Codemerger
2
- VERSION = "0.2.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/codemerger.rb CHANGED
@@ -1,3 +1,2 @@
1
- module Codemerger
2
- # Your code goes here...
3
- end
1
+ require "codemerger/version"
2
+ require "codemerger/merger"
@@ -0,0 +1,45 @@
1
+ require_relative 'test_helper'
2
+ require "codemerger"
3
+ describe Codemerger::Merger do
4
+ def setup
5
+ @merger = Codemerger::Merger.new "test"
6
+ end
7
+ it "should return the correct language string" do
8
+ _(@merger.get_language_str(".yml")).must_equal "yaml"
9
+ _(@merger.get_language_str(".xml")).must_equal "xml"
10
+ _(@merger.get_language_str(".html")).must_equal "xml"
11
+ _(@merger.get_language_str(".rb")).must_equal "ruby"
12
+ _(@merger.get_language_str(".java")).must_equal "java"
13
+ _(@merger.get_language_str(".scala")).must_equal "scala"
14
+ _(@merger.get_language_str(".erb")).must_equal "erb"
15
+ _(@merger.get_language_str(".xsl")).must_equal "xslt"
16
+ _(@merger.get_language_str(".css")).must_equal "css"
17
+ _(@merger.get_language_str(".js")).must_equal "javascript"
18
+ _(@merger.get_language_str(".sh")).must_equal "bash"
19
+ _(@merger.get_language_str(".bat")).must_equal "batch"
20
+ _(@merger.get_language_str(".xhtml")).must_equal "xml"
21
+ _(@merger.get_language_str(nil)).must_equal "ruby"
22
+ _(@merger.get_language_str("niaaa")).must_equal "text"
23
+ _(@merger.get_language_str(".coffee")).must_equal "coffeescript"
24
+ _(@merger.get_language_str(".scss")).must_equal "scss"
25
+ end
26
+ it "should delete and re-create the output directory" do
27
+ FileUtils.mkdir_p "output"
28
+ out_f = File.new("output/temp.txt", "w")
29
+ out_f << "content"
30
+ out_f.close
31
+ @merger.clean_dirs
32
+ _(File.exist?("output/temp.txt")).must_equal false
33
+ end
34
+ it "should return the correctly formated output for an embedded file" do
35
+ expected = "\n <b>test/sample.rb</b>\n <pre line=\"1\" lang=\"ruby\">\n def sample\n println \"sample\"\nend\n\n </pre>\n "
36
+ actual = @merger.build_html_merged_file_content("test/sample.rb")
37
+ _(expected).must_equal actual
38
+ end
39
+ it "should process HTML and Markdown files" do
40
+ @merger.process_files
41
+ _(File.exist?("output/test/test.html")).must_equal true
42
+ _(File.exist?("output/test/test2.html")).must_equal true
43
+ puts File.new("output/test/test2.html").read
44
+ end
45
+ end
data/test/sample.rb ADDED
@@ -0,0 +1,3 @@
1
+ def sample
2
+ println "sample"
3
+ end
data/test/test.html ADDED
@@ -0,0 +1 @@
1
+ {{test/sample.rb}}
@@ -0,0 +1,11 @@
1
+ {{master:test/sample.rb}}
2
+
3
+ _ruby name_{:.code-title}
4
+
5
+ ~~~ ruby
6
+ def a(b)
7
+ puts b
8
+ end
9
+ ~~~
10
+
11
+ Bloco colorido?
@@ -0,0 +1,7 @@
1
+ require "simplecov"
2
+ require 'minitest/simplecov_plugin'
3
+ SimpleCov.start do
4
+ add_filter "/test/"
5
+ #track_files "lib/**/*.rb"
6
+ end
7
+ require "minitest/autorun"
@@ -0,0 +1,8 @@
1
+ require_relative 'test_helper'
2
+ require "codemerger/version"
3
+
4
+ describe Codemerger do
5
+ it "should return the correct version number" do
6
+ _("0.5.0").must_equal Codemerger::VERSION
7
+ end
8
+ end
metadata CHANGED
@@ -1,75 +1,193 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codemerger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease: !!null
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rodrigo Urubatan
9
- autorequire: !!null
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-02-20 00:00:00.000000000 -03:00
13
- default_executable: !!null
11
+ date: 2025-02-26 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
- name: maruku
17
- requirement: &19950852 !ruby/object:Gem::Requirement
18
- none: false
14
+ name: kramdown
15
+ requirement: !ruby/object:Gem::Requirement
19
16
  requirements:
20
- - - ! '>='
17
+ - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
- version_requirements: *19950852
26
- description: ! "This gem is used to help writing technical posts for wordpress.\n
27
- \ The output is copied and pasted to a post into my wordpress blog, and the code
28
- gets colored using the plugin wp-syntax, and the output can be turned into PDF with
29
- the plugin wp-mpdf.\n\nToday this gem supports source files in the following languages:\n\n*
30
- Ruby (including Rakefile and Gemfile)\n* Java\n* YAML\n* HTML\n* XML\n* Scala\n*
31
- CSS\n* Javascript\n* Bash\n* Batch\n\nAll other files are configured as \"text\"."
32
- email:
33
- - rodrigo@urubatan.com.br
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rouge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: |-
126
+ This gem is used to help writing technical posts for wordpress.
127
+ The output is copied and pasted to a post into my wordpress blog, and the code gets colored using the plugin wp-syntax, and the output can be turned into PDF with the plugin wp-mpdf.
128
+
129
+ Today this gem supports source files in the following languages:
130
+
131
+ * Ruby (including Rakefile and Gemfile)
132
+ * Java
133
+ * YAML
134
+ * HTML
135
+ * XML
136
+ * Scala
137
+ * CSS
138
+ * Javascript
139
+ * Bash
140
+ * Batch
141
+
142
+ All other files are configured as "text".
143
+ email: rodrigo@urubatan.com.br
34
144
  executables: []
35
145
  extensions: []
36
- extra_rdoc_files: []
146
+ extra_rdoc_files:
147
+ - LICENSE
148
+ - README.markdown
37
149
  files:
38
- - .Gemfile.swp
39
- - .codemerger.gemspec.swp
40
- - .gitignore
150
+ - ".ruby-version"
41
151
  - Gemfile
42
152
  - Gemfile.lock
153
+ - LICENSE
43
154
  - README.markdown
44
155
  - Rakefile
156
+ - VERSION
45
157
  - codemerger.gemspec
46
158
  - lib/codemerger.rb
159
+ - lib/codemerger/document_with_css.html.erb
160
+ - lib/codemerger/merger.rb
47
161
  - lib/codemerger/rake_tasks.rb
48
162
  - lib/codemerger/version.rb
49
- has_rdoc: true
163
+ - test/merger_spec.rb
164
+ - test/sample.rb
165
+ - test/test.html
166
+ - test/test2.markdown
167
+ - test/test_helper.rb
168
+ - test/version_spec.rb
50
169
  homepage: https://github.com/urubatan/codemerger
51
- licenses: []
52
- post_install_message: !!null
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
53
174
  rdoc_options: []
54
175
  require_paths:
55
176
  - lib
56
177
  required_ruby_version: !ruby/object:Gem::Requirement
57
- none: false
58
178
  requirements:
59
- - - ! '>='
179
+ - - ">="
60
180
  - !ruby/object:Gem::Version
61
181
  version: '0'
62
182
  required_rubygems_version: !ruby/object:Gem::Requirement
63
- none: false
64
183
  requirements:
65
- - - ! '>='
184
+ - - ">="
66
185
  - !ruby/object:Gem::Version
67
186
  version: '0'
68
187
  requirements: []
69
- rubyforge_project: codemerger
70
- rubygems_version: 1.5.0
71
- signing_key: !!null
72
- specification_version: 3
188
+ rubygems_version: 3.5.22
189
+ signing_key:
190
+ specification_version: 4
73
191
  summary: Used to create blog posts and tecnical articles that need code samples, the
74
192
  code samples will be taken from the actual source code file instead of a copy paste
75
193
  approach
data/.Gemfile.swp DELETED
Binary file
Binary file
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- pkg/*
2
- *.gem
3
- .bundle
4
- .redcar/*
5
- *.swo
6
- *.swp