[recipes] Add a way to preserve fields when parsing instructions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add a way to preserve fields when parsing instructions
- Date: Sun, 19 Feb 2017 18:08:02 +0000 (UTC)
commit bb92399bcf94ee76cae496b4f6c1fbcee2df4754
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 19 12:40:54 2017 -0500
Add a way to preserve fields when parsing instructions
Make it possible to not replace the temperature tags.
This will be needed in future commits when we rewrite the
instructions on the edit page.
src/gr-cooking-view.c | 2 +-
src/gr-details-page.c | 2 +-
src/gr-recipe-formatter.c | 55 +++++++++++++++++++++++---------------------
src/gr-recipe-formatter.h | 3 +-
4 files changed, 33 insertions(+), 29 deletions(-)
---
diff --git a/src/gr-cooking-view.c b/src/gr-cooking-view.c
index c93f3f2..efe38ad 100644
--- a/src/gr-cooking-view.c
+++ b/src/gr-cooking-view.c
@@ -415,7 +415,7 @@ setup_steps (GrCookingView *view)
view->step = -1;
- steps = gr_recipe_parse_instructions (view->instructions);
+ steps = gr_recipe_parse_instructions (view->instructions, TRUE);
g_ptr_array_set_size (view->steps, 0);
for (i = 0; i < steps->len; i++) {
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 831533c..ebccf35 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -537,7 +537,7 @@ process_instructions (const char *instructions)
GString *s;
int i;
- steps = gr_recipe_parse_instructions (instructions);
+ steps = gr_recipe_parse_instructions (instructions, TRUE);
s = g_string_new ("");
diff --git a/src/gr-recipe-formatter.c b/src/gr-recipe-formatter.c
index e4884bc..3df6210 100644
--- a/src/gr-recipe-formatter.c
+++ b/src/gr-recipe-formatter.c
@@ -87,7 +87,7 @@ gr_recipe_format (GrRecipe *recipe)
g_string_append_printf (s, "* %s *\n", _("Directions"));
g_string_append (s, "\n");
- steps = gr_recipe_parse_instructions (gr_recipe_get_translated_instructions (recipe));
+ steps = gr_recipe_parse_instructions (gr_recipe_get_translated_instructions (recipe), TRUE);
for (i = 0; i < steps->len; i++) {
GrRecipeStep *step = g_ptr_array_index (steps, i);
g_string_append (s, step->text);
@@ -121,7 +121,8 @@ recipe_step_free (gpointer data)
}
GPtrArray *
-gr_recipe_parse_instructions (const char *instructions)
+gr_recipe_parse_instructions (const char *instructions,
+ gboolean format_for_display)
{
GPtrArray *step_array;
g_auto(GStrv) steps = NULL;
@@ -139,31 +140,33 @@ gr_recipe_parse_instructions (const char *instructions)
step = g_strdup (steps[i]);
- p = strstr (step, "[temperature:");
- while (p) {
- g_autofree char *prefix = NULL;
- const char *unit;
- int num;
- char *tmp;
-
- prefix = g_strndup (step, p - step);
-
- q = strstr (p, "]");
- if (q[-1] == 'C')
- unit = "℃";
- else if (q[-1] == 'F')
- unit ="℉";
- else {
- g_message ("Unsupported temperature unit: %c, using C", q[-1]);
- unit = "℃";
- }
- num = atoi (p + strlen ("[temperature:"));
-
- tmp = g_strdup_printf ("%s%d%s%s", prefix, num, unit, q + 1);
- g_free (step);
- step = tmp;
-
+ if (format_for_display) {
p = strstr (step, "[temperature:");
+ while (p) {
+ g_autofree char *prefix = NULL;
+ const char *unit;
+ int num;
+ char *tmp;
+
+ prefix = g_strndup (step, p - step);
+
+ q = strstr (p, "]");
+ if (q[-1] == 'C')
+ unit = "℃";
+ else if (q[-1] == 'F')
+ unit ="℉";
+ else {
+ g_message ("Unsupported temperature unit: %c, using C", q[-1]);
+ unit = "℃";
+ }
+ num = atoi (p + strlen ("[temperature:"));
+
+ tmp = g_strdup_printf ("%s%d%s%s", prefix, num, unit, q + 1);
+ g_free (step);
+ step = tmp;
+
+ p = strstr (step, "[temperature:");
+ }
}
p = strstr (step, "[image:");
diff --git a/src/gr-recipe-formatter.h b/src/gr-recipe-formatter.h
index 5633b23..9e0e7d8 100644
--- a/src/gr-recipe-formatter.h
+++ b/src/gr-recipe-formatter.h
@@ -33,6 +33,7 @@ typedef struct {
guint64 timer;
} GrRecipeStep;
-GPtrArray *gr_recipe_parse_instructions (const char *instructions);
+GPtrArray *gr_recipe_parse_instructions (const char *instructions,
+ gboolean format_for_display);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]