Skip to content
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

Merged
merged 17 commits into from
Oct 3, 2013
Merged

New Feature: Import jrnl files #51

merged 17 commits into from
Oct 3, 2013

Conversation

aniketpant
Copy link
Contributor

New feature added for importing jrnl files.

$ jekyll import jrnl

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

# will use ~/path/to/file/work.txt as the jrnl file
$ jekyll import jrnl --file ~/path/to/file/work.txt

# will output all files as txt files
# this feature is yet to be implemented due to contraints from jekyll
$ jekyll import jrnl --extension txt

# will output all files with YAML data having layout: custom
# this feature is yet to be implemented due to contraints from jekyll
$ jekyll import jrnl --layout custom

Signed-off-by: Aniket Pant <me@aniketpant.com>
Signed-off-by: Aniket Pant <me@aniketpant.com>
@aniketpant
Copy link
Contributor Author

@parkr I didn't realize that overrides wouldn't work straight away. How do I allow the usage of --time_format, --extension and --layout?

Signed-off-by: Aniket Pant <me@aniketpant.com>
extension = options[:extension] || "md"
layout = options[:layout] || "post"

date_length = Time.now().strftime(time_format).length
Copy link
Member

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 #... :)

Copy link
Contributor Author

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?

Copy link
Member

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.

GitHub Ruby Styleguide

I'll add it to the CONTRIBUTING file if it isn't already there.

@parkr
Copy link
Member

parkr commented Aug 12, 2013

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. :)

@aniketpant
Copy link
Contributor Author

@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:

@parkr I didn't realize that overrides wouldn't work straight away. How do I allow the usage of --time_format, --extension and --layout?

Thanks :)

@parkr
Copy link
Member

parkr commented Aug 12, 2013

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 bin/jekyll.

@aniketpant
Copy link
Contributor Author

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.

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.

At the moment, all options have to be added to the main Jekyll gem in bin/jekyll.

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.

@parkr
Copy link
Member

parkr commented Aug 12, 2013

Sorry for not being clear enough before! Thanks for being patient with me. :)

This gives me the idea to improve that code and allow the use of new overrides. Will try working on something.

Check out the commando branch on both repos - @mojombo was working on something similar a couple months a go - would you mind starting there? It allows each migrator to specify its own options, which is probably the solution we most want here. What do you think?

@aniketpant
Copy link
Contributor Author

commando looks brute. I am going to start digging in the code. Can you update me on the work that has been going on it? (maybe mail or if any discussion is already going on the same)

@parkr
Copy link
Member

parkr commented Aug 12, 2013

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>
@aniketpant
Copy link
Contributor Author

@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'
Copy link
Member

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?

@parkr
Copy link
Member

parkr commented Sep 23, 2013

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>
@aniketpant
Copy link
Contributor Author

@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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@parkr
Copy link
Member

parkr commented Sep 24, 2013

One more comment above then we should be good to go.

Want to try your hand at tests, or want us to do that?

@aniketpant
Copy link
Contributor Author

Me me me! I want to try writing tests. Just give me brief intro. I have
some testing before but never in Ruby.

@parkr
Copy link
Member

parkr commented Sep 24, 2013

Take a look at the other files in test/. You're going to want to add a test/test_jrnl_importer.rb that takes "fake" data and ensures that the output is correct. Try to just make sure you get the logic right (may need to refactor the class into more methods for easier testing) so that when we make changes, we don't muck anything up in the future. Oh and please try to avoid I/O (so no writing of the files).

@parkr
Copy link
Member

parkr commented Sep 24, 2013

:D

@aniketpant
Copy link
Contributor Author

Got it. Will write tests and let you know. If I have any doubts/questions,
will ask you on Twitter.

@parkr
Copy link
Member

parkr commented Sep 24, 2013

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>
Signed-off-by: Aniket Pant <me@aniketpant.com>
@aniketpant
Copy link
Contributor Author

@parkr Wrote the tests. Take a look at them and see if they do the job.

P.S. I wish we had mocha and chai for Ruby.

# Returns array converted to YAML
def self.create_meta(layout, title, date)
data = {
'layout' => layout.to_s,
Copy link
Member

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.

@mattr-
Copy link
Member

mattr- commented Sep 25, 2013

Looks good to me, other than one small nit.

Signed-off-by: Aniket Pant <me@aniketpant.com>
@parkr
Copy link
Member

parkr commented Sep 25, 2013

Looks like the tests aren't passing on Travis. Did you commit all your files and push up the latest?

@aniketpant
Copy link
Contributor Author

Yeah. I did. Could you please look into what's wrong?

I know that I should've removed that date test but that can't be the
reason as it passed OK on local.

end

should "have date" do
assert_equal("2013-09-24 11:36:00 +0530", "#{JekyllImport::Jrnl.get_date(@entry[0], @date_length)}")
Copy link
Member

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. :)

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Signed-off-by: Aniket Pant <me@aniketpant.com>
@aniketpant
Copy link
Contributor Author

@parkr The test is still failing. I am not sure what is the problem because I have changed the test now.

@parkr
Copy link
Member

parkr commented Sep 26, 2013

Ha! I had a feeling that was going to come back to bite us in the butt.

[ 2/31] TestJrnlMigrator#test: jrnl should have date.  = 0.05 s
  1) Failure:
test: jrnl should have date. (TestJrnlMigrator) [/Users/parkermoore/code/jekyll-import/test/test_jrnl_importer.rb:23]:
<2013-09-24 02:06:00 -0400> expected but was
<2013-09-24 11:36:00 -0400>.

(As a side note, the first argument in assert_equals is the actual value, the second arg is the expected value.)

Why don't we make a decision to just change this such that it extracts the string and puts the string from the jrnl line and outputs it as-is?

@aniketpant
Copy link
Contributor Author

@parkr What do you mean by the last part? Sorry, I didn't understand that.

@parkr
Copy link
Member

parkr commented Sep 26, 2013

Read in the (time) string, output the same string. Don't convert at all.

Signed-off-by: Aniket Pant <me@aniketpant.com>
@parkr
Copy link
Member

parkr commented Sep 29, 2013

Boom! LGTM. @mattr-?

@mattr-
Copy link
Member

mattr- commented Oct 3, 2013

Cool. Thanks! 💚

mattr- added a commit that referenced this pull request Oct 3, 2013
New Feature: Import jrnl files
@mattr- mattr- merged commit 74005bd into jekyll:master Oct 3, 2013
mattr- added a commit that referenced this pull request Oct 3, 2013
@aniketpant aniketpant deleted the import-jrnl branch October 4, 2013 01:59
@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants