Added more posts

This commit is contained in:
Oliver Davies 2015-03-16 16:16:06 +00:00
parent 02e01d36ff
commit 230319cc18
6 changed files with 261 additions and 0 deletions

View file

@ -0,0 +1,18 @@
---
title: The Inaugural Meetup for the South Wales Drupal User Group
slug: south-wales-drupal-user-group
tags:
- Drupal
- Drupal Planet
- SWDUG
---
If you do Drupal, and you're in the area, come and join us for the first South Wales Drupal User Group Meetup!
We'll be meeting in the communal area just outside of the [SubHub](http://www.subhub.com) HQ, at:
4, The Studios<br>
3 Burt Street<br>
Cardiff<br>
CF10 5FZ
For more information and to signup, visit <http://groups.drupal.org/node/95104>.

View file

@ -1,6 +1,7 @@
---
title: Checking if a user is logged into Drupal (the right way)
description: How to check if a user is logged into Drupal by using the user_is_logged_in() and user_is_anonymous() functions.
slug: checking-if-user-logged-drupal-right-way
tags:
- Drupal
- Drupal 6

View file

@ -0,0 +1,57 @@
---
title: Display Git Branch or Tag Names in your Bash Prompt
description: Whilst watching Drupalize.me's recent Introduction to Git series, I thought it was useful the way that the current Git branch or tag name was displayed in the bash prompt. Here's how to do it.
slug: display-git-branch-or-tag-names-your-bash-prompt
tags:
- Drupal
- Drupal Planet
- Git
- Terminal
---
Whilst watching [Drupalize.me](http://drupalize.me "Drupalize.me")'s recent [Introduction to Git series](http://drupalize.me/series/introduction-git-series "Introduction to Git on Drupalize.me"), I thought it was useful the way that the current Git branch or tag name was displayed in the bash prompt.
For example (with some slight modifications):
~~~~
oliver@oliver-mbp:~/Development/drupal(master) $
oliver@oliver-mbp:~/Development/a11y_checklist(7.x-1.0) $
~~~~
Here's how to do it.
To begin with, create a new file to contain the functions,
vim ~/.bash/git-prompt
Paste the following code into the file, and save it.
~~~~
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_git_tag () {
git describe --tags 2> /dev/null
}
parse_git_branch_or_tag() {
local OUT="$(parse_git_branch)"
if [ "$OUT" == " ((no branch))" ]; then
OUT="($(parse_git_tag))";
fi
echo $OUT
}
~~~~
Edit your `.bashrc` or `.bash_profile` file to override the PS1 value.
vim ~/.bashrc
Add the following code at the bottom of the file, and save it.
~~~~
source ~/.bash/git-prompt
PS1="\u@\h:\w\$(parse_git_branch_or_tag) $ "
~~~~
Restart your Terminal or type `source ~/.bashrc` to see your changes.

View file

@ -0,0 +1,38 @@
---
title: DrupalCamp London: What is Git Flow?
description: Slides and notes from my talk, "What is Git Flow?", that I presented at DrupalCamp London 2014.
slug: what-git-flow
tags:
- Git
- Git Flow
- DrupalCamp London
- Talks
---
Here are my slides from my "What is Git Flow?" session at [DrupalCamp London](http://2014.drupalcamplondon.co.uk).
<script async class="speakerdeck-embed" data-id="201559e0f103013198dd5a5f6f23ab67" data-ratio="1.29456384323641" src="//speakerdeck.com/assets/embed.js"></script>
## Take aways
The main take aways are:
* Git Flow adds various commands into Git to enhance its native functionality, which creates a branching model to separate your stable production code from your unstable development code.
* Never commit directly to the master branch - this is for production code only!
* You can commit directly to the develop branch, but this should be done sparingly.
* Use feature branches as much as possible - one per feature, user story or bug.
* Commit early and often, and push to a remote often to encourage collaboration as well as to provide a backup of your code.
* You can use settings within services like GitHub and Bitbucket to only allow certain users to push to the master and develop branches, and restrict other Developers to only commit and push to feature branches. Changes can then be committed and pushed, then reviewed as part of a peer code review, and merged back into the develop branch.
## Feedback
If you've got any questions, please feel free to <a href="http://twitter.com/opdavies" title="My Twitter account">tweet at me</a> or fill in the <a href="http://2014.drupalcamplondon.co.uk/node/add/session-evaluation?nid=86&destination=node/86" title="The session evaluation form to submit feedback">session evaluation form</a> that you can complete on the DrupalCamp London website.
I've had some great feedback via Twitter:
<blockquote class="twitter-tweet" lang="en"><p><a href="https://twitter.com/opdavies">@opdavies</a> <a href="https://twitter.com/DrupalCampLDN">@DrupalCampLDN</a> always had trouble with git. Your talk + Git flow has made it all very easy.</p>&mdash; James Tombs (@jtombs) <a href="https://twitter.com/jtombs/statuses/440108072078696449">March 2, 2014</a></blockquote>
<blockquote class="twitter-tweet" data-cards="hidden" lang="en"><p>Great presentation by <a href="https://twitter.com/opdavies">@opdavies</a> on git flow at <a href="https://twitter.com/search?q=%23dclondon&amp;src=hash">#dclondon</a> very well prepared and presented. <a href="http://t.co/tDINp2Nsbn">pic.twitter.com/tDINp2Nsbn</a></p>&mdash; Greg Franklin (@gfranklin) <a href="https://twitter.com/gfranklin/statuses/440104311276969984">March 2, 2014</a></blockquote>
<blockquote class="twitter-tweet" lang="en"><p>Great talk on git flow <a href="https://twitter.com/opdavies">@opdavies</a> <a href="https://twitter.com/search?q=%23dclondon&amp;src=hash">#dclondon</a></p>&mdash; Curve Agency (@CurveAgency) <a href="https://twitter.com/CurveAgency/statuses/440095250775035904">March 2, 2014</a></blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script><iframe width="560" height="315" src="//www.youtube.com/embed/T-miCpHxfds?rel=0" frameborder="0" allowfullscreen></iframe>

View file

@ -0,0 +1,91 @@
---
title: git format-patch is your Friend
slug: git-format-patch
tags:
- Patches
- Drupal
- Drupal Planet
- Git
---
## The Problem
As an active contributor to the <a href="http://drupal.org">Drupal</a> project, I spend a lot of time working with other peoples modules and themes, and occassionally have to fix a bug or add some new functionality.
In the Drupal community, we use a patch based workflow where any changes that I make get exported to a file detailing the differences. The patch file (*.patch) is attached to an item in an issue queue on Drupal.org, applied by the maintainer to their local copy of the code and reviewed, and hopefully committed.
There is an option that the maintainer can add to the end of their commit message.
For example:
--author="opdavies <opdavies@381388.no-reply.drupal.org>"
This differs slightly different for each Drupal user, and the code can be found on their Drupal.org profile page.
If this is added to the end of the commit message, the resulting commit will show that it was committed by the maintainer but authored by a different user. This will then display on Drupal.org that youve made a commit to that project.
<img class="thumbnail img-responsive" alt="A screenshot of a commit that was authored by rli but committed by opdavies" src="/images/blog/git-attribution-commit.png">
The problem is that some project maintainers either dont know about this option or occasionally forget to add it. [Dreditor](http://dreditor.org) can suggest a commit message and assign an author, but it is optional and, of course, not all maintainers use Dreditor (although they probably should).
The `git format-patch` command seems to be the answer, and will be my preferred method for generating patch files in the future rather than `git diff`.
## What does it do Differently?
From the [manual page](http://git-scm.com/docs/git-format-patch):
> Prepare each commit with its patch in one file per commit, formatted to resemble UNIX mailbox format. The output of this command is convenient for e-mail submission or for use with git am.
Here is a section of a patch that I created for the [Metatag module](http://drupal.org/project/metatag) using `git format-patch`:
~~~
From 80c8fa14de7f4a83c2e70367aab0aedcadf4f3b0 Mon Sep 17 00:00:00 2001
From: Oliver Davies &lt;oliver@oliverdavies.co.uk&gt;
Date: Mon, 12 May 2014 14:53:55 +0100
Subject: [PATCH] Exclude comment entities when checking if this is the page,
otherwise comment_fragment.module will break metatag
---
~~~
As mentioned above, the patch is structured in an email format. The commit message is used as the subject line, and the date that the commit was made locally is used for the date. What were interested in is the “From” value. This contains your name and email address from your `~/.gitconfig` file and is used to author the patch automatically.
Everything below this is the same as a standard patch file, the same as if was generated with `git diff`.
The full patch file can be found at <https://drupal.org/files/issues/metatag-comment-fragment-conflict-2265447-4.patch>.
## The Process
How did I create this patch? Here are the steps that I took:
1. Clone the source repository using `$ git clone --branch 7.x-1.x http://git.drupal.org/project/metatag.git` and move into that directory.
2. Create a branch for this patch using `$ git checkout -b 2265447-comment-fragment-conflict`.
3. Add and commit any changes as normal.
4. Generate the patch file using `$ git format-patch 7.x-1.x --stdout > metatag-comment-fragment-conflict-2265447-4.patch`.
*Note:* I am defining 7.x-1.x in the last step as the original branch to compare (i.e. the original branch that we forked to make our issue branch). This will change depending on the project that you are patching, and its version number. Also, commits should always be made against the development branch and not the stable release.
By default, a separate patch file will be created for each commit that weve made. This is overridden by the `--stdout` option which combines all of the patches into a single file. This is the recommended approach when uploading to Drupal.org.
The resulting patch file can be uploaded onto a Drupal.org issue queue, reviewed by the Testbot and applied by a module maintainer, and you automatically get the commit attributed. Problem solved.
## Committing the Patch
If you need to commit a patch that was created using `git format-patch`, the best command to do this with is the `git am` command.
For example, within your repository, run:
$ git am /path/to/file
$ git am ~/Code/metatag-comment-fragment-conflict-2265447-4.patch
You should end up with some output similar to the following:
~~~
Applying: #2272799 Added supporters section
Applying: #2272799 Added navigation tabs
Applying: #2272799 Fixed indentation
Applying: #2272799 Replaced URL
~~~
Each line is the commit message associated with that patch.
Assuming that there are no errors, you can go ahead and push your updated code into your remote repository.

View file

@ -0,0 +1,56 @@
---
title: Include CSS Fonts by Using a SASS each Loop
description: How to use an SASS each loop to easily add multiple fonts to your CSS.
slug: include-css-fonts-using-sass-each-loop
tags:
- Compass
- Drupal Planet
- Fonts
- SASS
---
Using a file structure similar to this, organise your font files into directories, using the the font name for both the directory name and for the file names.
~~~~
.
├── FuturaBold
│ ├── FuturaBold.eot
│ ├── FuturaBold.svg
│ ├── FuturaBold.ttf
│ └── FuturaBold.woff
├── FuturaBoldItalic
│ ├── FuturaBoldItalic.eot
│ ├── FuturaBoldItalic.svg
│ ├── FuturaBoldItalic.ttf
│ └── FuturaBoldItalic.woff
├── FuturaBook
│ ├── FuturaBook.eot
│ ├── FuturaBook.svg
│ ├── FuturaBook.ttf
│ └── FuturaBook.woff
├── FuturaItalic
│ ├── FuturaItalic.eot
│ ├── FuturaItalic.svg
│ ├── FuturaItalic.ttf
│ └── FuturaItalic.woff
~~~~
Within your SASS file, start an `@each` loop, listing the names of the fonts. In the same way as PHP's `foreach` loop, each font name will get looped through using the `$family` variable and then compiled into CSS.
~~~~
@each $family in FuturaBook, FuturaBold, FuturaBoldItalic, FuturaItalic {
@font-face {
font-family: #{$family};
src: url('../fonts/#{$family}/#{$family}.eot');
src: url('../fonts/#{$family}/#{$family}.eot?#iefix') format('embedded-opentype'),
url('../fonts/#{$family}/#{$family}.woff') format('woff'),
url('../fonts/#{$family}/#{$family}.ttf') format('truetype'),
url('../fonts/#{$family}/#{$family}.svg##{$family}') format('svg');
font-weight: normal;
font-style: normal;
}
}
~~~~
When the CSS has been compiled, you can then use in your CSS in the standard way.
font-family: "FuturaBook";