Set the path for the local data file

Hi,

I am a bit new to ruby and middleman and wanted to know how, if possible, to set the path of a local data file.

For a bit more clarity, The site already has localization working but I now need to add new data files, based on the users country and language.
I can get the at the existing data file (data/car.yml) via data.car.details.cfg but what I to do is set the reference to data.xx.xx.cfg

The reason for the file being separate is A) The new content is ~ 2k lines each and B) I have inherited the site I really do not want to rewrite a big section of it.

Is this possible or should I look for another way?

Thanks in advance.
Tim.

You can create nested folders of data.

For example: data/cars/car1.yml will be available as data.cars.car1. If you store a car_id in your original data file, you can know which subfile to reference the additional data from.

Hi,
Thanks for the reply. I have tried this and set up my files structure as data/foo/bar.yml
I get the following error:
undefined method `foo’ for #< Middleman::CoreExtensions::Data::DataStore:0x3955b78>

My code looks like
<% @cfg = data.foo.bar.en.cfg %>

Where @cfg is being used in partials. Any idea as to why I am getting the undefined method error?

Thanks,
Tim.

Ah, looks like this is only in the unstable 3.1.x betas. We’re hoping to have a final release out by the end of June. You can upgrade to the current release 3.1.0.rc.1 if you need this feature today.

I am getting an error when I try to update.

My Gem file looks like this:

#gem "middleman", :git => "https://github.com/sc0ttman/middleman.git", :branch => "-- 3.1.0.rc" #updated to use sub data directory
gem "middleman", "~> 3.1.0.rc"
gem 'libv8', '~> 3.11.8', :platforms => :ruby
gem 'therubyracer', :platforms => :ruby
gem "middleman-minify-html"
gem "win32-open3-19", :platforms => :mingw
gem 'wdm', '~> 0.0.3',  :platforms => :mingw

Setting the source to github didn’t seem to work so tried the next line.
And when I run the the command line “Bundle Install” I get the following error:

Fetching gem metadata from http://rubygems.org/........
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies...
Bundler could not find compatible versions for gem "middleman-core":
  In Gemfile:

    middleman-minify-html (>= 0) x86-mingw32 depends on

      middleman-core (~> 3.0.0) x86-mingw32

    middleman (~> 3.1.0.rc) ruby depends on
      middleman-core (3.1.0.rc.1)

Is this an issue with the RC build or do I need to add more gems/dependemncies to the gem file?

It might be an issue with middleman-minify-html, I don’t think we’ve released a 3.1.x compatible version yet. You could try pointing it at Github and running bundle update so the rc.2 is pulled down.