rrjj 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +84 -0
- data/Rakefile +14 -0
- data/config/rrjj.rb +35 -0
- data/lib/guard_helpers/file_helper.rb +35 -0
- data/lib/guard_helpers/opal_helper.rb +27 -0
- data/lib/guard_helpers/rails_helper.rb +33 -0
- data/lib/guard_helpers/rrjj_helper.rb +45 -0
- data/lib/guard_helpers/srt_helper.rb +96 -0
- data/lib/rails_handlers/ctrl_handler.rb +7 -0
- data/lib/ro_commands/check.rb +16 -0
- data/lib/ro_commands/model.rb +24 -0
- data/lib/ro_commands/post_handler.rb +85 -0
- data/lib/ro_commands/rails_base.rb +27 -0
- data/lib/ro_commands/rails_shortcuts.rb +18 -0
- data/lib/ro_commands/ro_proc.rb +8 -0
- data/lib/ro_core_ext/object.rb +11 -0
- data/lib/ro_html_handler.rb +8 -0
- data/lib/rrjj.rb +18 -0
- data/lib/rrjj/cmd.rb +7 -0
- data/lib/rrjj/cmds.rb +42 -0
- data/lib/rrjj/railtie.rb +13 -0
- data/lib/rrjj/ro_faker.rb +10 -0
- data/lib/rrjj/version.rb +3 -0
- data/lib/rrjj_ro_commands_bin.rb +4 -0
- data/lib/rubymine_heaven.rb +2 -0
- data/lib/rubymine_heaven/linkable_errors.rb +56 -0
- data/lib/rubymine_heaven/linkable_errors_handler.rb +31 -0
- data/lib/rubymine_heaven/linkable_errors_railtie.rb +21 -0
- data/lib/subtitle.rb +149 -0
- data/lib/subtitles/ex.srt +5 -0
- data/lib/templates/alias.erb +3 -0
- data/lib/templates/srt.erb +4 -0
- data/spec/controllers/app_controller_spec.rb +12 -0
- data/spec/decorators/app_decorator_spec.rb +4 -0
- data/spec/decorators/post_decorator_spec.rb +38 -0
- data/spec/features/posts/index_spec.rb +9 -0
- data/spec/features/posts/search_spec.rb +10 -0
- data/spec/fixtures/handler/error_page.html +1 -0
- data/spec/fixtures/handler/result.html +1 -0
- data/spec/fixtures/post_handler/posts/error/test.md +1 -0
- data/spec/fixtures/post_handler/posts/rails/test.html +0 -0
- data/spec/fixtures/post_handler/tmp/rspec_guard_result +1 -0
- data/spec/fixtures/rails_navigate/app/controllers/app_controller.rb +0 -0
- data/spec/fixtures/rails_navigate/app/controllers/one_controller.rb +0 -0
- data/spec/fixtures/rails_navigate/app/controllers/two_controller.rb +0 -0
- data/spec/fixtures/rails_navigate/app/decorators/two_decorator.rb +0 -0
- data/spec/fixtures/rails_navigate/app/models/two_model.rb +0 -0
- data/spec/fixtures/rails_navigate/opal_lib/path/to/file.rb +0 -0
- data/spec/fixtures/rails_navigate/opal_lib/path/to/file2.rb +0 -0
- data/spec/fixtures/try/origin/ex.erb.ogv +0 -0
- data/spec/helpers/app_helper_spec.rb +15 -0
- data/spec/helpers/posts_helper_spec.rb +15 -0
- data/spec/lib/guard_helpers/rails_helper_spec.rb +1 -0
- data/spec/lib/guard_helpers/ro_helper_spec.rb +23 -0
- data/spec/lib/guard_helpers/srt_helper_spec.rb +18 -0
- data/spec/lib/ro_cells/opal_spec.rb +40 -0
- data/spec/lib/ro_commands/check_spec.rb +21 -0
- data/spec/lib/ro_commands/post_handler_spec.rb +0 -0
- data/spec/lib/ro_commands/rails_navigate_spec.rb +47 -0
- data/spec/lib/rubymine_heaven/linkable_errors_railtie_spec.rb +2 -0
- data/spec/lib/srt_helper_spec.rb +5 -0
- data/spec/lib/subtitle_spec.rb +46 -0
- data/spec/lib/templates/srt_spec.rb +2 -0
- data/spec/lib/video_spec.rb +34 -0
- data/spec/models/ln_spec.rb +5 -0
- data/spec/models/post_spec.rb +8 -0
- data/spec/models/sub_spec.rb +5 -0
- data/spec/models/tag_spec.rb +5 -0
- data/spec/models/try_spec.rb +5 -0
- data/spec/requests/posts_spec.rb +11 -0
- data/spec/routing/posts_routing_spec.rb +35 -0
- data/spec/spec_helper.rb +79 -0
- data/spec/views/app/search.html.erb_spec.rb +5 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3298f0e49f86c928bc5fc7624bbe631863b8c8d7
|
4
|
+
data.tar.gz: 9152787ea1471ba5d145b54e169c340dc61c9de8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c49c06c5c88a1152228bc8f864e4421e41ad9a2d4e1aa9d71249b0f60cc76d7f8d153cd9e136f5762ab67efdaabc0f28490ca1f2f04e6ab578bc46d558c766c3
|
7
|
+
data.tar.gz: d0edcb1d3743167cd615c37ee533bbb40f5fd227083d3804eef52100375fa60ff126a2399671ea032858e55455da7a8d695f599d17ab38ae5eeb8b8f76f52d2d
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# RoadMap
|
2
|
+
|
3
|
+
## ro_commands
|
4
|
+
<del>- make zeus can run in submodule</del>
|
5
|
+
<del>- parallel test to speed up rspec</del>
|
6
|
+
<del>- ro_generators to add a rails scaffold generator</del>
|
7
|
+
<del>- rails new app which include article scaffold and post scaffold</del>
|
8
|
+
|
9
|
+
## My Blog
|
10
|
+
### Finish My Resume
|
11
|
+
- <del> add ro_debug generator</del>
|
12
|
+
- <del> fix rubymine_heaven bug</del>
|
13
|
+
- <del> finish rerecord a part of screencast for ro_commands</del>
|
14
|
+
<del>- shortcuts</del>
|
15
|
+
<del>- generate</del>
|
16
|
+
<del>- guard_helpers</del>
|
17
|
+
|
18
|
+
- <del> fix a ::RoCommands::Rails bug</del>
|
19
|
+
- <del> add bash alias</del>
|
20
|
+
- <del> add guard alias</del>
|
21
|
+
- <del> add decorator, controller, model, lib navigators and show spec file on right split at the same time</del>
|
22
|
+
- <del> fix rspec error</del>
|
23
|
+
- <del> support markdown file</del>
|
24
|
+
- <del> save markdown content to db</del>
|
25
|
+
- <del> show markdown content</del>
|
26
|
+
- <del> add navbar</del>
|
27
|
+
- <del> convert evernote note to my blog</del>
|
28
|
+
- <del> add PostDecorator spec to test abstract method is usable for all records</del>
|
29
|
+
- <del> read celluloid wiki</del>
|
30
|
+
- <del> optimize post_handler with celluloid</del>
|
31
|
+
- <del> use celluloid supervise restart opal</del>
|
32
|
+
- <del> opal do a google search</del>
|
33
|
+
- <del> capybara write a google search spec</del>
|
34
|
+
- <del> load all posts in posts dir as rspec test data</del>
|
35
|
+
- <del> add kill rails server cmd</del>
|
36
|
+
- <del> add compass stylesheets path to application.rb</del>
|
37
|
+
- <del> finish post index</del>
|
38
|
+
|
39
|
+
### deploy
|
40
|
+
- make a rrjj gem include some ro_commands(make ro rails_shortcuts can show a helper in ro_deploy project)
|
41
|
+
- make a guard upload
|
42
|
+
- use capystrano deploy my app
|
43
|
+
|
44
|
+
### after deploy
|
45
|
+
- add sub domain http://note.yikajiang.com
|
46
|
+
- add google rank
|
47
|
+
- try add google ad
|
48
|
+
|
49
|
+
### finish basic component
|
50
|
+
- add paginate
|
51
|
+
- finish post content css
|
52
|
+
- add all my evernote notes
|
53
|
+
- add markdown.css/js
|
54
|
+
- a simple resume
|
55
|
+
|
56
|
+
### use devise
|
57
|
+
- add root user(me)
|
58
|
+
- root user can delete post
|
59
|
+
|
60
|
+
### sunspot search(title and tags)
|
61
|
+
- create a new tag model, and a post has many tags
|
62
|
+
|
63
|
+
|
64
|
+
### upload tool
|
65
|
+
- add guard helper which can auto upload post in Dir.pwd posts
|
66
|
+
- add google rank
|
67
|
+
|
68
|
+
## make a google seo
|
69
|
+
|
70
|
+
### finish ro_commands readme(publish at my blog)
|
71
|
+
- record a video
|
72
|
+
|
73
|
+
|
74
|
+
## evernote like app in local
|
75
|
+
- create a crawler like httrack with capybara(deprecated)
|
76
|
+
- a chrome extension post a request to app(deprecated
|
77
|
+
|
78
|
+
## evernote app extension
|
79
|
+
- ro_crawler to handle exist evernote notes export file(html)
|
80
|
+
- learn how to upload a note to evernote(maybe have exist gem)
|
81
|
+
- upload this note to my blog at the same time
|
82
|
+
|
83
|
+
## sunspot + mysql/mongoid search engine standalone with my blog
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Add your own tasks in files placed in opal_lib/tasks ending in .rake,
|
2
|
+
# for example opal_lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
|
6
|
+
Rorojiangjiang::Application.load_tasks
|
7
|
+
|
8
|
+
require 'fileutils'
|
9
|
+
task :remove_zeus_sock do
|
10
|
+
FileUtils.rmtree(File.join(::Rails.root, '.zeus.sock'))
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'bundler/setup'
|
14
|
+
Bundler::GemHelper.install_tasks
|
data/config/rrjj.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'deps_methods'
|
2
|
+
module Rrjj
|
3
|
+
include DepsMethods
|
4
|
+
class << self
|
5
|
+
attr_accessor :project_lib
|
6
|
+
|
7
|
+
def project_lib
|
8
|
+
@project_lib ||= lib
|
9
|
+
end
|
10
|
+
|
11
|
+
def root
|
12
|
+
File.expand_path("../..", __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def home
|
16
|
+
ENV['HOME']
|
17
|
+
end
|
18
|
+
|
19
|
+
def lib
|
20
|
+
File.join(root, 'lib')
|
21
|
+
end
|
22
|
+
|
23
|
+
def spec
|
24
|
+
File.join(root, 'spec')
|
25
|
+
end
|
26
|
+
|
27
|
+
def fix
|
28
|
+
File.join(spec, 'fixtures')
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_editor
|
32
|
+
"rubymine"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "guard_helpers/base_helper"
|
2
|
+
require "ro_core_ext/string"
|
3
|
+
|
4
|
+
module ::GuardHelpers
|
5
|
+
module FileHelper
|
6
|
+
include ::GuardHelpers::BaseHelper
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def select_file(video)
|
11
|
+
Find.find("origin") do |p|
|
12
|
+
if test(?f, p)
|
13
|
+
|
14
|
+
basename = File.basename(p).gsub(%r{\.\w+$}, "")
|
15
|
+
if basename.match(%r{#{video.implicit}})
|
16
|
+
return p
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle_file(dir, video, cmd)
|
23
|
+
::Find.find(dir) do |p|
|
24
|
+
if test(?f, p)
|
25
|
+
basename = File.basename(p).gsub(%r{\.\w+$}, "")
|
26
|
+
if basename.match(%r{#{video.implicit}})
|
27
|
+
bash "#{cmd} #{p}"
|
28
|
+
return
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'guard_helpers/base_helper'
|
2
|
+
require 'rrjj'
|
3
|
+
|
4
|
+
module ::GuardHelpers
|
5
|
+
module OpalHelper
|
6
|
+
include BaseHelper
|
7
|
+
|
8
|
+
def start
|
9
|
+
super if defined? super
|
10
|
+
cmds = ::Pry::CommandSet.new do
|
11
|
+
end
|
12
|
+
::Pry::Commands.import cmds
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_on_modifications(paths)
|
16
|
+
super if defined? super
|
17
|
+
#handle_all_paths(%r{^app/assets/javascripts/(.+)\.rb$}) do
|
18
|
+
# path_basenames = paths.map do |path|
|
19
|
+
# File.basename(path)
|
20
|
+
# end
|
21
|
+
# notify "Handling opal files #{path_basenames}"
|
22
|
+
# ::RoCells::Opal.new.handle
|
23
|
+
#end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'guard_helpers/base_helper'
|
2
|
+
|
3
|
+
module ::GuardHelpers
|
4
|
+
module RailsHelper
|
5
|
+
include BaseHelper
|
6
|
+
|
7
|
+
def start
|
8
|
+
super if defined? super
|
9
|
+
cmds = ::Pry::CommandSet.new do
|
10
|
+
block_command "cn", "model columns name" do |model|
|
11
|
+
m = Object.const_get(model.camelize.to_sym)
|
12
|
+
column_name = m.columns.map(&:name)
|
13
|
+
Out.raw_out column_name
|
14
|
+
Out.out "file:#{File.basename __FILE__} line:#{__LINE__}", "red"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
::Pry::Commands.import cmds
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_on_modifications(paths)
|
22
|
+
super if defined? super
|
23
|
+
|
24
|
+
handle_each_path(%r{^db/schema\.rb$}) do |path|
|
25
|
+
guard_reset
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "guard_helpers/base_helper"
|
2
|
+
require 'rrjj/cmds'
|
3
|
+
|
4
|
+
module ::GuardHelpers
|
5
|
+
module RrjjHelper
|
6
|
+
include ::GuardHelpers::BaseHelper
|
7
|
+
|
8
|
+
def start
|
9
|
+
super if defined? super
|
10
|
+
|
11
|
+
cmds_all = ::Rrjj::Cmds.all.dup
|
12
|
+
cmds = ::Pry::CommandSet.new do
|
13
|
+
cmds_all.each do |cmd|
|
14
|
+
block_command cmd.shortcut, cmd.cmd do |*args|
|
15
|
+
::Kernel.system "#{cmd.cmd} #{args.join(" ")}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
::Pry::Commands.import cmds
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_on_modifications(paths)
|
24
|
+
super if defined? super
|
25
|
+
handle_each_path(%r{^lib/(.+)\.rb}) do |path|
|
26
|
+
install
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
def install
|
32
|
+
bx 'rake install'
|
33
|
+
end
|
34
|
+
|
35
|
+
def zro(bash)
|
36
|
+
system "zeus ro #{bash}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def write2rrjjsh
|
40
|
+
load 'rrjj/cmds.rb'
|
41
|
+
zro "rails_bashs write2rrjjsh"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'guard_helpers/base_helper'
|
2
|
+
require "subtitle"
|
3
|
+
require "ro_default"
|
4
|
+
|
5
|
+
Out.out "file:#{::File.basename __FILE__} line:#{__LINE__}", "green"
|
6
|
+
|
7
|
+
module ::GuardHelpers
|
8
|
+
module SrtHelper
|
9
|
+
include BaseHelper
|
10
|
+
|
11
|
+
def start
|
12
|
+
super if defined? super
|
13
|
+
create_open_file("subtitle_template", "erb")
|
14
|
+
|
15
|
+
cmds = ::Pry::CommandSet.new do
|
16
|
+
block_command "bs", "build subtitle template in subtitle_template" do |*args|
|
17
|
+
build_all_subtt
|
18
|
+
end
|
19
|
+
|
20
|
+
block_command "clearall", "clear all records" do |*args|
|
21
|
+
Sub.delete_all
|
22
|
+
Ln.delete_all
|
23
|
+
end
|
24
|
+
end
|
25
|
+
::Pry::Commands.import cmds
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_on_modifications(paths)
|
29
|
+
super if defined? super
|
30
|
+
|
31
|
+
handle_each_path(%r{^subtitle_template/(.+)\.erb$}) do
|
32
|
+
build_all_subtt
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
def build_all_subtt
|
39
|
+
Sub.delete_all
|
40
|
+
Ln.delete_all
|
41
|
+
::Find.find("subtitle_template") do |p|
|
42
|
+
if test(?f, p)
|
43
|
+
handle_subtitle_template(p)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def handle_subtitle_template(path)
|
49
|
+
basename = File.basename(path).gsub(%r{\.\w+$}, "")
|
50
|
+
sub = Sub.create name: basename
|
51
|
+
ls = File.readlines(path).delete_if do |e|
|
52
|
+
e.blank?
|
53
|
+
end
|
54
|
+
|
55
|
+
ls.each_with_index do |l, i|
|
56
|
+
start_time, end_time, content = handle_line(l)
|
57
|
+
sub.lns.create(no: i, start_time: start_time, end_time: end_time, content: content)
|
58
|
+
end
|
59
|
+
|
60
|
+
Sub.all.each do |sub|
|
61
|
+
if sub
|
62
|
+
@sub = sub
|
63
|
+
filename = "lib/subtitles/#{sub.name}.srt"
|
64
|
+
file = File.new(filename, "w+")
|
65
|
+
subtt "srt", sub.name
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def subtt(template, file)
|
71
|
+
if $lib
|
72
|
+
template_path = File.join($lib, "templates", template) + ".erb"
|
73
|
+
file_path = File.join($lib, "subtitles", file) + ".srt"
|
74
|
+
ctn = RoFile.read(template_path)
|
75
|
+
result = ERB.new(ctn).result(binding)
|
76
|
+
RoFile.write(file_path, result)
|
77
|
+
format_subtitle_file(file_path)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def format_subtitle_file(file_path)
|
82
|
+
ctn = RoFile.readlines(file_path).map do |line|
|
83
|
+
line.gsub(%r{^\s+}, "")
|
84
|
+
end.join("\n")
|
85
|
+
::RoFile.write(file_path, ctn)
|
86
|
+
end
|
87
|
+
|
88
|
+
def handle_line(l)
|
89
|
+
Out.out "l:#{l} file:#{File.basename __FILE__} line:#{__LINE__}", "red" if $RODEBUG
|
90
|
+
r = l.match(%r{(?<time>\d{2,6})(?<content>.*)})
|
91
|
+
Out.out "r:#{r} file:#{File.basename __FILE__} line:#{__LINE__}", "red" if $RODEBUG
|
92
|
+
return [Subtitle.handle_time(r[:time]), Subtitle.handle_content(r[:content])].flatten
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RoCommands
|
2
|
+
class Check < Base
|
3
|
+
desc usage("see_schema"), ""
|
4
|
+
|
5
|
+
def schema(*args)
|
6
|
+
bash "cat db/schema.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
desc usage("post"), ""
|
10
|
+
|
11
|
+
def table(*args)
|
12
|
+
table_name = args.first.camelize
|
13
|
+
Out.out(Object.const_get(:"#{table_name}").all)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'rails_base'
|
2
|
+
module ::RoCommands
|
3
|
+
class Model < RailsBase
|
4
|
+
desc usage('delete_all'), ''
|
5
|
+
|
6
|
+
def delete_all(mod)
|
7
|
+
model(mod).delete_all
|
8
|
+
end
|
9
|
+
|
10
|
+
desc usage("check"), ""
|
11
|
+
|
12
|
+
def check(mod)
|
13
|
+
model(mod).all.each do |record|
|
14
|
+
Out.out(record.inspect)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def model(mod)
|
21
|
+
Object.const_get(:"#{mod.camelize}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative 'rails_base'
|
2
|
+
require 'github/markup'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'ro_html_handler'
|
5
|
+
|
6
|
+
module RoCommands
|
7
|
+
|
8
|
+
class PostCell
|
9
|
+
include Celluloid
|
10
|
+
|
11
|
+
def handle_single(p)
|
12
|
+
tag_name = File.dirname(p)
|
13
|
+
title, content = if p.match(%r{\.md$})
|
14
|
+
handle_markdown(p)
|
15
|
+
elsif p.match(%r{(.+)\.html$})
|
16
|
+
handle_html(p)
|
17
|
+
end
|
18
|
+
return {title: title, content: content}
|
19
|
+
#post.tags.create name: tag_name
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def handle_markdown(p)
|
24
|
+
title = File.basename(p).gsub(%r{\.\w+$}, "")
|
25
|
+
content = GitHub::Markup::Markdown.new.render(RoFile.read(p))
|
26
|
+
return title, content
|
27
|
+
end
|
28
|
+
|
29
|
+
def handle_html(p)
|
30
|
+
origin = RoFile.read(p)
|
31
|
+
title = get_title(origin)
|
32
|
+
content = get_smth_in_html(origin, 'inner_html')
|
33
|
+
return title, content
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_title(html)
|
37
|
+
doc(html) do |d|
|
38
|
+
d.css('title').text
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_smth_in_html(html, smth)
|
43
|
+
doc(html) do |d|
|
44
|
+
d.css("body").send(:"#{smth}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
include RoHtmlHandler
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
class PostHandler < RailsBase
|
56
|
+
desc usage("handle"), ""
|
57
|
+
|
58
|
+
def handle
|
59
|
+
path = File.join(::Rails.root, 'posts')
|
60
|
+
futures = []
|
61
|
+
::Find.find(path) do |p|
|
62
|
+
if test(?f, p) and p.match(%r{(.+)\.(html|md)})
|
63
|
+
futures << PostCell.new.future.handle_single(p)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
futures.map(&:value).each do |record|
|
68
|
+
post_create(record)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def post_create(attrs={})
|
74
|
+
if attrs[:title]
|
75
|
+
Out.table("creating a record", attrs[:title], "file:#{File.basename __FILE__} line:#{__LINE__}")
|
76
|
+
|
77
|
+
post = Post.find_or_initialize_by(title: attrs[:title])
|
78
|
+
post.update(attrs)
|
79
|
+
post
|
80
|
+
else
|
81
|
+
raise "create a post must be has a title"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|