Skip to content
This repository was archived by the owner on Jun 21, 2018. It is now read-only.

Comments

Add toc_pages plugin#691

Open
okkez wants to merge 28 commits intomasterfrom
toc-pages
Open

Add toc_pages plugin#691
okkez wants to merge 28 commits intomasterfrom
toc-pages

Conversation

@okkez
Copy link
Contributor

@okkez okkez commented Jan 12, 2017

This is a daimon_markdown plugin.

@mtsmfm mtsmfm temporarily deployed to daimon-news-stg-pr-691 January 12, 2017 05:16 Inactive
@okkez okkez changed the title Add toc_pages plugin [WIP] Add toc_pages plugin Jan 12, 2017
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 January 17, 2017 04:46 Inactive
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 January 17, 2017 04:46 Inactive
@okkez okkez added the review label Jan 17, 2017
@okkez okkez changed the title [WIP] Add toc_pages plugin Add toc_pages plugin Jan 17, 2017
@okkez okkez removed the in progress label Jan 17, 2017
Copy link
Contributor

@mtsmfm mtsmfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
But TableOfContentsPages#call method is difficult and complex for me 😢


request = context[:request]

current_page = if request.params.key?(:page)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about passing context expressly (:page, :public_id etc) instead of :request?
It is difficult for me to find what params this plugin needs 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to use full functionalities of request in this plugin.
But in fact, this plugin uses some functionalities of request.

@okkez okkez temporarily deployed to daimon-news-stg-pr-691 January 26, 2017 07:40 Inactive
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 January 26, 2017 08:16 Inactive
@okkez
Copy link
Contributor Author

okkez commented Jan 26, 2017

I've fixed and pushed changes.
@mtsmfm Could you check this PR again?


@context = {
full_text: @post.body,
fullpath: request.fullpath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I want to have uniform name
(fulltext and fullpath) or (full_text and full_path)
but fulltextdoesn't make sence...

@post.pages.page(params[:page]).per(1)
end

@context = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about markdown_context ?
markdown_context is straightforward I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@context ->
@markdown_context

It's straightforward.
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 January 31, 2017 08:21 Inactive
Because `full_text` and `fullpath` don't have same form.
It's very confusing us.
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 January 31, 2017 08:37 Inactive
@mtsmfm mtsmfm temporarily deployed to daimon-news-stg-pr-691 February 23, 2017 01:14 Inactive
end
end

sub_test_case "toc" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Metrics/BlockLength: Block has too many lines. [114/25]

data("page1" => [1, 0, ["title"]],
"page2" => [2, 1, ["title-2"]],
"page3" => [3, 2, ["title-3", "title-3-1", "title-3-2"]])
test "multiple pages with complex source" do |(page, index, expected_header_ids)|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Metrics/BlockLength: Block has too many lines. [36/25]

page_separated_nodes = []
condition = 1.upto(6).map {|n| "./following::h#{n}" }.join("|")
html.search("//comment()[contains(.,\"nextpage\")]").map do |comment_element|
page_separated_nodes << comment_element.search(condition).first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

page_separated_nodes = html.search("//comment()[contains(.,\"nextpage\")]").map do |comment_element|
  comment_element.search(condition).first
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Good catch!

end
headers[id] += 1
header_content = header_node.children.first
# TODO: Arrange indent level
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for generated html indentation.
It is not important.

`#at` returns first element which is matched condition.
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 23, 2017 03:11 Inactive
headers_per_page = Hash.new {|h, k| h[k] = [] }
ul_list = Hash.new {|h, k| h[k] = UnorderedList.new }
ul_list[1] = UnorderedList.new(html_class: toc_class)
# rubocop:disable Metrics/BlockLength

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Lint/UnneededDisable: Unnecessary disabling of Metrics/BlockLength.


def to_html
if @items.empty?
%Q(<li>#{@header.link}</li>)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Style/UnneededPercentQ: Use %Q only for strings that contain both single quotes and double quotes, or for dynamic strings that contain double quotes. :ref

@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 23, 2017 09:54 Inactive
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 23, 2017 09:56 Inactive
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 24, 2017 01:30 Inactive
ul must not be child of ul directry.
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 24, 2017 06:17 Inactive
(previous_level + 1).upto(header.level) do |level|
ul_list[level - 1] << ul_list[level]
end
else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Style/EmptyElse: Redundant else-clause.

@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 24, 2017 06:21 Inactive
@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 24, 2017 06:26 Inactive
@mtsmfm mtsmfm temporarily deployed to daimon-news-stg-pr-691 February 24, 2017 06:32 Inactive
@mtsmfm
Copy link
Contributor

mtsmfm commented Feb 28, 2017

I got 500 error when I previewed a post has following body:

{{toc_pages}}

# Hello
hi !

<!--nextpage -->

## h2

a

### h3

b

@okkez
Copy link
Contributor Author

okkez commented Feb 28, 2017

ActionView::Template::Error (undefined method `[]' for nil:NilClass):
  24:           = render 'posts/credits', credits: @post.credits.with_ordered
  25:       %p.thumbnail= image_tag @post.thumbnail_url
  26:     .post__body
  27:       = render_markdown(@pages.map(&:body).join, @markdown_context)
  28: 
  29:     - if @pages.total_pages > 1
  30:       %nav.pagination
lib/daimon_markdown/plugins/toc_pages.rb:57:in `block in call'
lib/daimon_markdown/plugins/toc_pages.rb:56:in `call'
lib/daimon_markdown/plugins/toc_pages.rb:56:in `zip'
app/helpers/markdown_helper.rb:4:in `render_markdown'
app/views/posts/show.html.haml:27:in `block in _app_views_posts_show_html_haml___3001049241409430540_70268641750820'
app/views/posts/show.html.haml:13:in `_app_views_posts_show_html_haml___3001049241409430540_70268641750820'
config/environments/production.rb:100:in `call'
app/controllers/editor/posts_controller.rb:66:in `preview'
app/middlewares/redirector.rb:25:in `response'
config/application.rb:44:in `call'
app/middlewares/redirector.rb:7:in `call'

@okkez okkez temporarily deployed to daimon-news-stg-pr-691 February 28, 2017 03:33 Inactive
@okkez-bot
Copy link

Click here if you want to create rubocop's auto-correct Pull Request
Auto Correct by SideCI

See the documentation if you want to get more information about auto-correct.
Document


test "extra white spaces in page separator" do
# in this case page separator doesn't work
body =<<~BODY

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rubocop]

  • Style/SpaceAroundOperators: Surrounding space missing for operator =. :ref

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants