-
Notifications
You must be signed in to change notification settings - Fork 312
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
New Feature: Import jrnl files #51
Conversation
Signed-off-by: Aniket Pant <me@aniketpant.com>
Signed-off-by: Aniket Pant <me@aniketpant.com>
@parkr I didn't realize that overrides wouldn't work straight away. How do I allow the usage of |
Signed-off-by: Aniket Pant <me@aniketpant.com>
extension = options[:extension] || "md" | ||
layout = options[:layout] || "post" | ||
|
||
date_length = Time.now().strftime(time_format).length |
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.
Unlike Python, you don't need the parentheses here for Time.now()
. You can just call Time.now.strftime #...
:)
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.
@parkr Is the change required due to coding guidelines?
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.
Yes :)
Omit the parentheses when the method doesn't accept any arguments.
I'll add it to the CONTRIBUTING file if it isn't already there.
Nice work! Looks great so far. One suggestion I would make is to encapsulate various functionality into methods and call them from the main method. :) |
@parkr I am not clear with what you mean by that or maybe I didn't understand. Can you elaborate on which functionalities you want to be called form the main method? Also, I had asked this question before, you might have missed it:
Thanks :) |
I just mean that the various logic it'd be cool if you split out into separate methods so the whole process wasn't one big method with all the nuts-and-bolts code packed into it. At the moment, all options have to be added to the main Jekyll gem in |
Ah. I was planning to do that at the start but then I saw that the other migrators were also written as a single block of code. It's always good to decouple code.
I noticed that there is not provision for the addition of new overrides via CLI because there are only six of them available and they are hard coded. This gives me the idea to improve that code and allow the use of new overrides. Will try working on something. For now I will let the configuration I have provided in lines 17-19 (defaults are meaningful, they won't disturb anything). Once new overrides can be created, users will have more control over the imports. |
Sorry for not being clear enough before! Thanks for being patient with me. :)
Check out the |
|
I unfortunately don't know much about what Tom was working on on that branch. I looked through it briefly once but wasn't sure where I needed to go from there. I'll rebase and look through it now :) |
Signed-off-by: Aniket Pant <me@aniketpant.com>
Signed-off-by: Aniket Pant <me@aniketpant.com>
Signed-off-by: Aniket Pant <me@aniketpant.com>
@parkr About time we merged this? |
@@ -6,7 +6,7 @@ Gem::Specification.new do |s| | |||
|
|||
s.name = 'jekyll-import' | |||
s.version = '0.1.0.beta3' | |||
s.date = '2013-07-14' | |||
s.date = '2013-08-12' |
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.
Would you mind reverting this change?
Yes, I agree! Thanks for pinging. |
Signed-off-by: Aniket Pant <me@aniketpant.com>
Signed-off-by: Aniket Pant <me@aniketpant.com>
Signed-off-by: Aniket Pant <me@aniketpant.com>
@parkr Done. |
# convert relative to absolute if needed | ||
file = File.expand_path(file) | ||
|
||
abort "The jrnl file was not found. Please make sure '#{file}' exists. You can specify a different file using the --file switch." unless File.file?(file) |
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.
Just thinking about this again: does the --file
switch actually work in your tests?
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.
The --file
switch works. I am using ~/journal.txt
as the default because that's a jrnl default too. And then on L26, I check for the availability of the file.
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.
Awesome! I just wanted to make sure --file
works.
One more comment above then we should be good to go. Want to try your hand at tests, or want us to do that? |
Me me me! I want to try writing tests. Just give me brief intro. I have |
Take a look at the other files in |
:D |
Got it. Will write tests and let you know. If I have any doubts/questions, |
Sounds good! Or email me parker AT parkermoo.re |
Signed-off-by: Aniket Pant <me@aniketpant.com>
Signed-off-by: Aniket Pant <me@aniketpant.com>
@parkr Wrote the tests. Take a look at them and see if they do the job. P.S. I wish we had |
# Returns array converted to YAML | ||
def self.create_meta(layout, title, date) | ||
data = { | ||
'layout' => layout.to_s, |
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.
The calls to to_s
aren't needed here or on the line below. You're already working with Strings.
Looks good to me, other than one small nit. |
Signed-off-by: Aniket Pant <me@aniketpant.com>
Looks like the tests aren't passing on Travis. Did you commit all your files and push up the latest? |
Yeah. I did. Could you please look into what's wrong? I know that I should've removed that |
end | ||
|
||
should "have date" do | ||
assert_equal("2013-09-24 11:36:00 +0530", "#{JekyllImport::Jrnl.get_date(@entry[0], @date_length)}") |
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'll need to build a Time
object instead of just comparing to this String. :)
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 so?
The method returns a string on it's own.
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.
Time#parse
returns a Time
object: https://github.com/jekyll/jekyll-import/pull/51/files#L2R53
Signed-off-by: Aniket Pant <me@aniketpant.com>
@parkr The test is still failing. I am not sure what is the problem because I have changed the test now. |
Ha! I had a feeling that was going to come back to bite us in the butt.
(As a side note, the first argument in Why don't we make a decision to just change this such that it extracts the string and puts the string from the |
@parkr What do you mean by the last part? Sorry, I didn't understand that. |
Read in the (time) string, output the same string. Don't convert at all. |
Signed-off-by: Aniket Pant <me@aniketpant.com>
Boom! LGTM. @mattr-? |
Cool. Thanks! 💚 |
New feature added for importing jrnl files.
Available overrides
--file
: Path to input file (default: ~/journal.txt)--time_format
: the time format used by jrnl (default: %Y-%m-%d %H:%M)--extension
: file extension of the output file (default: md)--layout
: set layout of the output file (default: post)Usage