ever_mid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0d3242883db22aa9c82e4195f7b432cc52e8dbe5
4
+ data.tar.gz: 1f7c0a1b8bade8b32d08845d3f12b9b39803a308
5
+ SHA512:
6
+ metadata.gz: 77c9eb08bbbff29656367cc89dd906c6267eb00d66940ce60d6c509689549eff61a1f546cdb3abfaddbdadeef8d6e2ee748b55ab939bc43776bbed4ae2cb16fa
7
+ data.tar.gz: 5ca72f397fe02a2c0b94513f15f19718090a16594be77cf056c4354df2fe90a9f2b4f9bb9135472186b4c8c79283461e41e3f74e195a38591101530b9160b1b1
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
6
+
7
+ *.swp
8
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # If you do not have OpenSSL installed, update
2
+ # the following line to use "http://" instead
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in ever_mid.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem 'rake'
10
+ gem 'rdoc'
11
+ gem 'yard'
12
+ end
13
+
14
+ group :test do
15
+ gem 'cucumber'
16
+ gem 'aruba'
17
+ gem 'rspec'
18
+ end
19
+
20
+ gem 'ever_exp', '= 0.1.0'
21
+ gem 'toc_list', '= 0.1.1'
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = '--color --tags ~@wip --strict'
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task test: ['cucumber']
13
+
14
+ task default: :test
data/ever_mid.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "ever_mid"
6
+ s.version = "0.0.1"
7
+ s.platform = Gem::Platform::RUBY
8
+
9
+ s.authors = ["ken"]
10
+ s.email = ["block24block@gmail.com"]
11
+ s.homepage = "https://github.com/turnon/ever_mid"
12
+ s.summary = 'preprocess evernote-exported htmls, make them recognized by middleman builder'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # The version of middleman-core your extension depends on
20
+ s.add_runtime_dependency("middleman-core", [">= 4.1.10"])
21
+
22
+ # Additional dependencies
23
+ s.add_runtime_dependency("ever_exp", "0.1.0")
24
+ s.add_runtime_dependency("toc_list", "0.1.1")
25
+ end
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require 'middleman-core'
3
+ require 'middleman-core/step_definitions'
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'ever_mid')
@@ -0,0 +1,107 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+ require 'digest/sha1'
4
+ require 'toc_list'
5
+
6
+ module EverExp
7
+ class Note
8
+ def to_midsrc src_path
9
+ files.to_midsrc src_path
10
+ html.to_midsrc src_path
11
+ end
12
+
13
+ def id
14
+ html.id
15
+ end
16
+
17
+ def date
18
+ html.formated_date
19
+ end
20
+ end
21
+
22
+ class Files
23
+ def to_midsrc src_path
24
+ new_location = new_dir src_path
25
+ FileUtils.mkdir new_location
26
+ each do |file|
27
+ FileUtils.cp file.location, new_location
28
+ end
29
+ end
30
+
31
+ def id
32
+ note.id
33
+ end
34
+
35
+ def new_dir src_path
36
+ File.join src_path, EverMid::ImagesDir, id
37
+ end
38
+ end
39
+
40
+ class WithoutFiles
41
+ def to_midsrc src_path
42
+ end
43
+ end
44
+
45
+ class Html
46
+ def to_midsrc src_path
47
+ refresh_imgs
48
+ replace_code_blocks
49
+ set_toc_ref
50
+ File.open(new_location(src_path), 'w') do |file|
51
+ file.puts src_content
52
+ end
53
+ end
54
+
55
+ def id
56
+ @id ||= Digest::SHA1.hexdigest(title)[0..5]
57
+ end
58
+
59
+ def formated_date
60
+ created.strftime '%d %b %Y'
61
+ end
62
+
63
+ private
64
+
65
+ def page_var
66
+ {'title' => title, 'date' => formated_date, 'heading' => heading}.to_yaml
67
+ end
68
+
69
+ def new_location src_path
70
+ File.join src_path, EverMid::ArchiveDir, new_file_name
71
+ end
72
+
73
+ def new_file_name
74
+ id + '.html.erb'
75
+ end
76
+
77
+ def src_content
78
+ [page_var, "---\n", content].join
79
+ end
80
+
81
+ def refresh_imgs
82
+ imgs.each do |img|
83
+ org_src_path = img['src']
84
+ new_src_path = File.join('/' + EverMid::ImagesDir, id, File.basename(org_src_path))
85
+ img['src'] = new_src_path
86
+ end
87
+ end
88
+
89
+ def replace_code_blocks
90
+ code_blocks.each do |org_block|
91
+ new_block = [
92
+ '<div class="ever-code"><pre><code>',
93
+ org_block.plain_code,
94
+ '</code></pre></div>'
95
+ ].join
96
+ org_block.add_next_sibling new_block
97
+ org_block.remove
98
+ end
99
+ end
100
+
101
+ def set_toc_ref
102
+ heading_elements.each do |e|
103
+ e['id'] = TocList::HashMethod.call e.text
104
+ end
105
+ end
106
+ end
107
+ end
data/lib/ever_mid.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'pathname'
2
+ require "middleman-core"
3
+ require 'ever_mid/ever_exp'
4
+ require 'fileutils'
5
+ require 'toc_list'
6
+
7
+ class EverMid < ::Middleman::Extension
8
+ option :my_option, 'default', 'An example option'
9
+
10
+ ArchiveDir = 'archive'
11
+ ImagesDir = 'images'
12
+
13
+ def initialize(app, options_hash={}, &block)
14
+ super
15
+ end
16
+
17
+ def before_build
18
+ rebuild_dir
19
+ move_notes
20
+ aggregate
21
+ end
22
+
23
+ helpers do
24
+ def table_of_content
25
+ TocList.new({'table of content' => current_page.data.heading}).render
26
+ end
27
+
28
+ def table_of_content?
29
+ heading = current_page.data.heading
30
+ heading and not heading.empty?
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def rebuild_dir
37
+ [ArchiveDir, ImagesDir].each do |dir|
38
+ full_path = File.join source_path, dir
39
+ FileUtils.rm_rf full_path
40
+ FileUtils.mkdir full_path
41
+ end
42
+ end
43
+
44
+ def move_notes
45
+ notes.each do |note|
46
+ note.to_midsrc source_path
47
+ end
48
+ end
49
+
50
+ def aggregate
51
+ build_file_with_template '_tags.erb', :tags
52
+ build_file_with_template 'index.html.erb', :index
53
+ end
54
+
55
+ def build_file_with_template output_file, tmpl_file
56
+ rendered = ERB.new(template tmpl_file).result(binding)
57
+ File.open(under_source(output_file), 'w') do |file|
58
+ file.puts rendered
59
+ end
60
+ end
61
+
62
+ def notes
63
+ @notes ||= EverExp::Notes.new evernotes_path
64
+ end
65
+
66
+ def evernotes_path
67
+ under_root 'evernotes'
68
+ end
69
+
70
+ def source_path
71
+ under_root 'source'
72
+ end
73
+
74
+ def under_root dir_name
75
+ File.join app.root_path, dir_name
76
+ end
77
+
78
+ def under_source filename
79
+ File.join source_path, filename
80
+ end
81
+
82
+ def template name
83
+ tmpl_path = File.join(app.root_path, 'source', 'layouts', 'templates', name.to_s) + '.erb'
84
+ File.read tmpl_path
85
+ end
86
+ end
87
+
88
+
89
+ Middleman::Extensions.register :ever_mid, EverMid
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ever_mid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: ever_exp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.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.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: toc_list
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
55
+ description:
56
+ email:
57
+ - block24block@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Rakefile
65
+ - ever_mid.gemspec
66
+ - features/support/env.rb
67
+ - lib/ever_mid.rb
68
+ - lib/ever_mid/ever_exp.rb
69
+ homepage: https://github.com/turnon/ever_mid
70
+ licenses: []
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.8
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: preprocess evernote-exported htmls, make them recognized by middleman builder
92
+ test_files:
93
+ - features/support/env.rb