-
Couldn't load subscription status.
- Fork 152
GitHub edit link tag #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitHub edit link tag #108
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet! Just a handful of comments here. 😄
| # Returns a symbol representing the instance method | ||
| def self.def_hash_delegator(hash_method, key, method, default = nil) | ||
| define_method(method) do | ||
| hash = send(hash_method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use public_send here instead of send?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we did, we'd have to make site, site_github, source, and page public.
| end | ||
|
|
||
| def remove_leading_slash(part) | ||
| part.sub(%r!\A/!, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about part.start_with?("/") ? part[1..-1] : part?
>> path = "/lol"
=> "/lol"
>> Benchmark.ips do |x|
?> x.report ("sub") { path.sub(%r!\A/!, "") }
>> x.report ("[1..-1]") { path.start_with?("/") ? path[1..-1] : path }
>> x.compare!
>> end
Warming up --------------------------------------
sub 134.174k i/100ms
[1..-1] 185.434k i/100ms
Calculating -------------------------------------
sub 1.995M (± 5.5%) i/s - 10.063M in 5.058157s
[1..-1] 3.626M (± 6.7%) i/s - 18.173M in 5.035788s
Comparison:
[1..-1]: 3626032.7 i/s
sub: 1995248.9 i/s - 1.82x slower
| def parts_normalized | ||
| @parts_normalized ||= parts.map.with_index do |part, index| | ||
| part = remove_leading_slash(part.to_s) | ||
| part = ensure_trailing_slash(part) unless index == parts.length - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this unless mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the url is https://github.com/foo/bar/edit/master/page.md, we don't want the last element page.md to be given a trailing slash (and can't rely on the extension, because the repo might be, foo.js).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you leave a comment in the code to that effect or give it a tiny helper method which explains that?
| end | ||
|
|
||
| def link | ||
| "<a href=\"#{uri.normalize}\">#{link_text}</a>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You call uri.normalize but you return a "" in an error state. I don't see a String#normalize, so normalize will have to be called in uri instead of here.
docs/README.md
Outdated
|
|
||
| ## What it does | ||
|
|
||
| * Propegates the `site.github` namespace with [repository metadata](https://help.github.com/articles/repository-metadata-on-github-pages/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propagates
?
|
|
||
| ### 2. `~/.netrc` | ||
|
|
||
| If you prefer to use the good ol' `~/.netrc` file, just make sure the `netrc` gem is bundled and run `jekyll` like normal. So if I were to add it, I'd add `gem 'netrc'` to my `Gemfile`, run `bundle install`, then run `bundle exec jekyll build`. The `machine` directive should be `api.github.com`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should include an example...
machine api.github.com
login github-username
password 123abc-your-token
spec/spec_helpers/env_helper.rb
Outdated
| @@ -0,0 +1,29 @@ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty space!
spec/spec_helpers/fixture_helper.rb
Outdated
| } | ||
| end | ||
|
|
||
| def make_page(options = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not call this data or page_data if it's only every being used as page.data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used both in the fixture helper and in the edit link tag spec to create the context, which needs the page object, not the page data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I meant the argument. s/options/data/. Sorry for the confusion!
spec/spec_helpers/fixture_helper.rb
Outdated
| end | ||
|
|
||
| def make_page(options = {}) | ||
| page = Jekyll::Page.new site, config_defaults["source"], "", "page.md" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parens around the 4 arguments to .new would help readability here 👀
spec/spec_helpers/fixture_helper.rb
Outdated
|
|
||
| def make_page(options = {}) | ||
| page = Jekyll::Page.new site, config_defaults["source"], "", "page.md" | ||
| page.data = options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could use .tap
Jekyll::Page.new(site, config_defaults["source"], "", "page.md").tap { |page| page.data = data }
returns the Page object
|
@parkr thanks for the feedback. I believe I've implemented your suggestions and answered your questions to the best of my ability. Mind taking another look? 😄 |
|
@jekyllbot: merge |
|
I host my blog on Netllify. My default branch is It has |
|
@DirtyF I believe the following should work in your config: github:
source:
branch: master |
|
I hoped so but something is wrong: GitHub API is returning $ http --body https://api.github.com/repos/DirtyF/frank.taillandier.me/branches
[
{
"commit": {
"sha": "15a70597f9aee29fcb4c7ae354489b0b560230e8",
"url": "https://api.github.com/repos/DirtyF/frank.taillandier.me/commits/15a70597f9aee29fcb4c7ae354489b0b560230e8"
},
"name": "master"
}
]Whether |
|
The tag uses If |
|
Thanks for taking the time to explain how this works under the hood. 🔧
Well, as I said, In my case, it returns the default value |
This PR exposes a
github_edit_linktag that generates links to edit the current page on GitHub.To generate a link
Produces:
To generate a path
If you'd prefer to build your own link, simply don't pass link text
Produces:
In order to add the tag, I made to related changes:
Broke the various spec helpers into
spec/spec_helpers/foo_helper.rbto keepspec/spec_helpers.rbmore managableBroke the README into individual documents, and moved to the
docs/folder since adding the edit tag docs made the README a bit unwieldy.