How to specify articles directory for middleman-blog? - middleman

Is it possible somehow to specify articles directory outside of source/? In data/articles/ for an instance. It would be quite convenient 'cause I'm using submodule repository inside data/ for data/content purposes.
I have this lines in my config.rb:
activate :blog do |o|
o.permalink = "{title}"
o.sources = "data/articles/{title}"
end
But thing still ain't working and blog.articles is empty. What I'm doing wrong? Or it is supposed to be so?

Related

Change case of folder using libgit2sharp

How can I rename a directory in libgit2sharp (under Windows, which is case insensitive) when it's just a case change?
This code works fine for moving files across different directories:
File.Move(#"C:\repo\folder1\file.txt", #"C:\repo\folder2\file.txt");
repo.Index.Remove("folder1/file.txt");
repo.Index.Add("folder2/file.txt");
repo.Index.Write();
var commitResult = repo.Commit(logMessage, author, author);
However, if I'm just renaming case of a folder, it doesn't work:
Directory.Move(#"C:\repo\folder1\", #"C:\repo\Folder1\");
repo.Index.Remove("folder1/file.txt");
repo.Index.Add("Folder1/file.txt");
repo.Index.Write();
var commitResult = repo.Commit(logMessage, author, author); // nothing gets written - I get LibGit2Sharp.EmptyCommitException
I also tried doing 2 renames (and commiting once at the end) like suggested by this answer
Am I doing something wrong or this is a git limitation?
Is there any workaround besides doing an intermediate commit?
PS: I tried changing the repo to ignorecase=false (the default in Windows is true), but it didn't work either.
Turns out that it was enough to set ignorecase=false in git.config - but I had to use that since the beggining (before the first commit).
I only tried changing that setting by the moment that I was really removing the old case and adding the new one, looks like that wasn't enough - git doesn't detect the change.

How to apply metadata to all files in a content directory

I have a content directory called foo and I want all files under that directory to have an extra metadata item foovar: default, unless explicitly overridden in the file header. I think I'm supposed to do this with EXTRA_PATH_METADATA, but I can't figure out what incantation it wants.
(for my current use case I'm trying to apply template: sometemplate within this dir, but I'm interested in solving the general case as it would make several related headaches go away)
I think what you're looking for is actually DEFAULT_METADATA. Check out this portion of the documentation:
DEFAULT_METADATA = {}
The default metadata you want to use for all articles and pages.
So, in your case it might look something like this in your config file:
DEFAULT_METADATA = {'foovar': 'default'}
Then to assign your custom template(s), see this portion of the documentation.
This wasn't possible at the time I asked. I've since sent the devs a PR adding support, and it's been merged to master. Presumably it will go out in the next release. It makes EXTRA_PATH_METADATA recursive, so you can apply settings to a subdir like this:
EXTRA_PATH_METADATA = {'dirname/subdir': {'status': 'hidden'}}

Coldfusion 9 ORM Mapping issue

I have an issue with CF9 ORM mapping.
I get the following error from time to time (yes, it works fine most of the time),
Mapping for component model.Pubs not found. Either the mapping for this component is missing or the application must be restarted to generate the mapping.
ORM definition in Application.cfc
<cfscript>
this.datasource = "Pubs";
this.ormenabled = true;
this.ormsettings= {
dialect="MicrosoftSQLServer",
dbcreate="update",
eventhandling="true"
};
</cfscript>
<cfset this.mappings["/model"] = getDirectoryFromPath(getCurrentTemplatePath()) & "model" />
The only way to fix it is to refresh the ORM couple of time, which is by hitting ?init=true on Application.cfc. It is still a temporary solution, but I need to know the root cause of it and fix it.
<cfscript>
if(structKeyExists(url, "init")) { ormReload(); applicationStop(); location('index.cfm?reloaded=true'); }
Please advise.
Thanks!
I also had your problem, but now it works fine. First, if you don't set ormsettings.cfclocation, ColdFusion does this:
If it is not set, ColdFusion looks at the application directory, its sub-directories, and its mapped directories to search for persistent CFCs. (see Spec)
This is error prone, because you never know what ColdFusion finds in all that directories.
When you add cfclocation to your example it should work:
this.ormsettings= {
cfclocation = ["/model", "/other/entities", "/more/other/entites"]
}
There is a lot of discussion out there, about how to specify the paths for cfclocation. For me, that way works.
But the first element of my cfclocation is always an application mapping, like your this.mappings["/model"]. I have not tested it with webserver aliases or CFCs in the webroot, without mapping. You should also avoid colliding namespaces, like a "model" directory in the webroot, while having a "/model" mapping.
Good luck:)
Okay, thank you both #Henry and #Walter for your comments. They were the lead toward the right solution.
Here's what I did to make sure it's stable ALL the time.
I used one folder (location) for all ORM CFCs. There used to be a "model" folder for each section. Sections are sibling folders under one root and share the same Application.cfc.
I changed that to ONE root level folder for all CFCs, ie: /root/ormmodel
On the /root/Application.cfc, I adjusted the following code
<cfset application.mappings["/ormmodel"] = expandPath("/root/ormmodel") />
and
this.ormsettings= {
cfclocation = ["ormmodel"],
autogenmap = true,
...
eventhandling="true"
};
Notice the missing "/" in the cfclocation value.
On calling for model components, I changed the code from pub = new ormmodel.Pubs() to
pub = EntityNew("Pubs");
On an unrelated point, I've changed my components name to camelCase naming and avoided special characters like underscores and dashes.
I hope this would be helpful and save someone else hours of frustration and suspense.
Happy coding!

What is the best practice of storing single use user settings in rails 3?

I am struggling to find a pattern for storing single use user settings (VAT percentage, tag line. Things that are 1 off by nature) in Rails 3. I need to set up global site settings, which have single instances.
Ideally, I want the answer to be a design pattern, rather than a gem or plugin (unless someone knows a gem or plugin that integrates will with Active Admin)
What do you mean by single use settings? Do you mean things like API keys and environment variables?
If so, then a good practice is to use the ENV hash, and set up ENV variables in the environments file (explained below).
Create a .rb file for each individual gem (or arbitrary entity) that needs settings in your config/initializers/ directory. For example, when using stripe, I created config/initializers/stripe.rb shown below:
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
:secret_key => ENV['STRIPE_SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
This sets up initial settings within my stripe gem, and pulls the variable values from the ENV hash.
To set variables in the ENV hash, you can do so within the config/environments directory. In that directory, you will have three different files: config/environments/test.rb, config/environments/development.rb, config/environments/production.rb. Setting variables in the ENV hash(as shown below).
AppName::Application.configure do
# Set Stripe API Key
ENV['STRIPE_SECRET_KEY'] = "sk_test_key"
ENV['STRIPE_PUBLISHABLE_KEY'] = "pk_test_key"
...
end
How about a class for storing your key-value pairs?
class Settings < ActiveRecord::Base
attr_accessible :lookup, :value
def self.VAT
return self.find_by_lookup('VAT')
end
end
Then you can do #vat = Settings.VAT.value or similar. The lookup is your internally defined key. Of course the value column will have to be all the same datatype, but you can handle any necessary transformation in the getter methods (or through subclasses).

Lua - Question on modules

Say I want to make a module for say a set of GUI controls, how would I create a module that would load all of the GUI scripts, and should I put those scripts as modules themselves? I was thinking of having a system like this:
module("bgui", package.seeall)
dofile("modules/bgui/control.lua")
dofile("modules/bgui/container.lua")
dofile("modules/bgui/screenmanager.lua")
dofile("modules/bgui/form.lua")
dofile("modules/bgui/button.lua")
dofile("modules/bgui/textbox.lua")
dofile("modules/bgui/label.lua")
Would all the files run then have the variables they set as part of the bgui module?
Aka if in control.lua I had control = {...} would it be defined as bgui.control or should I make the control.lua a module itself, something like module("bgui.control") would that work as I intend?
Sorry if this isn't very clear had to write it in a rush, thanks :)
You are actually asking two questions here:
First, "is this way of loading lots of files on a module ok?"
The answer is - yes. It is kind of an unspoken standard to call that file mymodule/init.lua. Most people have ?/init.lua included on their path, so you can just write require('modules/bgui') and init.lua will be loaded automatically.
This said, you might want to remove some code duplication by using a temp table and a loop:
# modules/bgui/init.lua
local files = {
'control', 'container', 'screenmanager', 'form', 'button', 'textbox', 'label'
}
for _,file in ipairs(files) do dofile("modules/bgui/" .. file .. ".lua") end
Second, "are objects defined on one file available on bgui?".
The answer is also yes, as long as the file defining the variable is "done" (with dofile or require) before the file using the variable.