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

Expose data file's basename as attribute name #512

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/jekyll-admin/data_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module JekyllAdmin
class DataFile
METHODS_FOR_LIQUID = %w(path relative_path slug ext title).freeze
METHODS_FOR_LIQUID = %w(name path relative_path slug ext title).freeze
EXTENSIONS = %w(yaml yml json csv).freeze

include APIable
Expand Down Expand Up @@ -94,9 +94,10 @@ def basename
end

def basename_with_extension
[basename, extension].join
"#{basename}#{extension}"
end
alias_method :filename, :basename_with_extension
alias_method :name, :basename_with_extension
public :name

def namespace
"data"
Expand Down
6 changes: 6 additions & 0 deletions spec/jekyll-admin/data_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
expect(subject.slug).to eql("data_file")
end

it "exposes the basename_with_extension as 'name'" do
expect(subject.name).to eql("data_file.yml")
end

it "exposes the title" do
expect(subject.title).to eql("Data File")
end

it "returns the hash" do
expect(subject.to_api).to eql(
"name" => "data_file.yml",
"path" => "/_data/data_file.yml",
"relative_path" => "data_file.yml",
"slug" => "data_file",
Expand All @@ -46,6 +51,7 @@

it "returns the hash with content" do
expect(subject.to_api(:include_content => true)).to eql(
"name" => "data_file.yml",
"path" => "/_data/data_file.yml",
"relative_path" => "data_file.yml",
"slug" => "data_file",
Expand Down
10 changes: 10 additions & 0 deletions spec/jekyll-admin/server/data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

let(:base_response) do
{
"name" => "data_file.yml",
"path" => "/_data/data_file.yml",
"relative_path" => "data_file.yml",
"slug" => "data_file",
Expand Down Expand Up @@ -44,6 +45,7 @@ def app
get "/data/movies"

expected_response = {
"name" => "actors.yml",
"path" => "/_data/movies/actors.yml",
"relative_path" => "movies/actors.yml",
"slug" => "actors",
Expand All @@ -61,6 +63,7 @@ def app
get "/data/movies/actors.yml"

expected_response = {
"name" => "actors.yml",
"path" => "/_data/movies/actors.yml",
"relative_path" => "movies/actors.yml",
"slug" => "actors",
Expand All @@ -82,6 +85,7 @@ def app
delete_file "_data/data-file-new.yml"

expected_response = {
"name" => "data-file-new.yml",
"path" => "/_data/data-file-new.yml",
"relative_path" => "data-file-new.yml",
"slug" => "data-file-new",
Expand Down Expand Up @@ -109,6 +113,7 @@ def app
delete_file "_data/test-dir/data-file-new.yml"

expected_response = {
"name" => "data-file-new.yml",
"path" => "/_data/test-dir/data-file-new.yml",
"relative_path" => "test-dir/data-file-new.yml",
"slug" => "data-file-new",
Expand Down Expand Up @@ -136,6 +141,7 @@ def app
delete_file "_data/data-file-new.yml"

expected_response = {
"name" => "data-file-new.yml",
"path" => "/_data/data-file-new.yml",
"relative_path" => "data-file-new.yml",
"slug" => "data-file-new",
Expand Down Expand Up @@ -163,6 +169,7 @@ def app
delete_file "_data/test-dir/data-file-new.yml"

expected_response = {
"name" => "data-file-new.yml",
"path" => "/_data/test-dir/data-file-new.yml",
"relative_path" => "test-dir/data-file-new.yml",
"slug" => "data-file-new",
Expand Down Expand Up @@ -190,6 +197,7 @@ def app
write_file "_data/data-file-update.yml", "foo2: bar2"

expected_response = {
"name" => "data-file-update.yml",
"path" => "/_data/data-file-update.yml",
"relative_path" => "data-file-update.yml",
"slug" => "data-file-update",
Expand Down Expand Up @@ -217,6 +225,7 @@ def app
write_file "_data/test-dir/data-file-update.yml", "foo2: bar2"

expected_response = {
"name" => "data-file-update.yml",
"path" => "/_data/test-dir/data-file-update.yml",
"relative_path" => "test-dir/data-file-update.yml",
"slug" => "data-file-update",
Expand Down Expand Up @@ -245,6 +254,7 @@ def app
delete_file "_data/data-file-renamed.yml"

expected_response = {
"name" => "data-file-renamed.yml",
"path" => "/_data/data-file-renamed.yml",
"relative_path" => "data-file-renamed.yml",
"slug" => "data-file-renamed",
Expand Down